@sentry/opentelemetry 7.105.0 → 8.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -14
- package/cjs/asyncContextStrategy.js +87 -19
- package/cjs/asyncContextStrategy.js.map +1 -1
- package/cjs/constants.js +16 -4
- package/cjs/constants.js.map +1 -1
- package/cjs/contextManager.js +42 -15
- package/cjs/contextManager.js.map +1 -1
- package/cjs/custom/client.js +0 -28
- package/cjs/custom/client.js.map +1 -1
- package/cjs/custom/getCurrentHub.js +106 -0
- package/cjs/custom/getCurrentHub.js.map +1 -0
- package/cjs/custom/hub.js +3 -136
- package/cjs/custom/hub.js.map +1 -1
- package/cjs/custom/transaction.js +3 -32
- package/cjs/custom/transaction.js.map +1 -1
- package/cjs/index.js +9 -9
- package/cjs/index.js.map +1 -1
- package/cjs/propagator.js +125 -40
- package/cjs/propagator.js.map +1 -1
- package/cjs/sampler.js +7 -6
- package/cjs/sampler.js.map +1 -1
- package/cjs/semanticAttributes.js +0 -9
- package/cjs/semanticAttributes.js.map +1 -1
- package/cjs/setupEventContextTrace.js +12 -7
- package/cjs/setupEventContextTrace.js.map +1 -1
- package/cjs/spanExporter.js +62 -58
- package/cjs/spanExporter.js.map +1 -1
- package/cjs/spanProcessor.js +16 -18
- package/cjs/spanProcessor.js.map +1 -1
- package/cjs/trace.js +120 -23
- package/cjs/trace.js.map +1 -1
- package/cjs/utils/addOriginToSpan.js +2 -2
- package/cjs/utils/addOriginToSpan.js.map +1 -1
- package/cjs/utils/contextData.js +35 -15
- package/cjs/utils/contextData.js.map +1 -1
- package/cjs/utils/dynamicSamplingContext.js +64 -0
- package/cjs/utils/dynamicSamplingContext.js.map +1 -0
- package/cjs/utils/mapStatus.js +5 -4
- package/cjs/utils/mapStatus.js.map +1 -1
- package/cjs/utils/setupCheck.js +17 -0
- package/cjs/utils/setupCheck.js.map +1 -0
- package/cjs/utils/spanData.js +23 -23
- package/cjs/utils/spanData.js.map +1 -1
- package/esm/asyncContextStrategy.js +89 -18
- package/esm/asyncContextStrategy.js.map +1 -1
- package/esm/constants.js +11 -4
- package/esm/constants.js.map +1 -1
- package/esm/contextManager.js +41 -17
- package/esm/contextManager.js.map +1 -1
- package/esm/custom/client.js +0 -28
- package/esm/custom/client.js.map +1 -1
- package/esm/custom/getCurrentHub.js +101 -0
- package/esm/custom/getCurrentHub.js.map +1 -0
- package/esm/custom/hub.js +4 -133
- package/esm/custom/hub.js.map +1 -1
- package/esm/custom/transaction.js +4 -32
- package/esm/custom/transaction.js.map +1 -1
- package/esm/index.js +7 -5
- package/esm/index.js.map +1 -1
- package/esm/propagator.js +128 -45
- package/esm/propagator.js.map +1 -1
- package/esm/sampler.js +7 -6
- package/esm/sampler.js.map +1 -1
- package/esm/semanticAttributes.js +0 -9
- package/esm/semanticAttributes.js.map +1 -1
- package/esm/setupEventContextTrace.js +14 -9
- package/esm/setupEventContextTrace.js.map +1 -1
- package/esm/spanExporter.js +63 -59
- package/esm/spanExporter.js.map +1 -1
- package/esm/spanProcessor.js +12 -14
- package/esm/spanProcessor.js.map +1 -1
- package/esm/trace.js +122 -26
- package/esm/trace.js.map +1 -1
- package/esm/utils/addOriginToSpan.js +2 -2
- package/esm/utils/addOriginToSpan.js.map +1 -1
- package/esm/utils/contextData.js +33 -15
- package/esm/utils/contextData.js.map +1 -1
- package/esm/utils/dynamicSamplingContext.js +59 -0
- package/esm/utils/dynamicSamplingContext.js.map +1 -0
- package/esm/utils/mapStatus.js +5 -4
- package/esm/utils/mapStatus.js.map +1 -1
- package/esm/utils/setupCheck.js +14 -0
- package/esm/utils/setupCheck.js.map +1 -0
- package/esm/utils/spanData.js +22 -20
- package/esm/utils/spanData.js.map +1 -1
- package/package.json +5 -5
- package/types/asyncContextStrategy.d.ts.map +1 -1
- package/types/constants.d.ts +6 -2
- package/types/constants.d.ts.map +1 -1
- package/types/contextManager.d.ts +1 -1
- package/types/contextManager.d.ts.map +1 -1
- package/types/custom/client.d.ts.map +1 -1
- package/types/custom/getCurrentHub.d.ts +7 -0
- package/types/custom/getCurrentHub.d.ts.map +1 -0
- package/types/custom/hub.d.ts +2 -33
- package/types/custom/hub.d.ts.map +1 -1
- package/types/custom/transaction.d.ts +1 -10
- package/types/custom/transaction.d.ts.map +1 -1
- package/types/index.d.ts +7 -5
- package/types/index.d.ts.map +1 -1
- package/types/propagator.d.ts +11 -2
- package/types/propagator.d.ts.map +1 -1
- package/types/sampler.d.ts.map +1 -1
- package/types/semanticAttributes.d.ts +0 -9
- package/types/semanticAttributes.d.ts.map +1 -1
- package/types/setupEventContextTrace.d.ts.map +1 -1
- package/types/spanExporter.d.ts.map +1 -1
- package/types/spanProcessor.d.ts +1 -5
- package/types/spanProcessor.d.ts.map +1 -1
- package/types/trace.d.ts +14 -3
- package/types/trace.d.ts.map +1 -1
- package/types/types.d.ts +7 -12
- package/types/types.d.ts.map +1 -1
- package/types/utils/addOriginToSpan.d.ts.map +1 -1
- package/types/utils/contextData.d.ts +21 -10
- package/types/utils/contextData.d.ts.map +1 -1
- package/types/utils/dynamicSamplingContext.d.ts +11 -0
- package/types/utils/dynamicSamplingContext.d.ts.map +1 -0
- package/types/utils/mapStatus.d.ts +2 -2
- package/types/utils/mapStatus.d.ts.map +1 -1
- package/types/utils/setupCheck.d.ts +9 -0
- package/types/utils/setupCheck.d.ts.map +1 -0
- package/types/utils/spanData.d.ts +14 -8
- package/types/utils/spanData.d.ts.map +1 -1
- package/types-ts3.8/constants.d.ts +6 -2
- package/types-ts3.8/contextManager.d.ts +1 -1
- package/types-ts3.8/custom/getCurrentHub.d.ts +7 -0
- package/types-ts3.8/custom/hub.d.ts +2 -33
- package/types-ts3.8/custom/transaction.d.ts +1 -10
- package/types-ts3.8/index.d.ts +7 -5
- package/types-ts3.8/propagator.d.ts +11 -2
- package/types-ts3.8/semanticAttributes.d.ts +0 -9
- package/types-ts3.8/spanProcessor.d.ts +1 -5
- package/types-ts3.8/trace.d.ts +14 -3
- package/types-ts3.8/types.d.ts +7 -12
- package/types-ts3.8/utils/contextData.d.ts +21 -10
- package/types-ts3.8/utils/dynamicSamplingContext.d.ts +11 -0
- package/types-ts3.8/utils/mapStatus.d.ts +2 -2
- package/types-ts3.8/utils/setupCheck.d.ts +9 -0
- package/types-ts3.8/utils/spanData.d.ts +14 -8
- package/cjs/custom/scope.js +0 -202
- package/cjs/custom/scope.js.map +0 -1
- package/esm/custom/scope.js +0 -200
- package/esm/custom/scope.js.map +0 -1
- package/types/custom/scope.d.ts +0 -42
- package/types/custom/scope.d.ts.map +0 -1
- package/types-ts3.8/custom/scope.d.ts +0 -42
package/cjs/custom/hub.js
CHANGED
|
@@ -1,146 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
const core = require('@sentry/core');
|
|
4
|
-
const utils = require('@sentry/utils');
|
|
5
|
-
const scope = require('./scope.js');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A custom hub that ensures we always creat an OTEL scope.
|
|
9
|
-
* Exported only for testing
|
|
10
|
-
*/
|
|
11
|
-
class OpenTelemetryHub extends core.Hub {
|
|
12
|
-
constructor(client, scope$1 = new scope.OpenTelemetryScope()) {
|
|
13
|
-
super(client, scope$1);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Custom getClient method that uses the custom hub. */
|
|
18
|
-
function getClient() {
|
|
19
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
20
|
-
return getCurrentHub().getClient();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* *******************************************************************************
|
|
25
|
-
* Everything below here is a copy of the stuff from core's hub.ts,
|
|
26
|
-
* only that we make sure to create our custom NodeExperimentalScope instead of the default Scope.
|
|
27
|
-
* This is necessary to get the correct breadcrumbs behavior.
|
|
28
|
-
*
|
|
29
|
-
* Basically, this overwrites all places that do `new Scope()` with `new NodeExperimentalScope()`.
|
|
30
|
-
* Which in turn means overwriting all places that do `new Hub()` and make sure to pass in a NodeExperimentalScope instead.
|
|
31
|
-
* *******************************************************************************
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
3
|
/**
|
|
35
|
-
*
|
|
4
|
+
* Ensure the global hub is setup.
|
|
36
5
|
*
|
|
37
|
-
*
|
|
38
|
-
* changes and new methods are introduced.
|
|
39
|
-
*
|
|
40
|
-
* @hidden
|
|
41
|
-
*/
|
|
42
|
-
const API_VERSION = 4;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Returns the default hub instance.
|
|
46
|
-
*
|
|
47
|
-
* If a hub is already registered in the global carrier but this module
|
|
48
|
-
* contains a more recent version, it replaces the registered version.
|
|
49
|
-
* Otherwise, the currently registered hub will be returned.
|
|
50
|
-
*/
|
|
51
|
-
function getCurrentHub() {
|
|
52
|
-
// Get main carrier (global for every environment)
|
|
53
|
-
const registry = getMainCarrier();
|
|
54
|
-
|
|
55
|
-
if (registry.__SENTRY__ && registry.__SENTRY__.acs) {
|
|
56
|
-
const hub = registry.__SENTRY__.acs.getCurrentHub();
|
|
57
|
-
|
|
58
|
-
if (hub) {
|
|
59
|
-
return hub;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Return hub that lives on a global object
|
|
64
|
-
return getGlobalHub(registry);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Ensure the global hub is an OpenTelemetryHub.
|
|
6
|
+
* @deprecated This will be removed in the next major version.
|
|
69
7
|
*/
|
|
70
8
|
function setupGlobalHub() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (getGlobalHub(globalRegistry) instanceof OpenTelemetryHub) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// If the current global hub is not correct, ensure we overwrite it
|
|
78
|
-
setHubOnCarrier(globalRegistry, new OpenTelemetryHub());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* This will create a new {@link Hub} and add to the passed object on
|
|
83
|
-
* __SENTRY__.hub.
|
|
84
|
-
* @param carrier object
|
|
85
|
-
* @hidden
|
|
86
|
-
*/
|
|
87
|
-
function getHubFromCarrier(carrier) {
|
|
88
|
-
return utils.getGlobalSingleton('hub', () => new OpenTelemetryHub(), carrier);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function getGlobalHub(registry = getMainCarrier()) {
|
|
92
|
-
// If there's no hub, or its an old API, assign a new one
|
|
93
|
-
if (
|
|
94
|
-
!hasHubOnCarrier(registry) ||
|
|
95
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
96
|
-
getHubFromCarrier(registry).isOlderThan(API_VERSION)
|
|
97
|
-
) {
|
|
98
|
-
setHubOnCarrier(registry, new OpenTelemetryHub());
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Return hub that lives on a global object
|
|
102
|
-
return getHubFromCarrier(registry);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* This will tell whether a carrier has a hub on it or not
|
|
107
|
-
* @param carrier object
|
|
108
|
-
*/
|
|
109
|
-
function hasHubOnCarrier(carrier) {
|
|
110
|
-
return !!(carrier && carrier.__SENTRY__ && carrier.__SENTRY__.hub);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Returns the global shim registry.
|
|
115
|
-
*
|
|
116
|
-
* FIXME: This function is problematic, because despite always returning a valid Carrier,
|
|
117
|
-
* it has an optional `__SENTRY__` property, which then in turn requires us to always perform an unnecessary check
|
|
118
|
-
* at the call-site. We always access the carrier through this function, so we can guarantee that `__SENTRY__` is there.
|
|
119
|
-
**/
|
|
120
|
-
function getMainCarrier() {
|
|
121
|
-
utils.GLOBAL_OBJ.__SENTRY__ = utils.GLOBAL_OBJ.__SENTRY__ || {
|
|
122
|
-
extensions: {},
|
|
123
|
-
hub: undefined,
|
|
124
|
-
};
|
|
125
|
-
return utils.GLOBAL_OBJ;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* This will set passed {@link Hub} on the passed object's __SENTRY__.hub attribute
|
|
130
|
-
* @param carrier object
|
|
131
|
-
* @param hub Hub
|
|
132
|
-
* @returns A boolean indicating success or failure
|
|
133
|
-
*/
|
|
134
|
-
function setHubOnCarrier(carrier, hub) {
|
|
135
|
-
if (!carrier) return false;
|
|
136
|
-
const __SENTRY__ = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});
|
|
137
|
-
__SENTRY__.hub = hub;
|
|
138
|
-
return true;
|
|
9
|
+
// noop
|
|
139
10
|
}
|
|
140
11
|
|
|
141
|
-
exports.OpenTelemetryHub = OpenTelemetryHub;
|
|
142
|
-
exports.getClient = getClient;
|
|
143
|
-
exports.getCurrentHub = getCurrentHub;
|
|
144
|
-
exports.getHubFromCarrier = getHubFromCarrier;
|
|
145
12
|
exports.setupGlobalHub = setupGlobalHub;
|
|
146
13
|
//# sourceMappingURL=hub.js.map
|
package/cjs/custom/hub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hub.js","sources":["../../../src/custom/hub.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"hub.js","sources":["../../../src/custom/hub.ts"],"sourcesContent":["/**\n * Ensure the global hub is setup.\n *\n * @deprecated This will be removed in the next major version.\n */\nexport function setupGlobalHub(): void {\n // noop\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,GAAS;AACvC;AACA;;;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
|
-
const utils = require('@sentry/utils');
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* This is a fork of core's tracing/hubextensions.ts _startTransaction,
|
|
@@ -10,46 +9,18 @@ const utils = require('@sentry/utils');
|
|
|
10
9
|
function startTransaction(hub, transactionContext) {
|
|
11
10
|
// eslint-disable-next-line deprecation/deprecation
|
|
12
11
|
const client = hub.getClient();
|
|
13
|
-
const options = (client && client.getOptions()) || {};
|
|
14
12
|
|
|
15
13
|
// eslint-disable-next-line deprecation/deprecation
|
|
16
|
-
const transaction = new
|
|
14
|
+
const transaction = new core.Transaction(transactionContext, hub );
|
|
17
15
|
// Since we do not do sampling here, we assume that this is _always_ sampled
|
|
18
16
|
// Any sampling decision happens in OpenTelemetry's sampler
|
|
19
|
-
transaction.initSpanRecorder(
|
|
17
|
+
transaction.initSpanRecorder();
|
|
20
18
|
|
|
21
|
-
if (client
|
|
19
|
+
if (client) {
|
|
22
20
|
client.emit('startTransaction', transaction);
|
|
23
21
|
}
|
|
24
22
|
return transaction;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
/**
|
|
28
|
-
* This is a fork of the base Transaction with OTEL specific stuff added.
|
|
29
|
-
*/
|
|
30
|
-
class OpenTelemetryTransaction extends core.Transaction {
|
|
31
|
-
/**
|
|
32
|
-
* Finish the transaction, but apply the given scope instead of the current one.
|
|
33
|
-
*/
|
|
34
|
-
finishWithScope(endTimestamp, scope) {
|
|
35
|
-
const event = this._finishTransaction(endTimestamp);
|
|
36
|
-
|
|
37
|
-
if (!event) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
42
|
-
const client = this._hub.getClient();
|
|
43
|
-
|
|
44
|
-
if (!client) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const eventId = utils.uuid4();
|
|
49
|
-
return client.captureEvent(event, { event_id: eventId }, scope);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.OpenTelemetryTransaction = OpenTelemetryTransaction;
|
|
54
25
|
exports.startTransaction = startTransaction;
|
|
55
26
|
//# sourceMappingURL=transaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sources":["../../../src/custom/transaction.ts"],"sourcesContent":["import type { Hub } from '@sentry/core';\nimport { Transaction } from '@sentry/core';\nimport type {
|
|
1
|
+
{"version":3,"file":"transaction.js","sources":["../../../src/custom/transaction.ts"],"sourcesContent":["import type { Hub } from '@sentry/core';\nimport { Transaction } from '@sentry/core';\nimport type { Hub as HubInterface, TransactionContext } from '@sentry/types';\n\n/**\n * This is a fork of core's tracing/hubextensions.ts _startTransaction,\n * with some OTEL specifics.\n */\nexport function startTransaction(hub: HubInterface, transactionContext: TransactionContext): Transaction {\n // eslint-disable-next-line deprecation/deprecation\n const client = hub.getClient();\n\n // eslint-disable-next-line deprecation/deprecation\n const transaction = new Transaction(transactionContext, hub as Hub);\n // Since we do not do sampling here, we assume that this is _always_ sampled\n // Any sampling decision happens in OpenTelemetry's sampler\n transaction.initSpanRecorder();\n\n if (client) {\n client.emit('startTransaction', transaction);\n }\n return transaction;\n}\n"],"names":["Transaction"],"mappings":";;;;AAIA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,GAAG,EAAgB,kBAAkB,EAAmC;AACzG;AACA,EAAE,MAAM,MAAO,GAAE,GAAG,CAAC,SAAS,EAAE,CAAA;AAChC;AACA;AACA,EAAE,MAAM,cAAc,IAAIA,gBAAW,CAAC,kBAAkB,EAAE,GAAA,EAAW,CAAA;AACrE;AACA;AACA,EAAE,WAAW,CAAC,gBAAgB,EAAE,CAAA;AAChC;AACA,EAAE,IAAI,MAAM,EAAE;AACd,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAA;AAChD,GAAE;AACF,EAAE,OAAO,WAAW,CAAA;AACpB;;;;"}
|
package/cjs/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const isSentryRequest = require('./utils/isSentryRequest.js');
|
|
|
12
12
|
const getActiveSpan = require('./utils/getActiveSpan.js');
|
|
13
13
|
const trace = require('./trace.js');
|
|
14
14
|
const hub = require('./custom/hub.js');
|
|
15
|
-
const
|
|
15
|
+
const getCurrentHub = require('./custom/getCurrentHub.js');
|
|
16
16
|
const hubextensions = require('./custom/hubextensions.js');
|
|
17
17
|
const setupEventContextTrace = require('./setupEventContextTrace.js');
|
|
18
18
|
const asyncContextStrategy = require('./asyncContextStrategy.js');
|
|
@@ -20,6 +20,8 @@ const contextManager = require('./contextManager.js');
|
|
|
20
20
|
const propagator = require('./propagator.js');
|
|
21
21
|
const spanProcessor = require('./spanProcessor.js');
|
|
22
22
|
const sampler = require('./sampler.js');
|
|
23
|
+
const setupCheck = require('./utils/setupCheck.js');
|
|
24
|
+
const core = require('@sentry/core');
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* The following internal utils are not considered public API and are subject to change.
|
|
@@ -33,15 +35,12 @@ const _INTERNAL = {
|
|
|
33
35
|
|
|
34
36
|
exports.wrapClientClass = client.wrapClientClass;
|
|
35
37
|
exports.getSpanKind = getSpanKind.getSpanKind;
|
|
36
|
-
exports.getSpanFinishScope = spanData.getSpanFinishScope;
|
|
37
38
|
exports.getSpanHub = spanData.getSpanHub;
|
|
38
39
|
exports.getSpanMetadata = spanData.getSpanMetadata;
|
|
39
40
|
exports.getSpanParent = spanData.getSpanParent;
|
|
40
|
-
exports.
|
|
41
|
+
exports.getSpanScopes = spanData.getSpanScopes;
|
|
41
42
|
exports.setSpanMetadata = spanData.setSpanMetadata;
|
|
42
|
-
exports.
|
|
43
|
-
exports.setHubOnContext = contextData.setHubOnContext;
|
|
44
|
-
exports.setPropagationContextOnContext = contextData.setPropagationContextOnContext;
|
|
43
|
+
exports.getScopesFromContext = contextData.getScopesFromContext;
|
|
45
44
|
exports.spanHasAttributes = spanTypes.spanHasAttributes;
|
|
46
45
|
exports.spanHasEvents = spanTypes.spanHasEvents;
|
|
47
46
|
exports.spanHasKind = spanTypes.spanHasKind;
|
|
@@ -54,10 +53,9 @@ exports.getRootSpan = getActiveSpan.getRootSpan;
|
|
|
54
53
|
exports.startInactiveSpan = trace.startInactiveSpan;
|
|
55
54
|
exports.startSpan = trace.startSpan;
|
|
56
55
|
exports.startSpanManual = trace.startSpanManual;
|
|
57
|
-
exports.
|
|
58
|
-
exports.getCurrentHub = hub.getCurrentHub;
|
|
56
|
+
exports.withActiveSpan = trace.withActiveSpan;
|
|
59
57
|
exports.setupGlobalHub = hub.setupGlobalHub;
|
|
60
|
-
exports.
|
|
58
|
+
exports.getCurrentHub = getCurrentHub.getCurrentHub;
|
|
61
59
|
exports.addTracingExtensions = hubextensions.addTracingExtensions;
|
|
62
60
|
exports.setupEventContextTrace = setupEventContextTrace.setupEventContextTrace;
|
|
63
61
|
exports.setOpenTelemetryContextAsyncContextStrategy = asyncContextStrategy.setOpenTelemetryContextAsyncContextStrategy;
|
|
@@ -65,5 +63,7 @@ exports.wrapContextManagerClass = contextManager.wrapContextManagerClass;
|
|
|
65
63
|
exports.SentryPropagator = propagator.SentryPropagator;
|
|
66
64
|
exports.SentrySpanProcessor = spanProcessor.SentrySpanProcessor;
|
|
67
65
|
exports.SentrySampler = sampler.SentrySampler;
|
|
66
|
+
exports.openTelemetrySetupCheck = setupCheck.openTelemetrySetupCheck;
|
|
67
|
+
exports.getClient = core.getClient;
|
|
68
68
|
exports._INTERNAL = _INTERNAL;
|
|
69
69
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { addOriginToSpan } from './utils/addOriginToSpan';\nimport { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';\nimport { getRequestSpanData } from './utils/getRequestSpanData';\n\nexport type { OpenTelemetryClient } from './types';\nexport { wrapClientClass } from './custom/client';\n\nexport { getSpanKind } from './utils/getSpanKind';\nexport {\n getSpanHub,\n getSpanMetadata,\n getSpanParent,\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { addOriginToSpan } from './utils/addOriginToSpan';\nimport { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';\nimport { getRequestSpanData } from './utils/getRequestSpanData';\n\nexport type { OpenTelemetryClient } from './types';\nexport { wrapClientClass } from './custom/client';\n\nexport { getSpanKind } from './utils/getSpanKind';\nexport {\n getSpanHub,\n getSpanMetadata,\n getSpanParent,\n setSpanMetadata,\n getSpanScopes,\n} from './utils/spanData';\n\nexport { getScopesFromContext } from './utils/contextData';\n\nexport {\n spanHasAttributes,\n spanHasEvents,\n spanHasKind,\n spanHasName,\n spanHasParentId,\n spanHasStatus,\n} from './utils/spanTypes';\n\nexport { isSentryRequestSpan } from './utils/isSentryRequest';\n\nexport { getActiveSpan, getRootSpan } from './utils/getActiveSpan';\nexport { startSpan, startSpanManual, startInactiveSpan, withActiveSpan } from './trace';\n\n// eslint-disable-next-line deprecation/deprecation\nexport { setupGlobalHub } from './custom/hub';\n// eslint-disable-next-line deprecation/deprecation\nexport { getCurrentHub } from './custom/getCurrentHub';\nexport { addTracingExtensions } from './custom/hubextensions';\nexport { setupEventContextTrace } from './setupEventContextTrace';\n\nexport { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrategy';\nexport { wrapContextManagerClass } from './contextManager';\nexport { SentryPropagator } from './propagator';\nexport { SentrySpanProcessor } from './spanProcessor';\nexport { SentrySampler } from './sampler';\n\nexport { openTelemetrySetupCheck } from './utils/setupCheck';\n\n// Legacy\nexport { getClient } from '@sentry/core';\n\n/**\n * The following internal utils are not considered public API and are subject to change.\n * @hidden\n */\nconst _INTERNAL = {\n addOriginToSpan,\n maybeCaptureExceptionForTimedEvent,\n getRequestSpanData,\n} as const;\n\nexport { _INTERNAL };\n"],"names":["addOriginToSpan","maybeCaptureExceptionForTimedEvent","getRequestSpanData"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkDA;AACA;AACA;AACA;AACA,MAAM,YAAY;AAClB,mBAAEA,+BAAe;AACjB,sCAAEC,gEAAkC;AACpC,sBAAEC,qCAAkB;AACpB,CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/cjs/propagator.js
CHANGED
|
@@ -9,14 +9,36 @@ const core = require('@opentelemetry/core');
|
|
|
9
9
|
const core$1 = require('@sentry/core');
|
|
10
10
|
const utils = require('@sentry/utils');
|
|
11
11
|
const constants = require('./constants.js');
|
|
12
|
-
const hub = require('./custom/hub.js');
|
|
13
12
|
const contextData = require('./utils/contextData.js');
|
|
14
|
-
const
|
|
13
|
+
const setupCheck = require('./utils/setupCheck.js');
|
|
14
|
+
|
|
15
|
+
/** Get the Sentry propagation context from a span context. */
|
|
16
|
+
function getPropagationContextFromSpanContext(spanContext) {
|
|
17
|
+
const { traceId, spanId, traceFlags, traceState } = spanContext;
|
|
18
|
+
|
|
19
|
+
const dscString = traceState ? traceState.get(constants.SENTRY_TRACE_STATE_DSC) : undefined;
|
|
20
|
+
const dsc = dscString ? utils.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
21
|
+
const parentSpanId = traceState ? traceState.get(constants.SENTRY_TRACE_STATE_PARENT_SPAN_ID) : undefined;
|
|
22
|
+
const sampled = traceFlags === api.TraceFlags.SAMPLED;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
traceId,
|
|
26
|
+
spanId,
|
|
27
|
+
sampled,
|
|
28
|
+
parentSpanId,
|
|
29
|
+
dsc,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
15
32
|
|
|
16
33
|
/**
|
|
17
34
|
* Injects and extracts `sentry-trace` and `baggage` headers from carriers.
|
|
18
35
|
*/
|
|
19
36
|
class SentryPropagator extends core.W3CBaggagePropagator {
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
setupCheck.setIsSetup('SentryPropagator');
|
|
40
|
+
}
|
|
41
|
+
|
|
20
42
|
/**
|
|
21
43
|
* @inheritDoc
|
|
22
44
|
*/
|
|
@@ -27,9 +49,7 @@ class SentryPropagator extends core.W3CBaggagePropagator {
|
|
|
27
49
|
|
|
28
50
|
let baggage = api.propagation.getBaggage(context) || api.propagation.createBaggage({});
|
|
29
51
|
|
|
30
|
-
const
|
|
31
|
-
const { spanId, traceId, sampled } = getSentryTraceData(context, propagationContext);
|
|
32
|
-
const dynamicSamplingContext = propagationContext ? getDsc(context, propagationContext, traceId) : undefined;
|
|
52
|
+
const { dynamicSamplingContext, traceId, spanId, sampled } = getInjectionData(context);
|
|
33
53
|
|
|
34
54
|
if (dynamicSamplingContext) {
|
|
35
55
|
baggage = Object.entries(dynamicSamplingContext).reduce((b, [dscKey, dscValue]) => {
|
|
@@ -60,18 +80,32 @@ class SentryPropagator extends core.W3CBaggagePropagator {
|
|
|
60
80
|
|
|
61
81
|
const propagationContext = utils.propagationContextFromHeaders(sentryTraceHeader, maybeBaggageHeader);
|
|
62
82
|
|
|
63
|
-
//
|
|
64
|
-
const
|
|
83
|
+
// We store the DSC as OTEL trace state on the span context
|
|
84
|
+
const traceState = makeTraceState({
|
|
85
|
+
parentSpanId: propagationContext.parentSpanId,
|
|
86
|
+
dsc: propagationContext.dsc,
|
|
87
|
+
});
|
|
65
88
|
|
|
66
89
|
const spanContext = {
|
|
67
90
|
traceId: propagationContext.traceId,
|
|
68
91
|
spanId: propagationContext.parentSpanId || '',
|
|
69
92
|
isRemote: true,
|
|
70
93
|
traceFlags: propagationContext.sampled === true ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
|
|
94
|
+
traceState,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Add remote parent span context,
|
|
98
|
+
const ctxWithSpanContext = api.trace.setSpanContext(context, spanContext);
|
|
99
|
+
|
|
100
|
+
// Also update the scope on the context (to be sure this is picked up everywhere)
|
|
101
|
+
const scopes = contextData.getScopesFromContext(ctxWithSpanContext);
|
|
102
|
+
const newScopes = {
|
|
103
|
+
scope: scopes ? scopes.scope.clone() : core$1.getCurrentScope().clone(),
|
|
104
|
+
isolationScope: scopes ? scopes.isolationScope : core$1.getIsolationScope(),
|
|
71
105
|
};
|
|
106
|
+
newScopes.scope.setPropagationContext(propagationContext);
|
|
72
107
|
|
|
73
|
-
|
|
74
|
-
return api.trace.setSpanContext(contextWithPropagationContext, spanContext);
|
|
108
|
+
return contextData.setScopesOnContext(ctxWithSpanContext, newScopes);
|
|
75
109
|
}
|
|
76
110
|
|
|
77
111
|
/**
|
|
@@ -82,51 +116,102 @@ class SentryPropagator extends core.W3CBaggagePropagator {
|
|
|
82
116
|
}
|
|
83
117
|
}
|
|
84
118
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return propagationContext.dsc;
|
|
119
|
+
/** Exported for tests. */
|
|
120
|
+
function makeTraceState({
|
|
121
|
+
parentSpanId,
|
|
122
|
+
dsc,
|
|
123
|
+
}) {
|
|
124
|
+
if (!parentSpanId && !dsc) {
|
|
125
|
+
return undefined;
|
|
93
126
|
}
|
|
94
127
|
|
|
95
|
-
//
|
|
96
|
-
const
|
|
97
|
-
const activeSpan = api.trace.getSpan(context);
|
|
98
|
-
const scope = activeSpan ? spanData.getSpanScope(activeSpan) : undefined;
|
|
128
|
+
// We store the DSC as OTEL trace state on the span context
|
|
129
|
+
const dscString = dsc ? utils.dynamicSamplingContextToSentryBaggageHeader(dsc) : undefined;
|
|
99
130
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
131
|
+
const traceStateBase = parentSpanId
|
|
132
|
+
? new core.TraceState().set(constants.SENTRY_TRACE_STATE_PARENT_SPAN_ID, parentSpanId)
|
|
133
|
+
: new core.TraceState();
|
|
103
134
|
|
|
104
|
-
return
|
|
135
|
+
return dscString ? traceStateBase.set(constants.SENTRY_TRACE_STATE_DSC, dscString) : traceStateBase;
|
|
105
136
|
}
|
|
106
137
|
|
|
107
|
-
function
|
|
108
|
-
context,
|
|
109
|
-
propagationContext,
|
|
110
|
-
)
|
|
138
|
+
function getInjectionData(context)
|
|
111
139
|
|
|
112
140
|
{
|
|
113
141
|
const span = api.trace.getSpan(context);
|
|
114
|
-
const
|
|
142
|
+
const spanIsRemote = _optionalChain([span, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2(), 'access', _3 => _3.isRemote]);
|
|
143
|
+
|
|
144
|
+
// If we have a local span, we can just pick everything from it
|
|
145
|
+
if (span && !spanIsRemote) {
|
|
146
|
+
const spanContext = span.spanContext();
|
|
147
|
+
const propagationContext = getPropagationContextFromSpanContext(spanContext);
|
|
148
|
+
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, spanContext.traceId);
|
|
149
|
+
return {
|
|
150
|
+
dynamicSamplingContext,
|
|
151
|
+
traceId: spanContext.traceId,
|
|
152
|
+
spanId: spanContext.spanId,
|
|
153
|
+
sampled: spanContext.traceFlags === api.TraceFlags.SAMPLED,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
115
156
|
|
|
116
|
-
|
|
157
|
+
// Else we try to use the propagation context from the scope
|
|
158
|
+
const scope = _optionalChain([contextData.getScopesFromContext, 'call', _4 => _4(context), 'optionalAccess', _5 => _5.scope]);
|
|
159
|
+
if (scope) {
|
|
160
|
+
const propagationContext = scope.getPropagationContext();
|
|
161
|
+
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
|
|
162
|
+
return {
|
|
163
|
+
dynamicSamplingContext,
|
|
164
|
+
traceId: propagationContext.traceId,
|
|
165
|
+
spanId: propagationContext.spanId,
|
|
166
|
+
sampled: propagationContext.sampled,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Else, we look at the remote span context
|
|
171
|
+
const spanContext = api.trace.getSpanContext(context);
|
|
172
|
+
if (spanContext) {
|
|
173
|
+
const propagationContext = getPropagationContextFromSpanContext(spanContext);
|
|
174
|
+
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, spanContext.traceId);
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
dynamicSamplingContext,
|
|
178
|
+
traceId: spanContext.traceId,
|
|
179
|
+
spanId: spanContext.spanId,
|
|
180
|
+
sampled: spanContext.traceFlags === api.TraceFlags.SAMPLED,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// If we have neither, there is nothing much we can do, but that should not happen usually
|
|
185
|
+
// Unless there is a detached OTEL context being passed around
|
|
186
|
+
return {
|
|
187
|
+
dynamicSamplingContext: undefined,
|
|
188
|
+
traceId: undefined,
|
|
189
|
+
spanId: undefined,
|
|
190
|
+
sampled: undefined,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Get the DSC from a context, or fall back to use the one from the client. */
|
|
195
|
+
function getDynamicSamplingContext(
|
|
196
|
+
propagationContext,
|
|
197
|
+
traceId,
|
|
198
|
+
) {
|
|
199
|
+
// If we have a DSC on the propagation context, we just use it
|
|
200
|
+
if (_optionalChain([propagationContext, 'optionalAccess', _6 => _6.dsc])) {
|
|
201
|
+
return propagationContext.dsc;
|
|
202
|
+
}
|
|
117
203
|
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
// If we have an active span that is remote, we do not want to use the spanId, as we don't want to attach it to the parent span
|
|
121
|
-
// If `isRemote === true`, the span is bascially virtual
|
|
122
|
-
// If we don't have a local active span, we use the generated spanId from the propagationContext
|
|
123
|
-
const spanId = spanContext && !spanContext.isRemote ? spanContext.spanId : _optionalChain([propagationContext, 'optionalAccess', _2 => _2.spanId]);
|
|
204
|
+
// Else, we try to generate a new one
|
|
205
|
+
const client = core$1.getClient();
|
|
124
206
|
|
|
125
|
-
|
|
126
|
-
|
|
207
|
+
if (client) {
|
|
208
|
+
return core$1.getDynamicSamplingContextFromClient(traceId || propagationContext.traceId, client);
|
|
209
|
+
}
|
|
127
210
|
|
|
128
|
-
return
|
|
211
|
+
return undefined;
|
|
129
212
|
}
|
|
130
213
|
|
|
131
214
|
exports.SentryPropagator = SentryPropagator;
|
|
215
|
+
exports.getPropagationContextFromSpanContext = getPropagationContextFromSpanContext;
|
|
216
|
+
exports.makeTraceState = makeTraceState;
|
|
132
217
|
//# sourceMappingURL=propagator.js.map
|