@sentry/opentelemetry 10.32.1 → 10.34.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.
@@ -215,6 +215,10 @@ const SENTRY_TRACE_STATE_URL = 'sentry.url';
215
215
  const SENTRY_TRACE_STATE_SAMPLE_RAND = 'sentry.sample_rand';
216
216
  const SENTRY_TRACE_STATE_SAMPLE_RATE = 'sentry.sample_rate';
217
217
 
218
+ // NOTE: `@sentry/nextjs` has a local copy of this context key for Edge bundles:
219
+ // - `packages/nextjs/src/edge/index.ts` (`SENTRY_SCOPES_CONTEXT_KEY`)
220
+ //
221
+ // If you change the key name passed to `createContextKey(...)`, update that file too.
218
222
  const SENTRY_SCOPES_CONTEXT_KEY = api.createContextKey('sentry_scopes');
219
223
 
220
224
  const SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY = api.createContextKey('sentry_fork_isolation_scope');
@@ -230,6 +234,10 @@ const SCOPE_CONTEXT_FIELD = '_scopeContext';
230
234
  * This requires a Context Manager that was wrapped with getWrappedContextManager.
231
235
  */
232
236
  function getScopesFromContext(context) {
237
+ // NOTE: `@sentry/nextjs` has a local copy of this helper for Edge bundles:
238
+ // - `packages/nextjs/src/edge/index.ts` (`getScopesFromContext`)
239
+ //
240
+ // If you change how scopes are stored/read (key or retrieval), update that file too.
233
241
  return context.getValue(SENTRY_SCOPES_CONTEXT_KEY) ;
234
242
  }
235
243
 
@@ -262,6 +270,10 @@ function getContextFromScope(scope) {
262
270
  * @returns boolean
263
271
  */
264
272
  function isSentryRequestSpan(span) {
273
+ // NOTE: `@sentry/nextjs` has a local copy of this helper for Edge bundles:
274
+ // - `packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts` (`isSentryRequestSpan`)
275
+ //
276
+ // If you change supported OTEL attribute keys or request detection logic, update that file too.
265
277
  if (!spanHasAttributes(span)) {
266
278
  return false;
267
279
  }
@@ -1676,7 +1688,7 @@ class SentrySpanExporter {
1676
1688
  ) {
1677
1689
  this._finishedSpanBucketSize = options?.timeout || DEFAULT_TIMEOUT;
1678
1690
  this._finishedSpanBuckets = new Array(this._finishedSpanBucketSize).fill(undefined);
1679
- this._lastCleanupTimestampInS = Math.floor(Date.now() / 1000);
1691
+ this._lastCleanupTimestampInS = Math.floor(core._INTERNAL_safeDateNow() / 1000);
1680
1692
  this._spansToBucketEntry = new WeakMap();
1681
1693
  this._sentSpans = new Map();
1682
1694
  this._debouncedFlush = core.debounce(this.flush.bind(this), 1, { maxWait: 100 });
@@ -1687,7 +1699,7 @@ class SentrySpanExporter {
1687
1699
  * This is called by the span processor whenever a span is ended.
1688
1700
  */
1689
1701
  export(span) {
1690
- const currentTimestampInS = Math.floor(Date.now() / 1000);
1702
+ const currentTimestampInS = Math.floor(core._INTERNAL_safeDateNow() / 1000);
1691
1703
 
1692
1704
  if (this._lastCleanupTimestampInS !== currentTimestampInS) {
1693
1705
  let droppedSpanCount = 0;
@@ -1740,7 +1752,7 @@ class SentrySpanExporter {
1740
1752
  `SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} spans are waiting for their parent spans to finish`,
1741
1753
  );
1742
1754
 
1743
- const expirationDate = Date.now() + DEFAULT_TIMEOUT * 1000;
1755
+ const expirationDate = core._INTERNAL_safeDateNow() + DEFAULT_TIMEOUT * 1000;
1744
1756
 
1745
1757
  for (const span of sentSpans) {
1746
1758
  this._sentSpans.set(span.spanContext().spanId, expirationDate);
@@ -1820,7 +1832,7 @@ class SentrySpanExporter {
1820
1832
 
1821
1833
  /** Remove "expired" span id entries from the _sentSpans cache. */
1822
1834
  _flushSentSpanCache() {
1823
- const currentTimestamp = Date.now();
1835
+ const currentTimestamp = core._INTERNAL_safeDateNow();
1824
1836
  // Note, it is safe to delete items from the map as we go: https://stackoverflow.com/a/35943995/90297
1825
1837
  for (const [spanId, expirationTime] of this._sentSpans.entries()) {
1826
1838
  if (expirationTime <= currentTimestamp) {
@@ -2215,7 +2227,7 @@ class SentrySampler {
2215
2227
  const dscString = parentContext?.traceState ? parentContext.traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
2216
2228
  const dsc = dscString ? core.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
2217
2229
 
2218
- const sampleRand = core.parseSampleRate(dsc?.sample_rand) ?? Math.random();
2230
+ const sampleRand = core.parseSampleRate(dsc?.sample_rand) ?? core._INTERNAL_safeMathRandom();
2219
2231
 
2220
2232
  const [sampled, sampleRate, localSampleRateWasApplied] = core.sampleSpan(
2221
2233
  options,