-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathcontextData.ts
More file actions
39 lines (34 loc) · 1.53 KB
/
Copy pathcontextData.ts
File metadata and controls
39 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { Context } from '@opentelemetry/api';
import type { Hub, PropagationContext } from '@sentry/types';
import { SENTRY_HUB_CONTEXT_KEY, SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY } from '../constants';
/**
* Try to get the Propagation Context from the given OTEL context.
* This requires the SentryPropagator to be registered.
*/
export function getPropagationContextFromContext(context: Context): PropagationContext | undefined {
return context.getValue(SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY) as PropagationContext | undefined;
}
/**
* Set a Propagation Context on an OTEL context..
* This will return a forked context with the Propagation Context set.
*/
export function setPropagationContextOnContext(context: Context, propagationContext: PropagationContext): Context {
return context.setValue(SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY, propagationContext);
}
/**
* Try to get the Hub from the given OTEL context.
* This requires a Context Manager that was wrapped with getWrappedContextManager.
*/
// eslint-disable-next-line deprecation/deprecation
export function getHubFromContext(context: Context): Hub | undefined {
// eslint-disable-next-line deprecation/deprecation
return context.getValue(SENTRY_HUB_CONTEXT_KEY) as Hub | undefined;
}
/**
* Set a Hub on an OTEL context..
* This will return a forked context with the Propagation Context set.
*/
// eslint-disable-next-line deprecation/deprecation
export function setHubOnContext(context: Context, hub: Hub): Context {
return context.setValue(SENTRY_HUB_CONTEXT_KEY, hub);
}