@sentry/profiling-node 8.10.0 → 8.12.0-beta.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.
Files changed (153) hide show
  1. package/bindings/cpu_profiler.cc +5 -3
  2. package/lib/cjs/index.js +2 -662
  3. package/lib/cjs/index.js.map +1 -1
  4. package/lib/esm/index.js +2 -662
  5. package/lib/esm/index.js.map +1 -1
  6. package/lib/sentry_cpu_profiler-darwin-arm64-108.node +0 -0
  7. package/lib/sentry_cpu_profiler-darwin-arm64-115.node +0 -0
  8. package/lib/sentry_cpu_profiler-darwin-arm64-127.node +0 -0
  9. package/lib/sentry_cpu_profiler-darwin-arm64-93.node +0 -0
  10. package/lib/sentry_cpu_profiler-darwin-x64-108.node +0 -0
  11. package/lib/sentry_cpu_profiler-darwin-x64-115.node +0 -0
  12. package/lib/sentry_cpu_profiler-darwin-x64-127.node +0 -0
  13. package/lib/sentry_cpu_profiler-darwin-x64-93.node +0 -0
  14. package/lib/sentry_cpu_profiler-linux-arm64-glibc-108.node +0 -0
  15. package/lib/sentry_cpu_profiler-linux-arm64-glibc-115.node +0 -0
  16. package/lib/sentry_cpu_profiler-linux-arm64-glibc-127.node +0 -0
  17. package/lib/sentry_cpu_profiler-linux-arm64-glibc-93.node +0 -0
  18. package/lib/sentry_cpu_profiler-linux-arm64-musl-108.node +0 -0
  19. package/lib/sentry_cpu_profiler-linux-arm64-musl-115.node +0 -0
  20. package/lib/sentry_cpu_profiler-linux-arm64-musl-127.node +0 -0
  21. package/lib/sentry_cpu_profiler-linux-arm64-musl-93.node +0 -0
  22. package/lib/sentry_cpu_profiler-linux-x64-glibc-108.node +0 -0
  23. package/lib/sentry_cpu_profiler-linux-x64-glibc-115.node +0 -0
  24. package/lib/sentry_cpu_profiler-linux-x64-glibc-127.node +0 -0
  25. package/lib/sentry_cpu_profiler-linux-x64-glibc-93.node +0 -0
  26. package/lib/sentry_cpu_profiler-linux-x64-musl-108.node +0 -0
  27. package/lib/sentry_cpu_profiler-linux-x64-musl-115.node +0 -0
  28. package/lib/sentry_cpu_profiler-linux-x64-musl-127.node +0 -0
  29. package/lib/sentry_cpu_profiler-linux-x64-musl-93.node +0 -0
  30. package/lib/sentry_cpu_profiler-win32-x64-108.node +0 -0
  31. package/lib/sentry_cpu_profiler-win32-x64-115.node +0 -0
  32. package/lib/sentry_cpu_profiler-win32-x64-127.node +0 -0
  33. package/lib/sentry_cpu_profiler-win32-x64-93.node +0 -0
  34. package/lib/types/cpu_profiler.d.ts.map +1 -0
  35. package/lib/types/debug-build.d.ts.map +1 -0
  36. package/lib/types/index.d.ts.map +1 -0
  37. package/lib/types/integration.d.ts.map +1 -0
  38. package/lib/types/nodeVersion.d.ts.map +1 -0
  39. package/lib/types/spanProfileUtils.d.ts.map +1 -0
  40. package/lib/types/types.d.ts.map +1 -0
  41. package/lib/types/utils.d.ts.map +1 -0
  42. package/package.json +5 -5
  43. package/lib/types/core/src/asyncContext/index.d.ts +0 -14
  44. package/lib/types/core/src/asyncContext/index.d.ts.map +0 -1
  45. package/lib/types/core/src/asyncContext/stackStrategy.d.ts +0 -52
  46. package/lib/types/core/src/asyncContext/stackStrategy.d.ts.map +0 -1
  47. package/lib/types/core/src/asyncContext/types.d.ts +0 -47
  48. package/lib/types/core/src/asyncContext/types.d.ts.map +0 -1
  49. package/lib/types/core/src/carrier.d.ts +0 -37
  50. package/lib/types/core/src/carrier.d.ts.map +0 -1
  51. package/lib/types/core/src/constants.d.ts +0 -2
  52. package/lib/types/core/src/constants.d.ts.map +0 -1
  53. package/lib/types/core/src/currentScopes.d.ts +0 -55
  54. package/lib/types/core/src/currentScopes.d.ts.map +0 -1
  55. package/lib/types/core/src/debug-build.d.ts.map +0 -1
  56. package/lib/types/core/src/defaultScopes.d.ts +0 -6
  57. package/lib/types/core/src/defaultScopes.d.ts.map +0 -1
  58. package/lib/types/core/src/envelope.d.ts +0 -15
  59. package/lib/types/core/src/envelope.d.ts.map +0 -1
  60. package/lib/types/core/src/metrics/constants.d.ts +0 -19
  61. package/lib/types/core/src/metrics/constants.d.ts.map +0 -1
  62. package/lib/types/core/src/metrics/metric-summary.d.ts +0 -13
  63. package/lib/types/core/src/metrics/metric-summary.d.ts.map +0 -1
  64. package/lib/types/core/src/metrics/types.d.ts +0 -5
  65. package/lib/types/core/src/metrics/types.d.ts.map +0 -1
  66. package/lib/types/core/src/scope.d.ts +0 -211
  67. package/lib/types/core/src/scope.d.ts.map +0 -1
  68. package/lib/types/core/src/semanticAttributes.d.ts +0 -33
  69. package/lib/types/core/src/semanticAttributes.d.ts.map +0 -1
  70. package/lib/types/core/src/session.d.ts +0 -35
  71. package/lib/types/core/src/session.d.ts.map +0 -1
  72. package/lib/types/core/src/tracing/dynamicSamplingContext.d.ts +0 -24
  73. package/lib/types/core/src/tracing/dynamicSamplingContext.d.ts.map +0 -1
  74. package/lib/types/core/src/tracing/logSpans.d.ts +0 -10
  75. package/lib/types/core/src/tracing/logSpans.d.ts.map +0 -1
  76. package/lib/types/core/src/tracing/measurement.d.ts +0 -10
  77. package/lib/types/core/src/tracing/measurement.d.ts.map +0 -1
  78. package/lib/types/core/src/tracing/sampling.d.ts +0 -9
  79. package/lib/types/core/src/tracing/sampling.d.ts.map +0 -1
  80. package/lib/types/core/src/tracing/sentryNonRecordingSpan.d.ts +0 -26
  81. package/lib/types/core/src/tracing/sentryNonRecordingSpan.d.ts.map +0 -1
  82. package/lib/types/core/src/tracing/sentrySpan.d.ts +0 -86
  83. package/lib/types/core/src/tracing/sentrySpan.d.ts.map +0 -1
  84. package/lib/types/core/src/tracing/spanstatus.d.ts +0 -17
  85. package/lib/types/core/src/tracing/spanstatus.d.ts.map +0 -1
  86. package/lib/types/core/src/tracing/trace.d.ts +0 -76
  87. package/lib/types/core/src/tracing/trace.d.ts.map +0 -1
  88. package/lib/types/core/src/tracing/utils.d.ts +0 -13
  89. package/lib/types/core/src/tracing/utils.d.ts.map +0 -1
  90. package/lib/types/core/src/utils/handleCallbackErrors.d.ts +0 -13
  91. package/lib/types/core/src/utils/handleCallbackErrors.d.ts.map +0 -1
  92. package/lib/types/core/src/utils/hasTracingEnabled.d.ts +0 -8
  93. package/lib/types/core/src/utils/hasTracingEnabled.d.ts.map +0 -1
  94. package/lib/types/core/src/utils/parseSampleRate.d.ts +0 -9
  95. package/lib/types/core/src/utils/parseSampleRate.d.ts.map +0 -1
  96. package/lib/types/core/src/utils/spanOnScope.d.ts +0 -17
  97. package/lib/types/core/src/utils/spanOnScope.d.ts.map +0 -1
  98. package/lib/types/core/src/utils/spanUtils.d.ts +0 -74
  99. package/lib/types/core/src/utils/spanUtils.d.ts.map +0 -1
  100. package/lib/types/profiling-node/src/cpu_profiler.d.ts.map +0 -1
  101. package/lib/types/profiling-node/src/debug-build.d.ts +0 -7
  102. package/lib/types/profiling-node/src/debug-build.d.ts.map +0 -1
  103. package/lib/types/profiling-node/src/index.d.ts.map +0 -1
  104. package/lib/types/profiling-node/src/integration.d.ts.map +0 -1
  105. package/lib/types/profiling-node/src/nodeVersion.d.ts.map +0 -1
  106. package/lib/types/profiling-node/src/spanProfileUtils.d.ts.map +0 -1
  107. package/lib/types/profiling-node/src/types.d.ts.map +0 -1
  108. package/lib/types/profiling-node/src/utils.d.ts.map +0 -1
  109. package/lib/types-ts3.8/core/src/asyncContext/index.d.ts +0 -14
  110. package/lib/types-ts3.8/core/src/asyncContext/stackStrategy.d.ts +0 -52
  111. package/lib/types-ts3.8/core/src/asyncContext/types.d.ts +0 -47
  112. package/lib/types-ts3.8/core/src/carrier.d.ts +0 -37
  113. package/lib/types-ts3.8/core/src/constants.d.ts +0 -2
  114. package/lib/types-ts3.8/core/src/currentScopes.d.ts +0 -55
  115. package/lib/types-ts3.8/core/src/defaultScopes.d.ts +0 -6
  116. package/lib/types-ts3.8/core/src/envelope.d.ts +0 -18
  117. package/lib/types-ts3.8/core/src/metrics/constants.d.ts +0 -19
  118. package/lib/types-ts3.8/core/src/metrics/metric-summary.d.ts +0 -13
  119. package/lib/types-ts3.8/core/src/metrics/types.d.ts +0 -5
  120. package/lib/types-ts3.8/core/src/scope.d.ts +0 -211
  121. package/lib/types-ts3.8/core/src/semanticAttributes.d.ts +0 -33
  122. package/lib/types-ts3.8/core/src/session.d.ts +0 -35
  123. package/lib/types-ts3.8/core/src/tracing/dynamicSamplingContext.d.ts +0 -24
  124. package/lib/types-ts3.8/core/src/tracing/logSpans.d.ts +0 -10
  125. package/lib/types-ts3.8/core/src/tracing/measurement.d.ts +0 -10
  126. package/lib/types-ts3.8/core/src/tracing/sampling.d.ts +0 -12
  127. package/lib/types-ts3.8/core/src/tracing/sentryNonRecordingSpan.d.ts +0 -26
  128. package/lib/types-ts3.8/core/src/tracing/sentrySpan.d.ts +0 -86
  129. package/lib/types-ts3.8/core/src/tracing/spanstatus.d.ts +0 -17
  130. package/lib/types-ts3.8/core/src/tracing/trace.d.ts +0 -76
  131. package/lib/types-ts3.8/core/src/tracing/utils.d.ts +0 -13
  132. package/lib/types-ts3.8/core/src/utils/handleCallbackErrors.d.ts +0 -13
  133. package/lib/types-ts3.8/core/src/utils/hasTracingEnabled.d.ts +0 -8
  134. package/lib/types-ts3.8/core/src/utils/parseSampleRate.d.ts +0 -9
  135. package/lib/types-ts3.8/core/src/utils/spanOnScope.d.ts +0 -17
  136. package/lib/types-ts3.8/core/src/utils/spanUtils.d.ts +0 -74
  137. package/lib/types-ts3.8/profiling-node/src/debug-build.d.ts +0 -7
  138. /package/lib/types/{profiling-node/src/cpu_profiler.d.ts → cpu_profiler.d.ts} +0 -0
  139. /package/lib/types/{core/src/debug-build.d.ts → debug-build.d.ts} +0 -0
  140. /package/lib/types/{profiling-node/src/index.d.ts → index.d.ts} +0 -0
  141. /package/lib/types/{profiling-node/src/integration.d.ts → integration.d.ts} +0 -0
  142. /package/lib/types/{profiling-node/src/nodeVersion.d.ts → nodeVersion.d.ts} +0 -0
  143. /package/lib/types/{profiling-node/src/spanProfileUtils.d.ts → spanProfileUtils.d.ts} +0 -0
  144. /package/lib/types/{profiling-node/src/types.d.ts → types.d.ts} +0 -0
  145. /package/lib/types/{profiling-node/src/utils.d.ts → utils.d.ts} +0 -0
  146. /package/lib/types-ts3.8/{profiling-node/src/cpu_profiler.d.ts → cpu_profiler.d.ts} +0 -0
  147. /package/lib/types-ts3.8/{core/src/debug-build.d.ts → debug-build.d.ts} +0 -0
  148. /package/lib/types-ts3.8/{profiling-node/src/index.d.ts → index.d.ts} +0 -0
  149. /package/lib/types-ts3.8/{profiling-node/src/integration.d.ts → integration.d.ts} +0 -0
  150. /package/lib/types-ts3.8/{profiling-node/src/nodeVersion.d.ts → nodeVersion.d.ts} +0 -0
  151. /package/lib/types-ts3.8/{profiling-node/src/spanProfileUtils.d.ts → spanProfileUtils.d.ts} +0 -0
  152. /package/lib/types-ts3.8/{profiling-node/src/types.d.ts → types.d.ts} +0 -0
  153. /package/lib/types-ts3.8/{profiling-node/src/utils.d.ts → utils.d.ts} +0 -0
