@sentry/profiling-node 8.9.2 → 8.10.0
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/bindings/cpu_profiler.cc +2 -2
- package/lib/cjs/index.js +743 -33
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +744 -34
- package/lib/esm/index.js.map +1 -1
- package/lib/sentry_cpu_profiler-darwin-arm64-108.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-arm64-115.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-arm64-127.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-arm64-93.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-108.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-115.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-127.node +0 -0
- package/lib/sentry_cpu_profiler-darwin-x64-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-glibc-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-arm64-musl-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-glibc-93.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-108.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-115.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-127.node +0 -0
- package/lib/sentry_cpu_profiler-linux-x64-musl-93.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-108.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-115.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-127.node +0 -0
- package/lib/sentry_cpu_profiler-win32-x64-93.node +0 -0
- package/lib/types/core/src/asyncContext/index.d.ts +14 -0
- package/lib/types/core/src/asyncContext/index.d.ts.map +1 -0
- package/lib/types/core/src/asyncContext/stackStrategy.d.ts +52 -0
- package/lib/types/core/src/asyncContext/stackStrategy.d.ts.map +1 -0
- package/lib/types/core/src/asyncContext/types.d.ts +47 -0
- package/lib/types/core/src/asyncContext/types.d.ts.map +1 -0
- package/lib/types/core/src/carrier.d.ts +37 -0
- package/lib/types/core/src/carrier.d.ts.map +1 -0
- package/lib/types/core/src/constants.d.ts +2 -0
- package/lib/types/core/src/constants.d.ts.map +1 -0
- package/lib/types/core/src/currentScopes.d.ts +55 -0
- package/lib/types/core/src/currentScopes.d.ts.map +1 -0
- package/lib/types/core/src/debug-build.d.ts.map +1 -0
- package/lib/types/core/src/defaultScopes.d.ts +6 -0
- package/lib/types/core/src/defaultScopes.d.ts.map +1 -0
- package/lib/types/core/src/envelope.d.ts +15 -0
- package/lib/types/core/src/envelope.d.ts.map +1 -0
- package/lib/types/core/src/metrics/constants.d.ts +19 -0
- package/lib/types/core/src/metrics/constants.d.ts.map +1 -0
- package/lib/types/core/src/metrics/metric-summary.d.ts +13 -0
- package/lib/types/core/src/metrics/metric-summary.d.ts.map +1 -0
- package/lib/types/core/src/metrics/types.d.ts +5 -0
- package/lib/types/core/src/metrics/types.d.ts.map +1 -0
- package/lib/types/core/src/scope.d.ts +211 -0
- package/lib/types/core/src/scope.d.ts.map +1 -0
- package/lib/types/core/src/semanticAttributes.d.ts +33 -0
- package/lib/types/core/src/semanticAttributes.d.ts.map +1 -0
- package/lib/types/core/src/session.d.ts +35 -0
- package/lib/types/core/src/session.d.ts.map +1 -0
- package/lib/types/core/src/tracing/dynamicSamplingContext.d.ts +24 -0
- package/lib/types/core/src/tracing/dynamicSamplingContext.d.ts.map +1 -0
- package/lib/types/core/src/tracing/logSpans.d.ts +10 -0
- package/lib/types/core/src/tracing/logSpans.d.ts.map +1 -0
- package/lib/types/core/src/tracing/measurement.d.ts +10 -0
- package/lib/types/core/src/tracing/measurement.d.ts.map +1 -0
- package/lib/types/core/src/tracing/sampling.d.ts +9 -0
- package/lib/types/core/src/tracing/sampling.d.ts.map +1 -0
- package/lib/types/core/src/tracing/sentryNonRecordingSpan.d.ts +26 -0
- package/lib/types/core/src/tracing/sentryNonRecordingSpan.d.ts.map +1 -0
- package/lib/types/core/src/tracing/sentrySpan.d.ts +86 -0
- package/lib/types/core/src/tracing/sentrySpan.d.ts.map +1 -0
- package/lib/types/core/src/tracing/spanstatus.d.ts +17 -0
- package/lib/types/core/src/tracing/spanstatus.d.ts.map +1 -0
- package/lib/types/core/src/tracing/trace.d.ts +76 -0
- package/lib/types/core/src/tracing/trace.d.ts.map +1 -0
- package/lib/types/core/src/tracing/utils.d.ts +13 -0
- package/lib/types/core/src/tracing/utils.d.ts.map +1 -0
- package/lib/types/core/src/utils/handleCallbackErrors.d.ts +13 -0
- package/lib/types/core/src/utils/handleCallbackErrors.d.ts.map +1 -0
- package/lib/types/core/src/utils/hasTracingEnabled.d.ts +8 -0
- package/lib/types/core/src/utils/hasTracingEnabled.d.ts.map +1 -0
- package/lib/types/core/src/utils/parseSampleRate.d.ts +9 -0
- package/lib/types/core/src/utils/parseSampleRate.d.ts.map +1 -0
- package/lib/types/core/src/utils/spanOnScope.d.ts +17 -0
- package/lib/types/core/src/utils/spanOnScope.d.ts.map +1 -0
- package/lib/types/core/src/utils/spanUtils.d.ts +74 -0
- package/lib/types/core/src/utils/spanUtils.d.ts.map +1 -0
- package/lib/types/profiling-node/src/cpu_profiler.d.ts.map +1 -0
- package/lib/types/profiling-node/src/debug-build.d.ts +7 -0
- package/lib/types/profiling-node/src/debug-build.d.ts.map +1 -0
- package/lib/types/profiling-node/src/index.d.ts.map +1 -0
- package/lib/types/{integration.d.ts → profiling-node/src/integration.d.ts} +18 -0
- package/lib/types/profiling-node/src/integration.d.ts.map +1 -0
- package/lib/types/profiling-node/src/nodeVersion.d.ts.map +1 -0
- package/lib/types/profiling-node/src/spanProfileUtils.d.ts.map +1 -0
- package/lib/types/profiling-node/src/types.d.ts.map +1 -0
- package/lib/types/{utils.d.ts → profiling-node/src/utils.d.ts} +3 -1
- package/lib/types/profiling-node/src/utils.d.ts.map +1 -0
- package/lib/types-ts3.8/core/src/asyncContext/index.d.ts +14 -0
- package/lib/types-ts3.8/core/src/asyncContext/stackStrategy.d.ts +52 -0
- package/lib/types-ts3.8/core/src/asyncContext/types.d.ts +47 -0
- package/lib/types-ts3.8/core/src/carrier.d.ts +37 -0
- package/lib/types-ts3.8/core/src/constants.d.ts +2 -0
- package/lib/types-ts3.8/core/src/currentScopes.d.ts +55 -0
- package/lib/types-ts3.8/core/src/defaultScopes.d.ts +6 -0
- package/lib/types-ts3.8/core/src/envelope.d.ts +18 -0
- package/lib/types-ts3.8/core/src/metrics/constants.d.ts +19 -0
- package/lib/types-ts3.8/core/src/metrics/metric-summary.d.ts +13 -0
- package/lib/types-ts3.8/core/src/metrics/types.d.ts +5 -0
- package/lib/types-ts3.8/core/src/scope.d.ts +211 -0
- package/lib/types-ts3.8/core/src/semanticAttributes.d.ts +33 -0
- package/lib/types-ts3.8/core/src/session.d.ts +35 -0
- package/lib/types-ts3.8/core/src/tracing/dynamicSamplingContext.d.ts +24 -0
- package/lib/types-ts3.8/core/src/tracing/logSpans.d.ts +10 -0
- package/lib/types-ts3.8/core/src/tracing/measurement.d.ts +10 -0
- package/lib/types-ts3.8/core/src/tracing/sampling.d.ts +12 -0
- package/lib/types-ts3.8/core/src/tracing/sentryNonRecordingSpan.d.ts +26 -0
- package/lib/types-ts3.8/core/src/tracing/sentrySpan.d.ts +86 -0
- package/lib/types-ts3.8/core/src/tracing/spanstatus.d.ts +17 -0
- package/lib/types-ts3.8/core/src/tracing/trace.d.ts +76 -0
- package/lib/types-ts3.8/core/src/tracing/utils.d.ts +13 -0
- package/lib/types-ts3.8/core/src/utils/handleCallbackErrors.d.ts +13 -0
- package/lib/types-ts3.8/core/src/utils/hasTracingEnabled.d.ts +8 -0
- package/lib/types-ts3.8/core/src/utils/parseSampleRate.d.ts +9 -0
- package/lib/types-ts3.8/core/src/utils/spanOnScope.d.ts +17 -0
- package/lib/types-ts3.8/core/src/utils/spanUtils.d.ts +74 -0
- package/lib/types-ts3.8/profiling-node/src/debug-build.d.ts +7 -0
- package/lib/types-ts3.8/{integration.d.ts → profiling-node/src/integration.d.ts} +18 -0
- package/lib/types-ts3.8/{utils.d.ts → profiling-node/src/utils.d.ts} +3 -1
- package/package.json +5 -5
- package/lib/types/cpu_profiler.d.ts.map +0 -1
- package/lib/types/debug-build.d.ts.map +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/integration.d.ts.map +0 -1
- package/lib/types/nodeVersion.d.ts.map +0 -1
- package/lib/types/spanProfileUtils.d.ts.map +0 -1
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/utils.d.ts.map +0 -1
- /package/lib/types/{debug-build.d.ts → core/src/debug-build.d.ts} +0 -0
- /package/lib/types/{cpu_profiler.d.ts → profiling-node/src/cpu_profiler.d.ts} +0 -0
- /package/lib/types/{index.d.ts → profiling-node/src/index.d.ts} +0 -0
- /package/lib/types/{nodeVersion.d.ts → profiling-node/src/nodeVersion.d.ts} +0 -0
- /package/lib/types/{spanProfileUtils.d.ts → profiling-node/src/spanProfileUtils.d.ts} +0 -0
- /package/lib/types/{types.d.ts → profiling-node/src/types.d.ts} +0 -0
- /package/lib/types-ts3.8/{debug-build.d.ts → core/src/debug-build.d.ts} +0 -0
- /package/lib/types-ts3.8/{cpu_profiler.d.ts → profiling-node/src/cpu_profiler.d.ts} +0 -0
- /package/lib/types-ts3.8/{index.d.ts → profiling-node/src/index.d.ts} +0 -0
- /package/lib/types-ts3.8/{nodeVersion.d.ts → profiling-node/src/nodeVersion.d.ts} +0 -0
- /package/lib/types-ts3.8/{spanProfileUtils.d.ts → profiling-node/src/spanProfileUtils.d.ts} +0 -0
- /package/lib/types-ts3.8/{types.d.ts → profiling-node/src/types.d.ts} +0 -0
package/lib/cjs/index.js
CHANGED
|
@@ -18,6 +18,666 @@ const os = require('os');
|
|
|
18
18
|
const process$1 = require('process');
|
|
19
19
|
const worker_threads = require('worker_threads');
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Updates a session object with the properties passed in the context.
|
|
23
|
+
*
|
|
24
|
+
* Note that this function mutates the passed object and returns void.
|
|
25
|
+
* (Had to do this instead of returning a new and updated session because closing and sending a session
|
|
26
|
+
* makes an update to the session after it was passed to the sending logic.
|
|
27
|
+
* @see BaseClient.captureSession )
|
|
28
|
+
*
|
|
29
|
+
* @param session the `Session` to update
|
|
30
|
+
* @param context the `SessionContext` holding the properties that should be updated in @param session
|
|
31
|
+
*/
|
|
32
|
+
// eslint-disable-next-line complexity
|
|
33
|
+
function updateSession(session, context = {}) {
|
|
34
|
+
if (context.user) {
|
|
35
|
+
if (!session.ipAddress && context.user.ip_address) {
|
|
36
|
+
session.ipAddress = context.user.ip_address;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!session.did && !context.did) {
|
|
40
|
+
session.did = context.user.id || context.user.email || context.user.username;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
session.timestamp = context.timestamp || utils.timestampInSeconds();
|
|
45
|
+
|
|
46
|
+
if (context.abnormal_mechanism) {
|
|
47
|
+
session.abnormal_mechanism = context.abnormal_mechanism;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (context.ignoreDuration) {
|
|
51
|
+
session.ignoreDuration = context.ignoreDuration;
|
|
52
|
+
}
|
|
53
|
+
if (context.sid) {
|
|
54
|
+
// Good enough uuid validation. — Kamil
|
|
55
|
+
session.sid = context.sid.length === 32 ? context.sid : utils.uuid4();
|
|
56
|
+
}
|
|
57
|
+
if (context.init !== undefined) {
|
|
58
|
+
session.init = context.init;
|
|
59
|
+
}
|
|
60
|
+
if (!session.did && context.did) {
|
|
61
|
+
session.did = `${context.did}`;
|
|
62
|
+
}
|
|
63
|
+
if (typeof context.started === 'number') {
|
|
64
|
+
session.started = context.started;
|
|
65
|
+
}
|
|
66
|
+
if (session.ignoreDuration) {
|
|
67
|
+
session.duration = undefined;
|
|
68
|
+
} else if (typeof context.duration === 'number') {
|
|
69
|
+
session.duration = context.duration;
|
|
70
|
+
} else {
|
|
71
|
+
const duration = session.timestamp - session.started;
|
|
72
|
+
session.duration = duration >= 0 ? duration : 0;
|
|
73
|
+
}
|
|
74
|
+
if (context.release) {
|
|
75
|
+
session.release = context.release;
|
|
76
|
+
}
|
|
77
|
+
if (context.environment) {
|
|
78
|
+
session.environment = context.environment;
|
|
79
|
+
}
|
|
80
|
+
if (!session.ipAddress && context.ipAddress) {
|
|
81
|
+
session.ipAddress = context.ipAddress;
|
|
82
|
+
}
|
|
83
|
+
if (!session.userAgent && context.userAgent) {
|
|
84
|
+
session.userAgent = context.userAgent;
|
|
85
|
+
}
|
|
86
|
+
if (typeof context.errors === 'number') {
|
|
87
|
+
session.errors = context.errors;
|
|
88
|
+
}
|
|
89
|
+
if (context.status) {
|
|
90
|
+
session.status = context.status;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const SCOPE_SPAN_FIELD = '_sentrySpan';
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Set the active span for a given scope.
|
|
98
|
+
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
|
|
99
|
+
*/
|
|
100
|
+
function _setSpanForScope(scope, span) {
|
|
101
|
+
if (span) {
|
|
102
|
+
utils.addNonEnumerableProperty(scope , SCOPE_SPAN_FIELD, span);
|
|
103
|
+
} else {
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
105
|
+
delete (scope )[SCOPE_SPAN_FIELD];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get the active span for a given scope.
|
|
111
|
+
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
|
|
112
|
+
*/
|
|
113
|
+
function _getSpanForScope(scope) {
|
|
114
|
+
return scope[SCOPE_SPAN_FIELD];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Default value for maximum number of breadcrumbs added to an event.
|
|
119
|
+
*/
|
|
120
|
+
const DEFAULT_MAX_BREADCRUMBS = 100;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Holds additional event information.
|
|
124
|
+
*/
|
|
125
|
+
class ScopeClass {
|
|
126
|
+
/** Flag if notifying is happening. */
|
|
127
|
+
|
|
128
|
+
/** Callback for client to receive scope changes. */
|
|
129
|
+
|
|
130
|
+
/** Callback list that will be called during event processing. */
|
|
131
|
+
|
|
132
|
+
/** Array of breadcrumbs. */
|
|
133
|
+
|
|
134
|
+
/** User */
|
|
135
|
+
|
|
136
|
+
/** Tags */
|
|
137
|
+
|
|
138
|
+
/** Extra */
|
|
139
|
+
|
|
140
|
+
/** Contexts */
|
|
141
|
+
|
|
142
|
+
/** Attachments */
|
|
143
|
+
|
|
144
|
+
/** Propagation Context for distributed tracing */
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
|
|
148
|
+
* sent to Sentry
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
/** Fingerprint */
|
|
152
|
+
|
|
153
|
+
/** Severity */
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Transaction Name
|
|
157
|
+
*
|
|
158
|
+
* IMPORTANT: The transaction name on the scope has nothing to do with root spans/transaction objects.
|
|
159
|
+
* It's purpose is to assign a transaction to the scope that's added to non-transaction events.
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/** Session */
|
|
163
|
+
|
|
164
|
+
/** Request Mode Session Status */
|
|
165
|
+
|
|
166
|
+
/** The client on this scope */
|
|
167
|
+
|
|
168
|
+
/** Contains the last event id of a captured event. */
|
|
169
|
+
|
|
170
|
+
// NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.
|
|
171
|
+
|
|
172
|
+
constructor() {
|
|
173
|
+
this._notifyingListeners = false;
|
|
174
|
+
this._scopeListeners = [];
|
|
175
|
+
this._eventProcessors = [];
|
|
176
|
+
this._breadcrumbs = [];
|
|
177
|
+
this._attachments = [];
|
|
178
|
+
this._user = {};
|
|
179
|
+
this._tags = {};
|
|
180
|
+
this._extra = {};
|
|
181
|
+
this._contexts = {};
|
|
182
|
+
this._sdkProcessingMetadata = {};
|
|
183
|
+
this._propagationContext = utils.generatePropagationContext();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @inheritDoc
|
|
188
|
+
*/
|
|
189
|
+
clone() {
|
|
190
|
+
const newScope = new ScopeClass();
|
|
191
|
+
newScope._breadcrumbs = [...this._breadcrumbs];
|
|
192
|
+
newScope._tags = { ...this._tags };
|
|
193
|
+
newScope._extra = { ...this._extra };
|
|
194
|
+
newScope._contexts = { ...this._contexts };
|
|
195
|
+
newScope._user = this._user;
|
|
196
|
+
newScope._level = this._level;
|
|
197
|
+
newScope._session = this._session;
|
|
198
|
+
newScope._transactionName = this._transactionName;
|
|
199
|
+
newScope._fingerprint = this._fingerprint;
|
|
200
|
+
newScope._eventProcessors = [...this._eventProcessors];
|
|
201
|
+
newScope._requestSession = this._requestSession;
|
|
202
|
+
newScope._attachments = [...this._attachments];
|
|
203
|
+
newScope._sdkProcessingMetadata = { ...this._sdkProcessingMetadata };
|
|
204
|
+
newScope._propagationContext = { ...this._propagationContext };
|
|
205
|
+
newScope._client = this._client;
|
|
206
|
+
newScope._lastEventId = this._lastEventId;
|
|
207
|
+
|
|
208
|
+
_setSpanForScope(newScope, _getSpanForScope(this));
|
|
209
|
+
|
|
210
|
+
return newScope;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @inheritDoc
|
|
215
|
+
*/
|
|
216
|
+
setClient(client) {
|
|
217
|
+
this._client = client;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @inheritDoc
|
|
222
|
+
*/
|
|
223
|
+
setLastEventId(lastEventId) {
|
|
224
|
+
this._lastEventId = lastEventId;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @inheritDoc
|
|
229
|
+
*/
|
|
230
|
+
getClient() {
|
|
231
|
+
return this._client ;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @inheritDoc
|
|
236
|
+
*/
|
|
237
|
+
lastEventId() {
|
|
238
|
+
return this._lastEventId;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @inheritDoc
|
|
243
|
+
*/
|
|
244
|
+
addScopeListener(callback) {
|
|
245
|
+
this._scopeListeners.push(callback);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @inheritDoc
|
|
250
|
+
*/
|
|
251
|
+
addEventProcessor(callback) {
|
|
252
|
+
this._eventProcessors.push(callback);
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @inheritDoc
|
|
258
|
+
*/
|
|
259
|
+
setUser(user) {
|
|
260
|
+
// If null is passed we want to unset everything, but still define keys,
|
|
261
|
+
// so that later down in the pipeline any existing values are cleared.
|
|
262
|
+
this._user = user || {
|
|
263
|
+
email: undefined,
|
|
264
|
+
id: undefined,
|
|
265
|
+
ip_address: undefined,
|
|
266
|
+
username: undefined,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
if (this._session) {
|
|
270
|
+
updateSession(this._session, { user });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
this._notifyScopeListeners();
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @inheritDoc
|
|
279
|
+
*/
|
|
280
|
+
getUser() {
|
|
281
|
+
return this._user;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @inheritDoc
|
|
286
|
+
*/
|
|
287
|
+
getRequestSession() {
|
|
288
|
+
return this._requestSession;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* @inheritDoc
|
|
293
|
+
*/
|
|
294
|
+
setRequestSession(requestSession) {
|
|
295
|
+
this._requestSession = requestSession;
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @inheritDoc
|
|
301
|
+
*/
|
|
302
|
+
setTags(tags) {
|
|
303
|
+
this._tags = {
|
|
304
|
+
...this._tags,
|
|
305
|
+
...tags,
|
|
306
|
+
};
|
|
307
|
+
this._notifyScopeListeners();
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @inheritDoc
|
|
313
|
+
*/
|
|
314
|
+
setTag(key, value) {
|
|
315
|
+
this._tags = { ...this._tags, [key]: value };
|
|
316
|
+
this._notifyScopeListeners();
|
|
317
|
+
return this;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* @inheritDoc
|
|
322
|
+
*/
|
|
323
|
+
setExtras(extras) {
|
|
324
|
+
this._extra = {
|
|
325
|
+
...this._extra,
|
|
326
|
+
...extras,
|
|
327
|
+
};
|
|
328
|
+
this._notifyScopeListeners();
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @inheritDoc
|
|
334
|
+
*/
|
|
335
|
+
setExtra(key, extra) {
|
|
336
|
+
this._extra = { ...this._extra, [key]: extra };
|
|
337
|
+
this._notifyScopeListeners();
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @inheritDoc
|
|
343
|
+
*/
|
|
344
|
+
setFingerprint(fingerprint) {
|
|
345
|
+
this._fingerprint = fingerprint;
|
|
346
|
+
this._notifyScopeListeners();
|
|
347
|
+
return this;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* @inheritDoc
|
|
352
|
+
*/
|
|
353
|
+
setLevel(level) {
|
|
354
|
+
this._level = level;
|
|
355
|
+
this._notifyScopeListeners();
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* @inheritDoc
|
|
361
|
+
*/
|
|
362
|
+
setTransactionName(name) {
|
|
363
|
+
this._transactionName = name;
|
|
364
|
+
this._notifyScopeListeners();
|
|
365
|
+
return this;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* @inheritDoc
|
|
370
|
+
*/
|
|
371
|
+
setContext(key, context) {
|
|
372
|
+
if (context === null) {
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
374
|
+
delete this._contexts[key];
|
|
375
|
+
} else {
|
|
376
|
+
this._contexts[key] = context;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
this._notifyScopeListeners();
|
|
380
|
+
return this;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* @inheritDoc
|
|
385
|
+
*/
|
|
386
|
+
setSession(session) {
|
|
387
|
+
if (!session) {
|
|
388
|
+
delete this._session;
|
|
389
|
+
} else {
|
|
390
|
+
this._session = session;
|
|
391
|
+
}
|
|
392
|
+
this._notifyScopeListeners();
|
|
393
|
+
return this;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* @inheritDoc
|
|
398
|
+
*/
|
|
399
|
+
getSession() {
|
|
400
|
+
return this._session;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* @inheritDoc
|
|
405
|
+
*/
|
|
406
|
+
update(captureContext) {
|
|
407
|
+
if (!captureContext) {
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const scopeToMerge = typeof captureContext === 'function' ? captureContext(this) : captureContext;
|
|
412
|
+
|
|
413
|
+
const [scopeInstance, requestSession] =
|
|
414
|
+
scopeToMerge instanceof Scope
|
|
415
|
+
? [scopeToMerge.getScopeData(), scopeToMerge.getRequestSession()]
|
|
416
|
+
: utils.isPlainObject(scopeToMerge)
|
|
417
|
+
? [captureContext , (captureContext ).requestSession]
|
|
418
|
+
: [];
|
|
419
|
+
|
|
420
|
+
const { tags, extra, user, contexts, level, fingerprint = [], propagationContext } = scopeInstance || {};
|
|
421
|
+
|
|
422
|
+
this._tags = { ...this._tags, ...tags };
|
|
423
|
+
this._extra = { ...this._extra, ...extra };
|
|
424
|
+
this._contexts = { ...this._contexts, ...contexts };
|
|
425
|
+
|
|
426
|
+
if (user && Object.keys(user).length) {
|
|
427
|
+
this._user = user;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (level) {
|
|
431
|
+
this._level = level;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (fingerprint.length) {
|
|
435
|
+
this._fingerprint = fingerprint;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (propagationContext) {
|
|
439
|
+
this._propagationContext = propagationContext;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (requestSession) {
|
|
443
|
+
this._requestSession = requestSession;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return this;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* @inheritDoc
|
|
451
|
+
*/
|
|
452
|
+
clear() {
|
|
453
|
+
// client is not cleared here on purpose!
|
|
454
|
+
this._breadcrumbs = [];
|
|
455
|
+
this._tags = {};
|
|
456
|
+
this._extra = {};
|
|
457
|
+
this._user = {};
|
|
458
|
+
this._contexts = {};
|
|
459
|
+
this._level = undefined;
|
|
460
|
+
this._transactionName = undefined;
|
|
461
|
+
this._fingerprint = undefined;
|
|
462
|
+
this._requestSession = undefined;
|
|
463
|
+
this._session = undefined;
|
|
464
|
+
_setSpanForScope(this, undefined);
|
|
465
|
+
this._attachments = [];
|
|
466
|
+
this._propagationContext = utils.generatePropagationContext();
|
|
467
|
+
|
|
468
|
+
this._notifyScopeListeners();
|
|
469
|
+
return this;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @inheritDoc
|
|
474
|
+
*/
|
|
475
|
+
addBreadcrumb(breadcrumb, maxBreadcrumbs) {
|
|
476
|
+
const maxCrumbs = typeof maxBreadcrumbs === 'number' ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS;
|
|
477
|
+
|
|
478
|
+
// No data has been changed, so don't notify scope listeners
|
|
479
|
+
if (maxCrumbs <= 0) {
|
|
480
|
+
return this;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const mergedBreadcrumb = {
|
|
484
|
+
timestamp: utils.dateTimestampInSeconds(),
|
|
485
|
+
...breadcrumb,
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const breadcrumbs = this._breadcrumbs;
|
|
489
|
+
breadcrumbs.push(mergedBreadcrumb);
|
|
490
|
+
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
|
|
491
|
+
|
|
492
|
+
this._notifyScopeListeners();
|
|
493
|
+
|
|
494
|
+
return this;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* @inheritDoc
|
|
499
|
+
*/
|
|
500
|
+
getLastBreadcrumb() {
|
|
501
|
+
return this._breadcrumbs[this._breadcrumbs.length - 1];
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* @inheritDoc
|
|
506
|
+
*/
|
|
507
|
+
clearBreadcrumbs() {
|
|
508
|
+
this._breadcrumbs = [];
|
|
509
|
+
this._notifyScopeListeners();
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @inheritDoc
|
|
515
|
+
*/
|
|
516
|
+
addAttachment(attachment) {
|
|
517
|
+
this._attachments.push(attachment);
|
|
518
|
+
return this;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* @inheritDoc
|
|
523
|
+
*/
|
|
524
|
+
clearAttachments() {
|
|
525
|
+
this._attachments = [];
|
|
526
|
+
return this;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** @inheritDoc */
|
|
530
|
+
getScopeData() {
|
|
531
|
+
return {
|
|
532
|
+
breadcrumbs: this._breadcrumbs,
|
|
533
|
+
attachments: this._attachments,
|
|
534
|
+
contexts: this._contexts,
|
|
535
|
+
tags: this._tags,
|
|
536
|
+
extra: this._extra,
|
|
537
|
+
user: this._user,
|
|
538
|
+
level: this._level,
|
|
539
|
+
fingerprint: this._fingerprint || [],
|
|
540
|
+
eventProcessors: this._eventProcessors,
|
|
541
|
+
propagationContext: this._propagationContext,
|
|
542
|
+
sdkProcessingMetadata: this._sdkProcessingMetadata,
|
|
543
|
+
transactionName: this._transactionName,
|
|
544
|
+
span: _getSpanForScope(this),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* @inheritDoc
|
|
550
|
+
*/
|
|
551
|
+
setSDKProcessingMetadata(newData) {
|
|
552
|
+
this._sdkProcessingMetadata = { ...this._sdkProcessingMetadata, ...newData };
|
|
553
|
+
|
|
554
|
+
return this;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* @inheritDoc
|
|
559
|
+
*/
|
|
560
|
+
setPropagationContext(context) {
|
|
561
|
+
this._propagationContext = context;
|
|
562
|
+
return this;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* @inheritDoc
|
|
567
|
+
*/
|
|
568
|
+
getPropagationContext() {
|
|
569
|
+
return this._propagationContext;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @inheritDoc
|
|
574
|
+
*/
|
|
575
|
+
captureException(exception, hint) {
|
|
576
|
+
const eventId = hint && hint.event_id ? hint.event_id : utils.uuid4();
|
|
577
|
+
|
|
578
|
+
if (!this._client) {
|
|
579
|
+
utils.logger.warn('No client configured on scope - will not capture exception!');
|
|
580
|
+
return eventId;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const syntheticException = new Error('Sentry syntheticException');
|
|
584
|
+
|
|
585
|
+
this._client.captureException(
|
|
586
|
+
exception,
|
|
587
|
+
{
|
|
588
|
+
originalException: exception,
|
|
589
|
+
syntheticException,
|
|
590
|
+
...hint,
|
|
591
|
+
event_id: eventId,
|
|
592
|
+
},
|
|
593
|
+
this,
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
return eventId;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* @inheritDoc
|
|
601
|
+
*/
|
|
602
|
+
captureMessage(message, level, hint) {
|
|
603
|
+
const eventId = hint && hint.event_id ? hint.event_id : utils.uuid4();
|
|
604
|
+
|
|
605
|
+
if (!this._client) {
|
|
606
|
+
utils.logger.warn('No client configured on scope - will not capture message!');
|
|
607
|
+
return eventId;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const syntheticException = new Error(message);
|
|
611
|
+
|
|
612
|
+
this._client.captureMessage(
|
|
613
|
+
message,
|
|
614
|
+
level,
|
|
615
|
+
{
|
|
616
|
+
originalException: message,
|
|
617
|
+
syntheticException,
|
|
618
|
+
...hint,
|
|
619
|
+
event_id: eventId,
|
|
620
|
+
},
|
|
621
|
+
this,
|
|
622
|
+
);
|
|
623
|
+
|
|
624
|
+
return eventId;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* @inheritDoc
|
|
629
|
+
*/
|
|
630
|
+
captureEvent(event, hint) {
|
|
631
|
+
const eventId = hint && hint.event_id ? hint.event_id : utils.uuid4();
|
|
632
|
+
|
|
633
|
+
if (!this._client) {
|
|
634
|
+
utils.logger.warn('No client configured on scope - will not capture event!');
|
|
635
|
+
return eventId;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
this._client.captureEvent(event, { ...hint, event_id: eventId }, this);
|
|
639
|
+
|
|
640
|
+
return eventId;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* This will be called on every set call.
|
|
645
|
+
*/
|
|
646
|
+
_notifyScopeListeners() {
|
|
647
|
+
// We need this check for this._notifyingListeners to be able to work on scope during updates
|
|
648
|
+
// If this check is not here we'll produce endless recursion when something is done with the scope
|
|
649
|
+
// during the callback.
|
|
650
|
+
if (!this._notifyingListeners) {
|
|
651
|
+
this._notifyingListeners = true;
|
|
652
|
+
this._scopeListeners.forEach(callback => {
|
|
653
|
+
callback(this);
|
|
654
|
+
});
|
|
655
|
+
this._notifyingListeners = false;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// NOTE: By exporting this here as const & type, instead of doing `export class`,
|
|
661
|
+
// We can get the correct class when importing from `@sentry/core`, but the original type (from `@sentry/types`)
|
|
662
|
+
// This is helpful for interop, e.g. when doing `import type { Scope } from '@sentry/node';` (which re-exports this)
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Holds additional event information.
|
|
666
|
+
*/
|
|
667
|
+
const Scope = ScopeClass;
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Holds additional event information.
|
|
671
|
+
*/
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Get the global scope.
|
|
675
|
+
* This scope is applied to _all_ events.
|
|
676
|
+
*/
|
|
677
|
+
function getGlobalScope() {
|
|
678
|
+
return utils.getGlobalSingleton('globalScope', () => new Scope());
|
|
679
|
+
}
|
|
680
|
+
|
|
21
681
|
/**
|
|
22
682
|
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
|
|
23
683
|
*
|
|
@@ -202,12 +862,12 @@ const CpuProfilerBindings = new Bindings();
|
|
|
202
862
|
const NODE_VERSION = utils.parseSemver(process.versions.node) ;
|
|
203
863
|
const NODE_MAJOR = NODE_VERSION.major;
|
|
204
864
|
|
|
205
|
-
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable max-lines */
|
|
865
|
+
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable max-lines */
|
|
206
866
|
|
|
207
867
|
// We require the file because if we import it, it will be included in the bundle.
|
|
208
868
|
// I guess tsc does not check file contents when it's imported.
|
|
209
|
-
const
|
|
210
|
-
const
|
|
869
|
+
const PROFILER_THREAD_ID_STRING = String(worker_threads.threadId);
|
|
870
|
+
const PROFILER_THREAD_NAME = worker_threads.isMainThread ? 'main' : 'worker';
|
|
211
871
|
const FORMAT_VERSION = '1';
|
|
212
872
|
const CONTINUOUS_FORMAT_VERSION = '2';
|
|
213
873
|
|
|
@@ -253,8 +913,8 @@ function enrichWithThreadInformation(
|
|
|
253
913
|
frames: profile.frames,
|
|
254
914
|
stacks: profile.stacks,
|
|
255
915
|
thread_metadata: {
|
|
256
|
-
[
|
|
257
|
-
name:
|
|
916
|
+
[PROFILER_THREAD_ID_STRING]: {
|
|
917
|
+
name: PROFILER_THREAD_NAME,
|
|
258
918
|
},
|
|
259
919
|
},
|
|
260
920
|
} ;
|
|
@@ -272,12 +932,12 @@ function createProfilingEvent(client, profile, event) {
|
|
|
272
932
|
}
|
|
273
933
|
|
|
274
934
|
return createProfilePayload(client, profile, {
|
|
275
|
-
release: _nullishCoalesce(event.release, () => ( '')),
|
|
276
|
-
environment: _nullishCoalesce(event.environment, () => ( '')),
|
|
277
|
-
event_id: _nullishCoalesce(event.event_id, () => ( '')),
|
|
278
|
-
transaction: _nullishCoalesce(event.transaction, () => ( '')),
|
|
935
|
+
release: _nullishCoalesce$1(event.release, () => ( '')),
|
|
936
|
+
environment: _nullishCoalesce$1(event.environment, () => ( '')),
|
|
937
|
+
event_id: _nullishCoalesce$1(event.event_id, () => ( '')),
|
|
938
|
+
transaction: _nullishCoalesce$1(event.transaction, () => ( '')),
|
|
279
939
|
start_timestamp: event.start_timestamp ? event.start_timestamp * 1000 : Date.now(),
|
|
280
|
-
trace_id: _nullishCoalesce(_optionalChain$1([event, 'access', _ => _.contexts, 'optionalAccess', _2 => _2['trace'], 'optionalAccess', _3 => _3['trace_id']]), () => ( '')),
|
|
940
|
+
trace_id: _nullishCoalesce$1(_optionalChain$1([event, 'access', _ => _.contexts, 'optionalAccess', _2 => _2['trace'], 'optionalAccess', _3 => _3['trace_id']]), () => ( '')),
|
|
281
941
|
profile_id: profile.profile_id,
|
|
282
942
|
});
|
|
283
943
|
}
|
|
@@ -344,7 +1004,7 @@ function createProfilePayload(
|
|
|
344
1004
|
name: transaction,
|
|
345
1005
|
id: event_id,
|
|
346
1006
|
trace_id: trace_id || '',
|
|
347
|
-
active_thread_id:
|
|
1007
|
+
active_thread_id: PROFILER_THREAD_ID_STRING,
|
|
348
1008
|
},
|
|
349
1009
|
};
|
|
350
1010
|
|
|
@@ -363,7 +1023,6 @@ function createProfileChunkPayload(
|
|
|
363
1023
|
{
|
|
364
1024
|
release,
|
|
365
1025
|
environment,
|
|
366
|
-
start_timestamp,
|
|
367
1026
|
trace_id,
|
|
368
1027
|
profiler_id,
|
|
369
1028
|
chunk_id,
|
|
@@ -383,7 +1042,6 @@ function createProfileChunkPayload(
|
|
|
383
1042
|
const profile = {
|
|
384
1043
|
chunk_id: chunk_id,
|
|
385
1044
|
profiler_id: profiler_id,
|
|
386
|
-
timestamp: new Date(start_timestamp).toISOString(),
|
|
387
1045
|
platform: 'node',
|
|
388
1046
|
version: CONTINUOUS_FORMAT_VERSION,
|
|
389
1047
|
release: release,
|
|
@@ -402,7 +1060,6 @@ function createProfileChunkPayload(
|
|
|
402
1060
|
* Creates a profiling chunk envelope item, if the profile does not pass validation, returns null.
|
|
403
1061
|
*/
|
|
404
1062
|
function createProfilingChunkEvent(
|
|
405
|
-
start_timestamp,
|
|
406
1063
|
client,
|
|
407
1064
|
options,
|
|
408
1065
|
profile,
|
|
@@ -413,10 +1070,9 @@ function createProfilingChunkEvent(
|
|
|
413
1070
|
}
|
|
414
1071
|
|
|
415
1072
|
return createProfileChunkPayload(client, profile, {
|
|
416
|
-
release: _nullishCoalesce(options.release, () => ( '')),
|
|
417
|
-
environment: _nullishCoalesce(options.environment, () => ( '')),
|
|
418
|
-
|
|
419
|
-
trace_id: _nullishCoalesce(identifiers.trace_id, () => ( '')),
|
|
1073
|
+
release: _nullishCoalesce$1(options.release, () => ( '')),
|
|
1074
|
+
environment: _nullishCoalesce$1(options.environment, () => ( '')),
|
|
1075
|
+
trace_id: _nullishCoalesce$1(identifiers.trace_id, () => ( '')),
|
|
420
1076
|
chunk_id: identifiers.chunk_id,
|
|
421
1077
|
profiler_id: identifiers.profiler_id,
|
|
422
1078
|
});
|
|
@@ -753,7 +1409,6 @@ function stopSpanProfile(span, profile_id) {
|
|
|
753
1409
|
}
|
|
754
1410
|
|
|
755
1411
|
const profile = CpuProfilerBindings.stopProfiling(profile_id, 0);
|
|
756
|
-
|
|
757
1412
|
DEBUG_BUILD && utils.logger.log(`[Profiling] stopped profiling of transaction: ${core.spanToJSON(span).description}`);
|
|
758
1413
|
|
|
759
1414
|
// In case of an overlapping span, stopProfiling may return null and silently ignore the overlapping profile.
|
|
@@ -962,8 +1617,10 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
962
1617
|
utils.logger.log(`[Profiling] Failed to collect profile for: ${_optionalChain([this, 'access', _10 => _10._chunkData, 'optionalAccess', _11 => _11.id])}, the chunk_id is missing.`);
|
|
963
1618
|
return;
|
|
964
1619
|
}
|
|
965
|
-
|
|
966
|
-
|
|
1620
|
+
|
|
1621
|
+
const profile = this._stopChunkProfiling(this._chunkData);
|
|
1622
|
+
|
|
1623
|
+
if (!profile) {
|
|
967
1624
|
DEBUG_BUILD && utils.logger.log(`[Profiling] _chunkiledStartTraceID to collect profile for: ${this._chunkData.id}`);
|
|
968
1625
|
return;
|
|
969
1626
|
}
|
|
@@ -972,17 +1629,11 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
972
1629
|
}
|
|
973
1630
|
|
|
974
1631
|
DEBUG_BUILD && utils.logger.log(`[Profiling] Profile chunk ${this._chunkData.id} sent to Sentry.`);
|
|
975
|
-
const chunk = createProfilingChunkEvent(
|
|
976
|
-
this._chunkData.
|
|
977
|
-
this.
|
|
978
|
-
this.
|
|
979
|
-
|
|
980
|
-
{
|
|
981
|
-
chunk_id: this._chunkData.id,
|
|
982
|
-
trace_id: this._chunkData.startTraceID,
|
|
983
|
-
profiler_id: this._profilerId,
|
|
984
|
-
},
|
|
985
|
-
);
|
|
1632
|
+
const chunk = createProfilingChunkEvent(this._client, this._client.getOptions(), profile, {
|
|
1633
|
+
chunk_id: this._chunkData.id,
|
|
1634
|
+
trace_id: this._chunkData.startTraceID,
|
|
1635
|
+
profiler_id: this._profilerId,
|
|
1636
|
+
});
|
|
986
1637
|
|
|
987
1638
|
if (!chunk) {
|
|
988
1639
|
DEBUG_BUILD && utils.logger.log(`[Profiling] Failed to create profile chunk for: ${this._chunkData.id}`);
|
|
@@ -1025,11 +1676,21 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1025
1676
|
});
|
|
1026
1677
|
}
|
|
1027
1678
|
|
|
1679
|
+
/**
|
|
1680
|
+
* Stops the profile and clears chunk instrumentation from global scope
|
|
1681
|
+
* @returns void
|
|
1682
|
+
*/
|
|
1683
|
+
_stopChunkProfiling(chunk) {
|
|
1684
|
+
this._teardownSpanChunkInstrumentation();
|
|
1685
|
+
return CpuProfilerBindings.stopProfiling(chunk.id, ProfileFormat.CHUNK);
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1028
1688
|
/**
|
|
1029
1689
|
* Starts the profiler and registers the flush timer for a given chunk.
|
|
1030
1690
|
* @param chunk
|
|
1031
1691
|
*/
|
|
1032
1692
|
_startChunkProfiling(chunk) {
|
|
1693
|
+
this._setupSpanChunkInstrumentation();
|
|
1033
1694
|
CpuProfilerBindings.startProfiling(chunk.id);
|
|
1034
1695
|
DEBUG_BUILD && utils.logger.log(`[Profiling] starting profiling chunk: ${chunk.id}`);
|
|
1035
1696
|
|
|
@@ -1044,6 +1705,32 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1044
1705
|
chunk.timer.unref();
|
|
1045
1706
|
}
|
|
1046
1707
|
|
|
1708
|
+
/**
|
|
1709
|
+
* Attaches profiling information to spans that were started
|
|
1710
|
+
* during a profiling session.
|
|
1711
|
+
*/
|
|
1712
|
+
_setupSpanChunkInstrumentation() {
|
|
1713
|
+
if (!this._client) {
|
|
1714
|
+
DEBUG_BUILD &&
|
|
1715
|
+
utils.logger.log('[Profiling] Failed to collect profile, sentry client was never attached to the profiler.');
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
getGlobalScope().setContext('profile', {
|
|
1720
|
+
profiler_id: this._profilerId,
|
|
1721
|
+
});
|
|
1722
|
+
|
|
1723
|
+
this._client.on('beforeSendEvent', e => this._assignThreadIdContext(e));
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
/**
|
|
1727
|
+
* Clear profiling information from global context when a profile is not running.
|
|
1728
|
+
*/
|
|
1729
|
+
_teardownSpanChunkInstrumentation() {
|
|
1730
|
+
const globalScope = getGlobalScope();
|
|
1731
|
+
globalScope.setContext('profile', {});
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1047
1734
|
/**
|
|
1048
1735
|
* Initializes new profile chunk metadata
|
|
1049
1736
|
*/
|
|
@@ -1051,11 +1738,34 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
|
|
|
1051
1738
|
this._chunkData = {
|
|
1052
1739
|
id: utils.uuid4(),
|
|
1053
1740
|
startTraceID: traceId,
|
|
1054
|
-
startTimestampMS: utils.timestampInSeconds(),
|
|
1055
1741
|
timer: undefined,
|
|
1056
1742
|
};
|
|
1057
1743
|
}
|
|
1058
1744
|
|
|
1745
|
+
/**
|
|
1746
|
+
* Assigns thread_id and thread name context to a profiled event.
|
|
1747
|
+
*/
|
|
1748
|
+
_assignThreadIdContext(event) {
|
|
1749
|
+
if (!_optionalChain([event, 'optionalAccess', _13 => _13['contexts'], 'optionalAccess', _14 => _14['profile']])) {
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
if (!event.contexts) {
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// @ts-expect-error the trace fallback value is wrong, though it should never happen
|
|
1758
|
+
// and in case it does, we dont want to override whatever was passed initially.
|
|
1759
|
+
event.contexts['trace'] = {
|
|
1760
|
+
...(_nullishCoalesce(_optionalChain([event, 'access', _15 => _15.contexts, 'optionalAccess', _16 => _16['trace']]), () => ( {}))),
|
|
1761
|
+
data: {
|
|
1762
|
+
...(_nullishCoalesce(_optionalChain([event, 'access', _17 => _17.contexts, 'optionalAccess', _18 => _18['trace'], 'optionalAccess', _19 => _19['data']]), () => ( {}))),
|
|
1763
|
+
['thread.id']: PROFILER_THREAD_ID_STRING,
|
|
1764
|
+
['thread.name']: PROFILER_THREAD_NAME,
|
|
1765
|
+
},
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1059
1769
|
/**
|
|
1060
1770
|
* Resets the current chunk state.
|
|
1061
1771
|
*/
|