@@ -546,7 +546,8 @@ CreateFrameNode(const napi_env &env, const v8::CpuProfileNode &node,
546
546
  };
547
547
 
548
548
  napi_value CreateSample(const napi_env &env, const enum ProfileFormat format,
549
- const uint32_t stack_id, const int64_t sample_timestamp,
549
+ const uint32_t stack_id,
550
+ const int64_t sample_timestamp_ns,
550
551
  const double chunk_timestamp,
551
552
  const uint32_t thread_id) {
552
553
  napi_value js_node;
@@ -564,7 +565,7 @@ napi_value CreateSample(const napi_env &env, const enum ProfileFormat format,
564
565
  switch (format) {
565
566
  case ProfileFormat::kFormatThread: {
566
567
  napi_value timestamp;
567
- napi_create_int64(env, sample_timestamp, &timestamp);
568
+ napi_create_int64(env, sample_timestamp_ns, &timestamp);
568
569
  napi_set_named_property(env, js_node, "elapsed_since_start_ns", timestamp);
569
570
  } break;
570
571
  case ProfileFormat::kFormatChunk: {
@@ -643,7 +644,8 @@ static void GetSamples(const napi_env &env, const v8::CpuProfile *profile,
643
644
  uint64_t sample_offset_from_profile_start_ms =
644
645
  (sample_timestamp_us - profile_start_time_us) * 1e-3;
645
646
  double seconds_since_start =
646
- profile_start_timestamp_ms + sample_offset_from_profile_start_ms;
647
+ (profile_start_timestamp_ms + sample_offset_from_profile_start_ms) *
648
+ 1e-3;
647
649
 
648
650
  napi_value sample = nullptr;
649
651
  sample = CreateSample(env, format, stack_index, sample_timestamp_ns,
package/lib/cjs/index.js CHANGED
@@ -18,666 +18,6 @@ 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
-
681
21
  /**
682
22
  * 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.
683
23
  *
@@ -1716,7 +1056,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1716
1056
  return;
1717
1057
  }
1718
1058
 
1719
- getGlobalScope().setContext('profile', {
1059
+ core.getGlobalScope().setContext('profile', {
1720
1060
  profiler_id: this._profilerId,
1721
1061
  });
1722
1062
 
@@ -1727,7 +1067,7 @@ class ContinuousProfiler {constructor() { ContinuousProfiler.prototype.__init.ca
1727
1067
  * Clear profiling information from global context when a profile is not running.
1728
1068
  */
1729
1069
  _teardownSpanChunkInstrumentation() {
1730
- const globalScope = getGlobalScope();
1070
+ const globalScope = core.getGlobalScope();
1731
1071
  globalScope.setContext('profile', {});
1732
1072
  }
1733
1073