@sentry/browser 10.26.0 → 10.28.0-alpha.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/build/npm/cjs/dev/client.js +0 -1
- package/build/npm/cjs/dev/client.js.map +1 -1
- package/build/npm/cjs/dev/index.js +5 -0
- package/build/npm/cjs/dev/index.js.map +1 -1
- package/build/npm/cjs/dev/integrations/httpcontext.js +2 -0
- package/build/npm/cjs/dev/integrations/httpcontext.js.map +1 -1
- package/build/npm/cjs/dev/integrations/spanstreaming.js +217 -0
- package/build/npm/cjs/dev/integrations/spanstreaming.js.map +1 -0
- package/build/npm/cjs/dev/profiling/UIProfiler.js +98 -41
- package/build/npm/cjs/dev/profiling/UIProfiler.js.map +1 -1
- package/build/npm/cjs/dev/profiling/index.js +59 -0
- package/build/npm/cjs/dev/profiling/index.js.map +1 -0
- package/build/npm/cjs/dev/profiling/integration.js +12 -10
- package/build/npm/cjs/dev/profiling/integration.js.map +1 -1
- package/build/npm/cjs/dev/profiling/utils.js +11 -5
- package/build/npm/cjs/dev/profiling/utils.js.map +1 -1
- package/build/npm/cjs/dev/tracing/request.js +1 -0
- package/build/npm/cjs/dev/tracing/request.js.map +1 -1
- package/build/npm/cjs/prod/client.js +0 -1
- package/build/npm/cjs/prod/client.js.map +1 -1
- package/build/npm/cjs/prod/index.js +5 -0
- package/build/npm/cjs/prod/index.js.map +1 -1
- package/build/npm/cjs/prod/integrations/httpcontext.js +2 -0
- package/build/npm/cjs/prod/integrations/httpcontext.js.map +1 -1
- package/build/npm/cjs/prod/integrations/spanstreaming.js +217 -0
- package/build/npm/cjs/prod/integrations/spanstreaming.js.map +1 -0
- package/build/npm/cjs/prod/profiling/UIProfiler.js +98 -41
- package/build/npm/cjs/prod/profiling/UIProfiler.js.map +1 -1
- package/build/npm/cjs/prod/profiling/index.js +59 -0
- package/build/npm/cjs/prod/profiling/index.js.map +1 -0
- package/build/npm/cjs/prod/profiling/integration.js +12 -10
- package/build/npm/cjs/prod/profiling/integration.js.map +1 -1
- package/build/npm/cjs/prod/profiling/utils.js +11 -5
- package/build/npm/cjs/prod/profiling/utils.js.map +1 -1
- package/build/npm/cjs/prod/tracing/request.js +1 -0
- package/build/npm/cjs/prod/tracing/request.js.map +1 -1
- package/build/npm/esm/dev/client.js +0 -1
- package/build/npm/esm/dev/client.js.map +1 -1
- package/build/npm/esm/dev/index.js +3 -1
- package/build/npm/esm/dev/index.js.map +1 -1
- package/build/npm/esm/dev/integrations/httpcontext.js +2 -0
- package/build/npm/esm/dev/integrations/httpcontext.js.map +1 -1
- package/build/npm/esm/dev/integrations/spanstreaming.js +215 -0
- package/build/npm/esm/dev/integrations/spanstreaming.js.map +1 -0
- package/build/npm/esm/dev/package.json +1 -1
- package/build/npm/esm/dev/profiling/UIProfiler.js +100 -43
- package/build/npm/esm/dev/profiling/UIProfiler.js.map +1 -1
- package/build/npm/esm/dev/profiling/index.js +57 -0
- package/build/npm/esm/dev/profiling/index.js.map +1 -0
- package/build/npm/esm/dev/profiling/integration.js +13 -11
- package/build/npm/esm/dev/profiling/integration.js.map +1 -1
- package/build/npm/esm/dev/profiling/utils.js +12 -6
- package/build/npm/esm/dev/profiling/utils.js.map +1 -1
- package/build/npm/esm/dev/tracing/request.js +1 -0
- package/build/npm/esm/dev/tracing/request.js.map +1 -1
- package/build/npm/esm/prod/client.js +0 -1
- package/build/npm/esm/prod/client.js.map +1 -1
- package/build/npm/esm/prod/index.js +3 -1
- package/build/npm/esm/prod/index.js.map +1 -1
- package/build/npm/esm/prod/integrations/httpcontext.js +2 -0
- package/build/npm/esm/prod/integrations/httpcontext.js.map +1 -1
- package/build/npm/esm/prod/integrations/spanstreaming.js +215 -0
- package/build/npm/esm/prod/integrations/spanstreaming.js.map +1 -0
- package/build/npm/esm/prod/package.json +1 -1
- package/build/npm/esm/prod/profiling/UIProfiler.js +100 -43
- package/build/npm/esm/prod/profiling/UIProfiler.js.map +1 -1
- package/build/npm/esm/prod/profiling/index.js +57 -0
- package/build/npm/esm/prod/profiling/index.js.map +1 -0
- package/build/npm/esm/prod/profiling/integration.js +13 -11
- package/build/npm/esm/prod/profiling/integration.js.map +1 -1
- package/build/npm/esm/prod/profiling/utils.js +12 -6
- package/build/npm/esm/prod/profiling/utils.js.map +1 -1
- package/build/npm/esm/prod/tracing/request.js +1 -0
- package/build/npm/esm/prod/tracing/request.js.map +1 -1
- package/build/npm/types/client.d.ts.map +1 -1
- package/build/npm/types/exports.d.ts +1 -0
- package/build/npm/types/exports.d.ts.map +1 -1
- package/build/npm/types/index.d.ts +2 -1
- package/build/npm/types/index.d.ts.map +1 -1
- package/build/npm/types/integrations/httpcontext.d.ts.map +1 -1
- package/build/npm/types/integrations/spanstreaming.d.ts +5 -0
- package/build/npm/types/integrations/spanstreaming.d.ts.map +1 -0
- package/build/npm/types/profiling/UIProfiler.d.ts +23 -22
- package/build/npm/types/profiling/UIProfiler.d.ts.map +1 -1
- package/build/npm/types/profiling/index.d.ts +8 -0
- package/build/npm/types/profiling/index.d.ts.map +1 -0
- package/build/npm/types/profiling/integration.d.ts.map +1 -1
- package/build/npm/types/profiling/utils.d.ts +1 -1
- package/build/npm/types/profiling/utils.d.ts.map +1 -1
- package/build/npm/types/tracing/request.d.ts.map +1 -1
- package/build/npm/types-ts3.8/exports.d.ts +1 -0
- package/build/npm/types-ts3.8/index.d.ts +2 -1
- package/build/npm/types-ts3.8/integrations/spanstreaming.d.ts +5 -0
- package/build/npm/types-ts3.8/profiling/UIProfiler.d.ts +23 -22
- package/build/npm/types-ts3.8/profiling/index.d.ts +8 -0
- package/build/npm/types-ts3.8/profiling/utils.d.ts +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../../src/client.ts"],"sourcesContent":["import type {\n BrowserClientProfilingOptions,\n BrowserClientReplayOptions,\n ClientOptions,\n Event,\n EventHint,\n Options as CoreOptions,\n ParameterizedString,\n Scope,\n SeverityLevel,\n} from '@sentry/core';\nimport {\n _INTERNAL_flushLogsBuffer,\n _INTERNAL_flushMetricsBuffer,\n addAutoIpAddressToSession,\n applySdkMetadata,\n Client,\n getSDKSource,\n} from '@sentry/core';\nimport { eventFromException, eventFromMessage } from './eventbuilder';\nimport { WINDOW } from './helpers';\nimport type { BrowserTransportOptions } from './transports/types';\n\n/**\n * A magic string that build tooling can leverage in order to inject a release value into the SDK.\n */\ndeclare const __SENTRY_RELEASE__: string | undefined;\n\ntype BrowserSpecificOptions = BrowserClientReplayOptions &\n BrowserClientProfilingOptions & {\n /** If configured, this URL will be used as base URL for lazy loading integration. */\n cdnBaseUrl?: string;\n\n /**\n * Important: Only set this option if you know what you are doing!\n *\n * By default, the SDK will check if `Sentry.init` is called in a browser extension.\n * In case it is, it will stop initialization and log a warning\n * because browser extensions require a different Sentry initialization process:\n * https://docs.sentry.io/platforms/javascript/best-practices/shared-environments/\n *\n * Setting up the SDK in a browser extension with global error monitoring is not recommended\n * and will likely flood you with errors from other web sites or extensions. This can heavily\n * impact your quota and cause interference with your and other Sentry SDKs in shared environments.\n *\n * If this check wrongfully flags your setup as a browser extension, you can set this\n * option to `true` to skip the check.\n *\n * @default false\n */\n skipBrowserExtensionCheck?: boolean;\n\n /**\n * If set to `true`, the SDK propagates the W3C `traceparent` header to any outgoing requests,\n * in addition to the `sentry-trace` and `baggage` headers. Use the {@link CoreOptions.tracePropagationTargets}\n * option to control to which outgoing requests the header will be attached.\n *\n * **Important:** If you set this option to `true`, make sure that you configured your servers'\n * CORS settings to allow the `traceparent` header. Otherwise, requests might get blocked.\n *\n * @see https://www.w3.org/TR/trace-context/\n *\n * @default false\n */\n propagateTraceparent?: boolean;\n\n /**\n * If you use Spotlight by Sentry during development, use\n * this option to forward captured Sentry events to Spotlight.\n *\n * Either set it to true, or provide a specific Spotlight Sidecar URL.\n *\n * More details: https://spotlightjs.com/\n *\n * IMPORTANT: Only set this option to `true` while developing, not in production!\n */\n spotlight?: boolean | string;\n };\n/**\n * Configuration options for the Sentry Browser SDK.\n * @see @sentry/core Options for more information.\n */\nexport type BrowserOptions = CoreOptions<BrowserTransportOptions> & BrowserSpecificOptions;\n\n/**\n * Configuration options for the Sentry Browser SDK Client class\n * @see BrowserClient for more information.\n */\nexport type BrowserClientOptions = ClientOptions<BrowserTransportOptions> & BrowserSpecificOptions;\n\n/**\n * The Sentry Browser SDK Client.\n *\n * @see BrowserOptions for documentation on configuration options.\n * @see SentryClient for usage documentation.\n */\nexport class BrowserClient extends Client<BrowserClientOptions> {\n /**\n * Creates a new Browser SDK instance.\n *\n * @param options Configuration options for this SDK.\n */\n public constructor(options: BrowserClientOptions) {\n const opts = applyDefaultOptions(options);\n const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource();\n applySdkMetadata(opts, 'browser', ['browser'], sdkSource);\n\n // Only allow IP inferral by Relay if sendDefaultPii is true\n if (opts._metadata?.sdk) {\n opts._metadata.sdk.settings = {\n infer_ip: opts.sendDefaultPii ? 'auto' : 'never',\n // purposefully allowing already passed settings to override the default\n ...opts._metadata.sdk.settings,\n };\n }\n\n super(opts);\n\n const {\n sendDefaultPii,\n sendClientReports,\n enableLogs,\n _experiments,\n enableMetrics: enableMetricsOption,\n } = this._options;\n\n // todo(v11): Remove the experimental flag\n // eslint-disable-next-line deprecation/deprecation\n const enableMetrics = enableMetricsOption ?? _experiments?.enableMetrics ?? true;\n\n // Flush logs and metrics when page becomes hidden (e.g., tab switch, navigation)\n // todo(v11): Remove the experimental flag\n
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../../../src/client.ts"],"sourcesContent":["import type {\n BrowserClientProfilingOptions,\n BrowserClientReplayOptions,\n ClientOptions,\n Event,\n EventHint,\n Options as CoreOptions,\n ParameterizedString,\n Scope,\n SeverityLevel,\n} from '@sentry/core';\nimport {\n _INTERNAL_flushLogsBuffer,\n _INTERNAL_flushMetricsBuffer,\n addAutoIpAddressToSession,\n applySdkMetadata,\n Client,\n getSDKSource,\n} from '@sentry/core';\nimport { eventFromException, eventFromMessage } from './eventbuilder';\nimport { WINDOW } from './helpers';\nimport type { BrowserTransportOptions } from './transports/types';\n\n/**\n * A magic string that build tooling can leverage in order to inject a release value into the SDK.\n */\ndeclare const __SENTRY_RELEASE__: string | undefined;\n\ntype BrowserSpecificOptions = BrowserClientReplayOptions &\n BrowserClientProfilingOptions & {\n /** If configured, this URL will be used as base URL for lazy loading integration. */\n cdnBaseUrl?: string;\n\n /**\n * Important: Only set this option if you know what you are doing!\n *\n * By default, the SDK will check if `Sentry.init` is called in a browser extension.\n * In case it is, it will stop initialization and log a warning\n * because browser extensions require a different Sentry initialization process:\n * https://docs.sentry.io/platforms/javascript/best-practices/shared-environments/\n *\n * Setting up the SDK in a browser extension with global error monitoring is not recommended\n * and will likely flood you with errors from other web sites or extensions. This can heavily\n * impact your quota and cause interference with your and other Sentry SDKs in shared environments.\n *\n * If this check wrongfully flags your setup as a browser extension, you can set this\n * option to `true` to skip the check.\n *\n * @default false\n */\n skipBrowserExtensionCheck?: boolean;\n\n /**\n * If set to `true`, the SDK propagates the W3C `traceparent` header to any outgoing requests,\n * in addition to the `sentry-trace` and `baggage` headers. Use the {@link CoreOptions.tracePropagationTargets}\n * option to control to which outgoing requests the header will be attached.\n *\n * **Important:** If you set this option to `true`, make sure that you configured your servers'\n * CORS settings to allow the `traceparent` header. Otherwise, requests might get blocked.\n *\n * @see https://www.w3.org/TR/trace-context/\n *\n * @default false\n */\n propagateTraceparent?: boolean;\n\n /**\n * If you use Spotlight by Sentry during development, use\n * this option to forward captured Sentry events to Spotlight.\n *\n * Either set it to true, or provide a specific Spotlight Sidecar URL.\n *\n * More details: https://spotlightjs.com/\n *\n * IMPORTANT: Only set this option to `true` while developing, not in production!\n */\n spotlight?: boolean | string;\n };\n/**\n * Configuration options for the Sentry Browser SDK.\n * @see @sentry/core Options for more information.\n */\nexport type BrowserOptions = CoreOptions<BrowserTransportOptions> & BrowserSpecificOptions;\n\n/**\n * Configuration options for the Sentry Browser SDK Client class\n * @see BrowserClient for more information.\n */\nexport type BrowserClientOptions = ClientOptions<BrowserTransportOptions> & BrowserSpecificOptions;\n\n/**\n * The Sentry Browser SDK Client.\n *\n * @see BrowserOptions for documentation on configuration options.\n * @see SentryClient for usage documentation.\n */\nexport class BrowserClient extends Client<BrowserClientOptions> {\n /**\n * Creates a new Browser SDK instance.\n *\n * @param options Configuration options for this SDK.\n */\n public constructor(options: BrowserClientOptions) {\n const opts = applyDefaultOptions(options);\n const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource();\n applySdkMetadata(opts, 'browser', ['browser'], sdkSource);\n\n // Only allow IP inferral by Relay if sendDefaultPii is true\n if (opts._metadata?.sdk) {\n opts._metadata.sdk.settings = {\n infer_ip: opts.sendDefaultPii ? 'auto' : 'never',\n // purposefully allowing already passed settings to override the default\n ...opts._metadata.sdk.settings,\n };\n }\n\n super(opts);\n\n const {\n sendDefaultPii,\n sendClientReports,\n enableLogs,\n _experiments,\n enableMetrics: enableMetricsOption,\n } = this._options;\n\n // todo(v11): Remove the experimental flag\n // eslint-disable-next-line deprecation/deprecation\n const enableMetrics = enableMetricsOption ?? _experiments?.enableMetrics ?? true;\n\n // Flush logs and metrics when page becomes hidden (e.g., tab switch, navigation)\n // todo(v11): Remove the experimental flag\n if (WINDOW.document && (sendClientReports || enableLogs || enableMetrics)) {\n WINDOW.document.addEventListener('visibilitychange', () => {\n if (WINDOW.document.visibilityState === 'hidden') {\n if (sendClientReports) {\n this._flushOutcomes();\n }\n if (enableLogs) {\n _INTERNAL_flushLogsBuffer(this);\n }\n\n if (enableMetrics) {\n _INTERNAL_flushMetricsBuffer(this);\n }\n }\n });\n }\n\n if (sendDefaultPii) {\n this.on('beforeSendSession', addAutoIpAddressToSession);\n }\n }\n\n /**\n * @inheritDoc\n */\n public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {\n return eventFromException(this._options.stackParser, exception, hint, this._options.attachStacktrace);\n }\n\n /**\n * @inheritDoc\n */\n public eventFromMessage(\n message: ParameterizedString,\n level: SeverityLevel = 'info',\n hint?: EventHint,\n ): PromiseLike<Event> {\n return eventFromMessage(this._options.stackParser, message, level, hint, this._options.attachStacktrace);\n }\n\n /**\n * @inheritDoc\n */\n protected _prepareEvent(\n event: Event,\n hint: EventHint,\n currentScope: Scope,\n isolationScope: Scope,\n ): PromiseLike<Event | null> {\n event.platform = event.platform || 'javascript';\n\n return super._prepareEvent(event, hint, currentScope, isolationScope);\n }\n}\n\n/** Exported only for tests. */\nexport function applyDefaultOptions<T extends Partial<BrowserClientOptions>>(optionsArg: T): T {\n return {\n release:\n typeof __SENTRY_RELEASE__ === 'string' // This allows build tooling to find-and-replace __SENTRY_RELEASE__ to inject a release value\n ? __SENTRY_RELEASE__\n : WINDOW.SENTRY_RELEASE?.id, // This supports the variable that sentry-webpack-plugin injects\n sendClientReports: true,\n // We default this to true, as it is the safer scenario\n parentSpanIsAlwaysRootSpan: true,\n ...optionsArg,\n };\n}\n"],"names":[],"mappings":";;;;AAuBA;AACA;AACA;;AAiEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,aAAA,SAAsB,MAAM,CAAuB;AAChE;AACA;AACA;AACA;AACA;AACA,GAAS,WAAW,CAAC,OAAO,EAAwB;AACpD,IAAI,MAAM,IAAA,GAAO,mBAAmB,CAAC,OAAO,CAAC;AAC7C,IAAI,MAAM,YAAY,MAAM,CAAC,iBAAA,IAAqB,YAAY,EAAE;AAChE,IAAI,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;;AAE7D;AACA,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;AAC7B,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW;AACpC,QAAQ,QAAQ,EAAE,IAAI,CAAC,iBAAiB,MAAA,GAAS,OAAO;AACxD;AACA,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ;AACtC,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IAAI,KAAK,GAAkB,MAAM;AACjC,IAAI,IAAI;AACR,IAAwB;AACxB,IAAI,OAAO,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC;AAC5G,EAAE;;AAEF;AACA;AACA;AACA,GAAY,aAAa;AACzB,IAAI,KAAK;AACT,IAAI,IAAI;AACR,IAAI,YAAY;AAChB,IAAI,cAAc;AAClB,IAA+B;AAC/B,IAAI,KAAK,CAAC,QAAA,GAAW,KAAK,CAAC,QAAA,IAAY,YAAY;;AAEnD,IAAI,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,cAAc,CAAC;AACzE,EAAE;AACF;;AAEA;AACO,SAAS,mBAAmB,CAA0C,UAAU,EAAQ;AAC/F,EAAE,OAAO;AACT,IAAI,OAAO;AACX,MAAM,OAAO,uBAAuB,QAAA;AACpC,UAAU;AACV,UAAU,MAAM,CAAC,cAAc,EAAE,EAAE;AACnC,IAAI,iBAAiB,EAAE,IAAI;AAC3B;AACA,IAAI,0BAA0B,EAAE,IAAI;AACpC,IAAI,GAAG,UAAU;AACjB,GAAG;AACH;;;;"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { feedbackAsyncIntegration } from './feedbackAsync.js';
|
|
2
2
|
export { feedbackSyncIntegration as feedbackIntegration, feedbackSyncIntegration } from './feedbackSync.js';
|
|
3
|
-
export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, captureSession, close, consoleLoggingIntegration, continueTrace, createConsolaReporter, createTransport, dedupeIntegration, endSession, eventFiltersIntegration, extraErrorDataIntegration, featureFlagsIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, inboundFiltersIntegration, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, instrumentOpenAiClient, instrumentSupabaseClient, isEnabled, isInitialized, lastEventId, logger, makeMultiplexedTransport, metrics, moduleMetadataIntegration, parameterize, registerSpanErrorInstrumentation, rewriteFramesIntegration, setContext, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSession, startSpan, startSpanManual, supabaseIntegration, suppressTracing, thirdPartyErrorFilterIntegration, updateSpanName, withActiveSpan, withIsolationScope, withScope, zodErrorsIntegration } from '@sentry/core';
|
|
3
|
+
export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, captureSession, close, consoleLoggingIntegration, continueTrace, createConsolaReporter, createTransport, dedupeIntegration, endSession, eventFiltersIntegration, extraErrorDataIntegration, featureFlagsIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, inboundFiltersIntegration, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, instrumentOpenAiClient, instrumentSupabaseClient, isEnabled, isInitialized, lastEventId, logger, makeMultiplexedTransport, metrics, moduleMetadataIntegration, parameterize, registerSpanErrorInstrumentation, rewriteFramesIntegration, setContext, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSession, startSpan, startSpanManual, supabaseIntegration, suppressTracing, thirdPartyErrorFilterIntegration, updateSpanName, withActiveSpan, withIsolationScope, withScope, withStreamSpan, zodErrorsIntegration } from '@sentry/core';
|
|
4
4
|
export { WINDOW } from './helpers.js';
|
|
5
5
|
export { BrowserClient } from './client.js';
|
|
6
6
|
export { makeFetchTransport } from './transports/fetch.js';
|
|
7
|
+
export { uiProfiler } from './profiling/index.js';
|
|
7
8
|
export { chromeStackLineParser, defaultStackLineParsers, defaultStackParser, geckoStackLineParser, opera10StackLineParser, opera11StackLineParser, winjsStackLineParser } from './stack-parsers.js';
|
|
8
9
|
export { eventFromException, eventFromMessage, exceptionFromError } from './eventbuilder.js';
|
|
9
10
|
export { createUserFeedbackEnvelope } from './userfeedback.js';
|
|
@@ -37,4 +38,5 @@ export { growthbookIntegration } from './integrations/featureFlags/growthbook/in
|
|
|
37
38
|
export { statsigIntegration } from './integrations/featureFlags/statsig/integration.js';
|
|
38
39
|
export { diagnoseSdkConnectivity } from './diagnose-sdk.js';
|
|
39
40
|
export { registerWebWorker, webWorkerIntegration } from './integrations/webWorker.js';
|
|
41
|
+
export { spanStreamingIntegration } from './integrations/spanstreaming.js';
|
|
40
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -8,6 +8,8 @@ import { WINDOW, getHttpRequestData } from '../helpers.js';
|
|
|
8
8
|
const httpContextIntegration = defineIntegration(() => {
|
|
9
9
|
return {
|
|
10
10
|
name: 'HttpContext',
|
|
11
|
+
// TODO (span-streaming): probably fine to omit this in favour of us globally
|
|
12
|
+
// already adding request context data but should double-check this
|
|
11
13
|
preprocessEvent(event) {
|
|
12
14
|
// if none of the information we want exists, don't bother
|
|
13
15
|
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpcontext.js","sources":["../../../../../src/integrations/httpcontext.ts"],"sourcesContent":["import { defineIntegration } from '@sentry/core';\nimport { getHttpRequestData, WINDOW } from '../helpers';\n\n/**\n * Collects information about HTTP request headers and\n * attaches them to the event.\n */\nexport const httpContextIntegration = defineIntegration(() => {\n return {\n name: 'HttpContext',\n preprocessEvent(event) {\n // if none of the information we want exists, don't bother\n if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {\n return;\n }\n\n const reqData = getHttpRequestData();\n const headers = {\n ...reqData.headers,\n ...event.request?.headers,\n };\n\n event.request = {\n ...reqData,\n ...event.request,\n headers,\n };\n },\n };\n});\n"],"names":[],"mappings":";;;AAGA;AACA;AACA;AACA;MACa,sBAAA,GAAyB,iBAAiB,CAAC,MAAM;AAC9D,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,aAAa;AACvB,IAAI,eAAe,CAAC,KAAK,EAAE;AAC3B;AACA,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE;AACrE,QAAQ;AACR,MAAM;;AAEN,MAAM,MAAM,OAAA,GAAU,kBAAkB,EAAE;AAC1C,MAAM,MAAM,UAAU;AACtB,QAAQ,GAAG,OAAO,CAAC,OAAO;AAC1B,QAAQ,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO;AACjC,OAAO;;AAEP,MAAM,KAAK,CAAC,OAAA,GAAU;AACtB,QAAQ,GAAG,OAAO;AAClB,QAAQ,GAAG,KAAK,CAAC,OAAO;AACxB,QAAQ,OAAO;AACf,OAAO;AACP,IAAI,CAAC;AACL,GAAG;AACH,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"httpcontext.js","sources":["../../../../../src/integrations/httpcontext.ts"],"sourcesContent":["import { defineIntegration } from '@sentry/core';\nimport { getHttpRequestData, WINDOW } from '../helpers';\n\n/**\n * Collects information about HTTP request headers and\n * attaches them to the event.\n */\nexport const httpContextIntegration = defineIntegration(() => {\n return {\n name: 'HttpContext',\n // TODO (span-streaming): probably fine to omit this in favour of us globally\n // already adding request context data but should double-check this\n preprocessEvent(event) {\n // if none of the information we want exists, don't bother\n if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {\n return;\n }\n\n const reqData = getHttpRequestData();\n const headers = {\n ...reqData.headers,\n ...event.request?.headers,\n };\n\n event.request = {\n ...reqData,\n ...event.request,\n headers,\n };\n },\n };\n});\n"],"names":[],"mappings":";;;AAGA;AACA;AACA;AACA;MACa,sBAAA,GAAyB,iBAAiB,CAAC,MAAM;AAC9D,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,aAAa;AACvB;AACA;AACA,IAAI,eAAe,CAAC,KAAK,EAAE;AAC3B;AACA,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE;AACrE,QAAQ;AACR,MAAM;;AAEN,MAAM,MAAM,OAAA,GAAU,kBAAkB,EAAE;AAC1C,MAAM,MAAM,UAAU;AACtB,QAAQ,GAAG,OAAO,CAAC,OAAO;AAC1B,QAAQ,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO;AACjC,OAAO;;AAEP,MAAM,KAAK,CAAC,OAAA,GAAU;AACtB,QAAQ,GAAG,OAAO;AAClB,QAAQ,GAAG,KAAK,CAAC,OAAO;AACxB,QAAQ,OAAO;AACf,OAAO;AACP,IAAI,CAAC;AACL,GAAG;AACH,CAAC;;;;"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { defineIntegration, debug, isV2BeforeSendSpanCallback, INTERNAL_getSegmentSpan, spanToV2JSON, shouldIgnoreSpan, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, reparentChildSpans, getDynamicSamplingContextFromSpan, createSpanV2Envelope, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_USER_USERNAME, SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS, SEMANTIC_ATTRIBUTE_USER_EMAIL, SEMANTIC_ATTRIBUTE_USER_ID, SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME, SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID, SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME, showSpanDropWarning, getGlobalScope, mergeScopeData, SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT, SEMANTIC_ATTRIBUTE_SENTRY_RELEASE } from '@sentry/core';
|
|
2
|
+
import { DEBUG_BUILD } from '../debug-build.js';
|
|
3
|
+
|
|
4
|
+
const spanStreamingIntegration = defineIntegration(((userOptions) => {
|
|
5
|
+
const validatedUserProvidedBatchLimit =
|
|
6
|
+
userOptions?.batchLimit && userOptions.batchLimit <= 1000 && userOptions.batchLimit >= 1
|
|
7
|
+
? userOptions.batchLimit
|
|
8
|
+
: undefined;
|
|
9
|
+
|
|
10
|
+
if (DEBUG_BUILD && userOptions?.batchLimit && !validatedUserProvidedBatchLimit) {
|
|
11
|
+
debug.warn('SpanStreaming batchLimit must be between 1 and 1000, defaulting to 1000');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const options = {
|
|
15
|
+
...userOptions,
|
|
16
|
+
batchLimit:
|
|
17
|
+
userOptions?.batchLimit && userOptions.batchLimit <= 1000 && userOptions.batchLimit >= 1
|
|
18
|
+
? userOptions.batchLimit
|
|
19
|
+
: 1000,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// key: traceId-segmentSpanId
|
|
23
|
+
const spanTreeMap = new Map();
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
name: 'SpanStreaming',
|
|
27
|
+
setup(client) {
|
|
28
|
+
const clientOptions = client.getOptions();
|
|
29
|
+
const beforeSendSpan = clientOptions.beforeSendSpan;
|
|
30
|
+
|
|
31
|
+
const initialMessage = 'spanStreamingIntegration requires';
|
|
32
|
+
const fallbackMsg = 'Falling back to static trace lifecycle.';
|
|
33
|
+
|
|
34
|
+
if (clientOptions.traceLifecycle !== 'stream') {
|
|
35
|
+
DEBUG_BUILD && debug.warn(`${initialMessage} \`traceLifecycle\` to be set to "stream"! ${fallbackMsg}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (beforeSendSpan && !isV2BeforeSendSpanCallback(beforeSendSpan)) {
|
|
40
|
+
client.getOptions().traceLifecycle = 'static';
|
|
41
|
+
debug.warn(`${initialMessage} a beforeSendSpan callback using \`withStreamSpan\`! ${fallbackMsg}`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
client.on('spanEnd', span => {
|
|
46
|
+
const spanTreeMapKey = getSpanTreeMapKey(span);
|
|
47
|
+
const spanBuffer = spanTreeMap.get(spanTreeMapKey);
|
|
48
|
+
if (spanBuffer) {
|
|
49
|
+
spanBuffer.add(span);
|
|
50
|
+
} else {
|
|
51
|
+
spanTreeMap.set(spanTreeMapKey, new Set([span]));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// For now, we send all spans on local segment (root) span end.
|
|
56
|
+
// TODO: This will change once we have more concrete ideas about a universal SDK data buffer.
|
|
57
|
+
client.on('segmentSpanEnd', segmentSpan => {
|
|
58
|
+
processAndSendSpans(segmentSpan, {
|
|
59
|
+
spanTreeMap: spanTreeMap,
|
|
60
|
+
client,
|
|
61
|
+
batchLimit: options.batchLimit,
|
|
62
|
+
beforeSendSpan,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}) );
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Just the traceid alone isn't enough because there can be multiple span trees with the same traceid.
|
|
71
|
+
*/
|
|
72
|
+
function getSpanTreeMapKey(span) {
|
|
73
|
+
return `${span.spanContext().traceId}-${INTERNAL_getSegmentSpan(span).spanContext().spanId}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function processAndSendSpans(
|
|
77
|
+
segmentSpan,
|
|
78
|
+
{ client, spanTreeMap, batchLimit, beforeSendSpan },
|
|
79
|
+
) {
|
|
80
|
+
const traceId = segmentSpan.spanContext().traceId;
|
|
81
|
+
const spanTreeMapKey = getSpanTreeMapKey(segmentSpan);
|
|
82
|
+
const spansOfTrace = spanTreeMap.get(spanTreeMapKey);
|
|
83
|
+
|
|
84
|
+
if (!spansOfTrace?.size) {
|
|
85
|
+
spanTreeMap.delete(spanTreeMapKey);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const segmentSpanJson = spanToV2JSON(segmentSpan);
|
|
90
|
+
|
|
91
|
+
for (const span of spansOfTrace) {
|
|
92
|
+
applyCommonSpanAttributes(span, segmentSpanJson, client);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { ignoreSpans } = client.getOptions();
|
|
96
|
+
|
|
97
|
+
// 1. Check if the entire span tree is ignored by ignoreSpans
|
|
98
|
+
if (ignoreSpans?.length && shouldIgnoreSpan(segmentSpanJson, ignoreSpans)) {
|
|
99
|
+
client.recordDroppedEvent('before_send', 'span', spansOfTrace.size);
|
|
100
|
+
spanTreeMap.delete(spanTreeMapKey);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const serializedSpans = Array.from(spansOfTrace ?? []).map(s => {
|
|
105
|
+
const serialized = spanToV2JSON(s);
|
|
106
|
+
// remove internal span attributes we don't need to send.
|
|
107
|
+
delete serialized.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
|
|
108
|
+
return serialized;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const processedSpans = [];
|
|
112
|
+
let ignoredSpanCount = 0;
|
|
113
|
+
|
|
114
|
+
for (const span of serializedSpans) {
|
|
115
|
+
// 2. Check if child spans should be ignored
|
|
116
|
+
const isChildSpan = span.span_id !== segmentSpan.spanContext().spanId;
|
|
117
|
+
if (ignoreSpans?.length && isChildSpan && shouldIgnoreSpan(span, ignoreSpans)) {
|
|
118
|
+
reparentChildSpans(serializedSpans, span);
|
|
119
|
+
ignoredSpanCount++;
|
|
120
|
+
// drop this span by not adding it to the processedSpans array
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 3. Apply beforeSendSpan callback
|
|
125
|
+
// TODO: validate beforeSendSpan result/pass in a copy and merge afterwards
|
|
126
|
+
const processedSpan = beforeSendSpan ? applyBeforeSendSpanCallback(span, beforeSendSpan) : span;
|
|
127
|
+
processedSpans.push(processedSpan);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (ignoredSpanCount) {
|
|
131
|
+
client.recordDroppedEvent('before_send', 'span', ignoredSpanCount);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const batches = [];
|
|
135
|
+
for (let i = 0; i < processedSpans.length; i += batchLimit) {
|
|
136
|
+
batches.push(processedSpans.slice(i, i + batchLimit));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
DEBUG_BUILD && debug.log(`Sending trace ${traceId} in ${batches.length} batch${batches.length === 1 ? '' : 'es'}`);
|
|
140
|
+
|
|
141
|
+
const dsc = getDynamicSamplingContextFromSpan(segmentSpan);
|
|
142
|
+
|
|
143
|
+
for (const batch of batches) {
|
|
144
|
+
const envelope = createSpanV2Envelope(batch, dsc, client);
|
|
145
|
+
// no need to handle client reports for network errors,
|
|
146
|
+
// buffer overflows or rate limiting here. All of this is handled
|
|
147
|
+
// by client and transport.
|
|
148
|
+
client.sendEnvelope(envelope).then(null, reason => {
|
|
149
|
+
DEBUG_BUILD && debug.error('Error while sending span stream envelope:', reason);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
spanTreeMap.delete(spanTreeMapKey);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function applyCommonSpanAttributes(span, serializedSegmentSpan, client) {
|
|
157
|
+
const sdk = client.getSdkMetadata();
|
|
158
|
+
const { release, environment, sendDefaultPii } = client.getOptions();
|
|
159
|
+
|
|
160
|
+
const { isolationScope: spanIsolationScope, scope: spanScope } = getCapturedScopesOnSpan(span);
|
|
161
|
+
|
|
162
|
+
const originalAttributeKeys = Object.keys(spanToV2JSON(span).attributes ?? {});
|
|
163
|
+
|
|
164
|
+
const finalScopeData = getFinalScopeData(spanIsolationScope, spanScope);
|
|
165
|
+
|
|
166
|
+
// avoid overwriting any previously set attributes (from users or potentially our SDK instrumentation)
|
|
167
|
+
setAttributesIfNotPresent(span, originalAttributeKeys, {
|
|
168
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,
|
|
169
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment,
|
|
170
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: serializedSegmentSpan.name,
|
|
171
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: serializedSegmentSpan.span_id,
|
|
172
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: sdk?.sdk?.name,
|
|
173
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: sdk?.sdk?.version,
|
|
174
|
+
...(sendDefaultPii
|
|
175
|
+
? {
|
|
176
|
+
[SEMANTIC_ATTRIBUTE_USER_ID]: finalScopeData.user?.id,
|
|
177
|
+
[SEMANTIC_ATTRIBUTE_USER_EMAIL]: finalScopeData.user?.email,
|
|
178
|
+
[SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: finalScopeData.user?.ip_address ?? undefined,
|
|
179
|
+
[SEMANTIC_ATTRIBUTE_USER_USERNAME]: finalScopeData.user?.username,
|
|
180
|
+
}
|
|
181
|
+
: {}),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function applyBeforeSendSpanCallback(span, beforeSendSpan) {
|
|
186
|
+
const modifedSpan = beforeSendSpan(span);
|
|
187
|
+
if (!modifedSpan) {
|
|
188
|
+
showSpanDropWarning();
|
|
189
|
+
return span;
|
|
190
|
+
}
|
|
191
|
+
return modifedSpan;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function setAttributesIfNotPresent(span, originalAttributeKeys, newAttributes) {
|
|
195
|
+
Object.keys(newAttributes).forEach(key => {
|
|
196
|
+
if (!originalAttributeKeys.includes(key)) {
|
|
197
|
+
span.setAttribute(key, newAttributes[key]);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// TODO: Extract this to a helper in core. It's used in multiple places.
|
|
203
|
+
function getFinalScopeData(isolationScope, scope) {
|
|
204
|
+
const finalScopeData = getGlobalScope().getScopeData();
|
|
205
|
+
if (isolationScope) {
|
|
206
|
+
mergeScopeData(finalScopeData, isolationScope.getScopeData());
|
|
207
|
+
}
|
|
208
|
+
if (scope) {
|
|
209
|
+
mergeScopeData(finalScopeData, scope.getScopeData());
|
|
210
|
+
}
|
|
211
|
+
return finalScopeData;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export { spanStreamingIntegration };
|
|
215
|
+
//# sourceMappingURL=spanstreaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spanstreaming.js","sources":["../../../../../src/integrations/spanstreaming.ts"],"sourcesContent":["import type { Client, IntegrationFn, Scope, ScopeData, Span, SpanAttributes, SpanV2JSON } from '@sentry/core';\nimport {\n createSpanV2Envelope,\n debug,\n defineIntegration,\n getCapturedScopesOnSpan,\n getDynamicSamplingContextFromSpan,\n getGlobalScope,\n INTERNAL_getSegmentSpan,\n isV2BeforeSendSpanCallback,\n mergeScopeData,\n reparentChildSpans,\n SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT,\n SEMANTIC_ATTRIBUTE_SENTRY_RELEASE,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID,\n SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME,\n SEMANTIC_ATTRIBUTE_USER_EMAIL,\n SEMANTIC_ATTRIBUTE_USER_ID,\n SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,\n SEMANTIC_ATTRIBUTE_USER_USERNAME,\n shouldIgnoreSpan,\n showSpanDropWarning,\n spanToV2JSON,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\nexport interface SpanStreamingOptions {\n batchLimit: number;\n}\n\nexport const spanStreamingIntegration = defineIntegration(((userOptions?: Partial<SpanStreamingOptions>) => {\n const validatedUserProvidedBatchLimit =\n userOptions?.batchLimit && userOptions.batchLimit <= 1000 && userOptions.batchLimit >= 1\n ? userOptions.batchLimit\n : undefined;\n\n if (DEBUG_BUILD && userOptions?.batchLimit && !validatedUserProvidedBatchLimit) {\n debug.warn('SpanStreaming batchLimit must be between 1 and 1000, defaulting to 1000');\n }\n\n const options: SpanStreamingOptions = {\n ...userOptions,\n batchLimit:\n userOptions?.batchLimit && userOptions.batchLimit <= 1000 && userOptions.batchLimit >= 1\n ? userOptions.batchLimit\n : 1000,\n };\n\n // key: traceId-segmentSpanId\n const spanTreeMap = new Map<string, Set<Span>>();\n\n return {\n name: 'SpanStreaming',\n setup(client) {\n const clientOptions = client.getOptions();\n const beforeSendSpan = clientOptions.beforeSendSpan;\n\n const initialMessage = 'spanStreamingIntegration requires';\n const fallbackMsg = 'Falling back to static trace lifecycle.';\n\n if (clientOptions.traceLifecycle !== 'stream') {\n DEBUG_BUILD && debug.warn(`${initialMessage} \\`traceLifecycle\\` to be set to \"stream\"! ${fallbackMsg}`);\n return;\n }\n\n if (beforeSendSpan && !isV2BeforeSendSpanCallback(beforeSendSpan)) {\n client.getOptions().traceLifecycle = 'static';\n debug.warn(`${initialMessage} a beforeSendSpan callback using \\`withStreamSpan\\`! ${fallbackMsg}`);\n return;\n }\n\n client.on('spanEnd', span => {\n const spanTreeMapKey = getSpanTreeMapKey(span);\n const spanBuffer = spanTreeMap.get(spanTreeMapKey);\n if (spanBuffer) {\n spanBuffer.add(span);\n } else {\n spanTreeMap.set(spanTreeMapKey, new Set([span]));\n }\n });\n\n // For now, we send all spans on local segment (root) span end.\n // TODO: This will change once we have more concrete ideas about a universal SDK data buffer.\n client.on('segmentSpanEnd', segmentSpan => {\n processAndSendSpans(segmentSpan, {\n spanTreeMap: spanTreeMap,\n client,\n batchLimit: options.batchLimit,\n beforeSendSpan,\n });\n });\n },\n };\n}) satisfies IntegrationFn);\n\ninterface SpanProcessingOptions {\n client: Client;\n spanTreeMap: Map<string, Set<Span>>;\n batchLimit: number;\n beforeSendSpan: ((span: SpanV2JSON) => SpanV2JSON) | undefined;\n}\n\n/**\n * Just the traceid alone isn't enough because there can be multiple span trees with the same traceid.\n */\nfunction getSpanTreeMapKey(span: Span): string {\n return `${span.spanContext().traceId}-${INTERNAL_getSegmentSpan(span).spanContext().spanId}`;\n}\n\nfunction processAndSendSpans(\n segmentSpan: Span,\n { client, spanTreeMap, batchLimit, beforeSendSpan }: SpanProcessingOptions,\n): void {\n const traceId = segmentSpan.spanContext().traceId;\n const spanTreeMapKey = getSpanTreeMapKey(segmentSpan);\n const spansOfTrace = spanTreeMap.get(spanTreeMapKey);\n\n if (!spansOfTrace?.size) {\n spanTreeMap.delete(spanTreeMapKey);\n return;\n }\n\n const segmentSpanJson = spanToV2JSON(segmentSpan);\n\n for (const span of spansOfTrace) {\n applyCommonSpanAttributes(span, segmentSpanJson, client);\n }\n\n const { ignoreSpans } = client.getOptions();\n\n // 1. Check if the entire span tree is ignored by ignoreSpans\n if (ignoreSpans?.length && shouldIgnoreSpan(segmentSpanJson, ignoreSpans)) {\n client.recordDroppedEvent('before_send', 'span', spansOfTrace.size);\n spanTreeMap.delete(spanTreeMapKey);\n return;\n }\n\n const serializedSpans = Array.from(spansOfTrace ?? []).map(s => {\n const serialized = spanToV2JSON(s);\n // remove internal span attributes we don't need to send.\n delete serialized.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];\n return serialized;\n });\n\n const processedSpans = [];\n let ignoredSpanCount = 0;\n\n for (const span of serializedSpans) {\n // 2. Check if child spans should be ignored\n const isChildSpan = span.span_id !== segmentSpan.spanContext().spanId;\n if (ignoreSpans?.length && isChildSpan && shouldIgnoreSpan(span, ignoreSpans)) {\n reparentChildSpans(serializedSpans, span);\n ignoredSpanCount++;\n // drop this span by not adding it to the processedSpans array\n continue;\n }\n\n // 3. Apply beforeSendSpan callback\n // TODO: validate beforeSendSpan result/pass in a copy and merge afterwards\n const processedSpan = beforeSendSpan ? applyBeforeSendSpanCallback(span, beforeSendSpan) : span;\n processedSpans.push(processedSpan);\n }\n\n if (ignoredSpanCount) {\n client.recordDroppedEvent('before_send', 'span', ignoredSpanCount);\n }\n\n const batches: SpanV2JSON[][] = [];\n for (let i = 0; i < processedSpans.length; i += batchLimit) {\n batches.push(processedSpans.slice(i, i + batchLimit));\n }\n\n DEBUG_BUILD && debug.log(`Sending trace ${traceId} in ${batches.length} batch${batches.length === 1 ? '' : 'es'}`);\n\n const dsc = getDynamicSamplingContextFromSpan(segmentSpan);\n\n for (const batch of batches) {\n const envelope = createSpanV2Envelope(batch, dsc, client);\n // no need to handle client reports for network errors,\n // buffer overflows or rate limiting here. All of this is handled\n // by client and transport.\n client.sendEnvelope(envelope).then(null, reason => {\n DEBUG_BUILD && debug.error('Error while sending span stream envelope:', reason);\n });\n }\n\n spanTreeMap.delete(spanTreeMapKey);\n}\n\nfunction applyCommonSpanAttributes(span: Span, serializedSegmentSpan: SpanV2JSON, client: Client): void {\n const sdk = client.getSdkMetadata();\n const { release, environment, sendDefaultPii } = client.getOptions();\n\n const { isolationScope: spanIsolationScope, scope: spanScope } = getCapturedScopesOnSpan(span);\n\n const originalAttributeKeys = Object.keys(spanToV2JSON(span).attributes ?? {});\n\n const finalScopeData = getFinalScopeData(spanIsolationScope, spanScope);\n\n // avoid overwriting any previously set attributes (from users or potentially our SDK instrumentation)\n setAttributesIfNotPresent(span, originalAttributeKeys, {\n [SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,\n [SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: serializedSegmentSpan.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: serializedSegmentSpan.span_id,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: sdk?.sdk?.name,\n [SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: sdk?.sdk?.version,\n ...(sendDefaultPii\n ? {\n [SEMANTIC_ATTRIBUTE_USER_ID]: finalScopeData.user?.id,\n [SEMANTIC_ATTRIBUTE_USER_EMAIL]: finalScopeData.user?.email,\n [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: finalScopeData.user?.ip_address ?? undefined,\n [SEMANTIC_ATTRIBUTE_USER_USERNAME]: finalScopeData.user?.username,\n }\n : {}),\n });\n}\n\nfunction applyBeforeSendSpanCallback(span: SpanV2JSON, beforeSendSpan: (span: SpanV2JSON) => SpanV2JSON): SpanV2JSON {\n const modifedSpan = beforeSendSpan(span);\n if (!modifedSpan) {\n showSpanDropWarning();\n return span;\n }\n return modifedSpan;\n}\n\nfunction setAttributesIfNotPresent(span: Span, originalAttributeKeys: string[], newAttributes: SpanAttributes): void {\n Object.keys(newAttributes).forEach(key => {\n if (!originalAttributeKeys.includes(key)) {\n span.setAttribute(key, newAttributes[key]);\n }\n });\n}\n\n// TODO: Extract this to a helper in core. It's used in multiple places.\nfunction getFinalScopeData(isolationScope: Scope | undefined, scope: Scope | undefined): ScopeData {\n const finalScopeData = getGlobalScope().getScopeData();\n if (isolationScope) {\n mergeScopeData(finalScopeData, isolationScope.getScopeData());\n }\n if (scope) {\n mergeScopeData(finalScopeData, scope.getScopeData());\n }\n return finalScopeData;\n}\n"],"names":[],"mappings":";;;AAiCO,MAAM,2BAA2B,iBAAiB,EAAE,CAAC,WAAW,KAAqC;AAC5G,EAAE,MAAM,+BAAA;AACR,IAAI,WAAW,EAAE,UAAA,IAAc,WAAW,CAAC,UAAA,IAAc,IAAA,IAAQ,WAAW,CAAC,cAAc;AAC3F,QAAQ,WAAW,CAAC;AACpB,QAAQ,SAAS;;AAEjB,EAAE,IAAI,WAAA,IAAe,WAAW,EAAE,UAAA,IAAc,CAAC,+BAA+B,EAAE;AAClF,IAAI,KAAK,CAAC,IAAI,CAAC,yEAAyE,CAAC;AACzF,EAAE;;AAEF,EAAE,MAAM,OAAO,GAAyB;AACxC,IAAI,GAAG,WAAW;AAClB,IAAI,UAAU;AACd,MAAM,WAAW,EAAE,UAAA,IAAc,WAAW,CAAC,UAAA,IAAc,IAAA,IAAQ,WAAW,CAAC,cAAc;AAC7F,UAAU,WAAW,CAAC;AACtB,UAAU,IAAI;AACd,GAAG;;AAEH;AACA,EAAE,MAAM,WAAA,GAAc,IAAI,GAAG,EAAqB;;AAElD,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,eAAe;AACzB,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,MAAM,aAAA,GAAgB,MAAM,CAAC,UAAU,EAAE;AAC/C,MAAM,MAAM,cAAA,GAAiB,aAAa,CAAC,cAAc;;AAEzD,MAAM,MAAM,cAAA,GAAiB,mCAAmC;AAChE,MAAM,MAAM,WAAA,GAAc,yCAAyC;;AAEnE,MAAM,IAAI,aAAa,CAAC,cAAA,KAAmB,QAAQ,EAAE;AACrD,QAAQ,eAAe,KAAK,CAAC,IAAI,CAAC,CAAC,EA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
|
@@ -1,58 +1,112 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { debug, uuid4, getGlobalScope, getRootSpan, getSdkMetadataForEnvelopeHeader, createEnvelope, dsnToString } from '@sentry/core';
|
|
2
2
|
import { DEBUG_BUILD } from '../debug-build.js';
|
|
3
|
-
import { startJSSelfProfile, createProfileChunkPayload, validateProfileChunk } from './utils.js';
|
|
3
|
+
import { shouldProfileSession, startJSSelfProfile, createProfileChunkPayload, validateProfileChunk } from './utils.js';
|
|
4
4
|
|
|
5
5
|
const CHUNK_INTERVAL_MS = 60000; // 1 minute
|
|
6
6
|
// Maximum length for trace lifecycle profiling per root span (e.g. if spanEnd never fires)
|
|
7
|
-
const MAX_ROOT_SPAN_PROFILE_MS = 300000; // 5 minutes
|
|
7
|
+
const MAX_ROOT_SPAN_PROFILE_MS = 300000; // 5 minutes max per root span in trace mode
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* UIProfiler (Profiling V2):
|
|
11
|
+
* Supports two lifecycle modes:
|
|
12
|
+
* - 'manual': controlled explicitly via start()/stop()
|
|
13
|
+
* - 'trace': automatically runs while there are active sampled root spans
|
|
14
14
|
*
|
|
15
15
|
* Profiles are emitted as standalone `profile_chunk` envelopes either when:
|
|
16
16
|
* - there are no more sampled root spans, or
|
|
17
17
|
* - the 60s chunk timer elapses while profiling is running.
|
|
18
18
|
*/
|
|
19
|
-
class UIProfiler
|
|
19
|
+
class UIProfiler {
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// Manual + Trace
|
|
22
|
+
// one per Profiler session
|
|
23
|
+
// current profiler instance active flag
|
|
24
|
+
// sampling decision for entire session
|
|
22
25
|
|
|
23
|
-
//
|
|
26
|
+
// Trace-only
|
|
24
27
|
|
|
25
28
|
constructor() {
|
|
26
29
|
this._client = undefined;
|
|
27
30
|
this._profiler = undefined;
|
|
28
31
|
this._chunkTimer = undefined;
|
|
29
|
-
|
|
30
|
-
this._rootSpanTimeouts = new Map();
|
|
32
|
+
|
|
31
33
|
this._profilerId = undefined;
|
|
32
34
|
this._isRunning = false;
|
|
33
35
|
this._sessionSampled = false;
|
|
36
|
+
this._lifecycleMode = undefined;
|
|
37
|
+
|
|
38
|
+
this._activeRootSpanIds = new Set();
|
|
39
|
+
this._rootSpanTimeouts = new Map();
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
37
|
-
* Initialize the profiler with client
|
|
43
|
+
* Initialize the profiler with client, session sampling and lifecycle mode.
|
|
38
44
|
*/
|
|
39
|
-
initialize(client
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
initialize(client) {
|
|
46
|
+
const lifecycleMode = (client.getOptions() ).profileLifecycle;
|
|
47
|
+
const sessionSampled = shouldProfileSession(client.getOptions());
|
|
48
|
+
|
|
49
|
+
DEBUG_BUILD && debug.log(`[Profiling] Initializing profiler (lifecycle='${lifecycleMode}').`);
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
if (!sessionSampled) {
|
|
52
|
+
DEBUG_BUILD && debug.log('[Profiling] Session not sampled. Skipping lifecycle profiler initialization.');
|
|
53
|
+
}
|
|
44
54
|
|
|
55
|
+
// One Profiler ID per profiling session (user session)
|
|
56
|
+
this._profilerId = uuid4();
|
|
45
57
|
this._client = client;
|
|
46
58
|
this._sessionSampled = sessionSampled;
|
|
59
|
+
this._lifecycleMode = lifecycleMode;
|
|
47
60
|
|
|
48
|
-
|
|
61
|
+
if (lifecycleMode === 'trace') {
|
|
62
|
+
this._setupTraceLifecycleListeners(client);
|
|
63
|
+
}
|
|
49
64
|
}
|
|
50
65
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
/** Starts UI profiling (only effective in 'manual' mode and when sampled). */
|
|
67
|
+
start() {
|
|
68
|
+
if (this._lifecycleMode === 'trace') {
|
|
69
|
+
DEBUG_BUILD &&
|
|
70
|
+
debug.warn(
|
|
71
|
+
'[Profiling] `profileLifecycle` is set to "trace". Calls to `uiProfiler.start()` are ignored in trace mode.',
|
|
72
|
+
);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (this._isRunning) {
|
|
77
|
+
DEBUG_BUILD && debug.warn('[Profiling] Profile session is already running, `uiProfiler.start()` is a no-op.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
55
81
|
if (!this._sessionSampled) {
|
|
82
|
+
DEBUG_BUILD && debug.warn('[Profiling] Session is not sampled, `uiProfiler.start()` is a no-op.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this._beginProfiling();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Stops UI profiling (only effective in 'manual' mode). */
|
|
90
|
+
stop() {
|
|
91
|
+
if (this._lifecycleMode === 'trace') {
|
|
92
|
+
DEBUG_BUILD &&
|
|
93
|
+
debug.warn(
|
|
94
|
+
'[Profiling] `profileLifecycle` is set to "trace". Calls to `uiProfiler.stop()` are ignored in trace mode.',
|
|
95
|
+
);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!this._isRunning) {
|
|
100
|
+
DEBUG_BUILD && debug.warn('[Profiling] Profiler is not running, `uiProfiler.stop()` is a no-op.');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this._endProfiling();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Handle an already-active root span at integration setup time (used only in trace mode). */
|
|
108
|
+
notifyRootSpanActive(rootSpan) {
|
|
109
|
+
if (this._lifecycleMode !== 'trace' || !this._sessionSampled) {
|
|
56
110
|
return;
|
|
57
111
|
}
|
|
58
112
|
|
|
@@ -61,7 +115,7 @@ class UIProfiler {
|
|
|
61
115
|
return;
|
|
62
116
|
}
|
|
63
117
|
|
|
64
|
-
this.
|
|
118
|
+
this._registerTraceRootSpan(spanId);
|
|
65
119
|
|
|
66
120
|
const rootSpanCount = this._activeRootSpanIds.size;
|
|
67
121
|
|
|
@@ -69,20 +123,20 @@ class UIProfiler {
|
|
|
69
123
|
DEBUG_BUILD &&
|
|
70
124
|
debug.log('[Profiling] Detected already active root span during setup. Active root spans now:', rootSpanCount);
|
|
71
125
|
|
|
72
|
-
this.
|
|
126
|
+
this._beginProfiling();
|
|
73
127
|
}
|
|
74
128
|
}
|
|
75
129
|
|
|
76
130
|
/**
|
|
77
|
-
*
|
|
131
|
+
* Begin profiling if not already running.
|
|
78
132
|
*/
|
|
79
|
-
|
|
133
|
+
_beginProfiling() {
|
|
80
134
|
if (this._isRunning) {
|
|
81
135
|
return;
|
|
82
136
|
}
|
|
83
137
|
this._isRunning = true;
|
|
84
138
|
|
|
85
|
-
DEBUG_BUILD && debug.log('[Profiling] Started profiling with
|
|
139
|
+
DEBUG_BUILD && debug.log('[Profiling] Started profiling with profiler ID:', this._profilerId);
|
|
86
140
|
|
|
87
141
|
// Expose profiler_id to match root spans with profiles
|
|
88
142
|
getGlobalScope().setContext('profile', { profiler_id: this._profilerId });
|
|
@@ -90,7 +144,7 @@ class UIProfiler {
|
|
|
90
144
|
this._startProfilerInstance();
|
|
91
145
|
|
|
92
146
|
if (!this._profiler) {
|
|
93
|
-
DEBUG_BUILD && debug.log('[Profiling]
|
|
147
|
+
DEBUG_BUILD && debug.log('[Profiling] Failed to start JS Profiler; stopping.');
|
|
94
148
|
this._resetProfilerInfo();
|
|
95
149
|
return;
|
|
96
150
|
}
|
|
@@ -98,15 +152,13 @@ class UIProfiler {
|
|
|
98
152
|
this._startPeriodicChunking();
|
|
99
153
|
}
|
|
100
154
|
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
stop() {
|
|
155
|
+
/** End profiling session; final chunk will be collected and sent. */
|
|
156
|
+
_endProfiling() {
|
|
105
157
|
if (!this._isRunning) {
|
|
106
158
|
return;
|
|
107
159
|
}
|
|
108
|
-
|
|
109
160
|
this._isRunning = false;
|
|
161
|
+
|
|
110
162
|
if (this._chunkTimer) {
|
|
111
163
|
clearTimeout(this._chunkTimer);
|
|
112
164
|
this._chunkTimer = undefined;
|
|
@@ -118,6 +170,12 @@ class UIProfiler {
|
|
|
118
170
|
this._collectCurrentChunk().catch(e => {
|
|
119
171
|
DEBUG_BUILD && debug.error('[Profiling] Failed to collect current profile chunk on `stop()`:', e);
|
|
120
172
|
});
|
|
173
|
+
|
|
174
|
+
// Manual: Clear profiling context so spans outside start()/stop() aren't marked as profiled
|
|
175
|
+
// Trace: Profile context is kept for the whole session duration
|
|
176
|
+
if (this._lifecycleMode === 'manual') {
|
|
177
|
+
getGlobalScope().setContext('profile', {});
|
|
178
|
+
}
|
|
121
179
|
}
|
|
122
180
|
|
|
123
181
|
/** Trace-mode: attach spanStart/spanEnd listeners. */
|
|
@@ -149,7 +207,7 @@ class UIProfiler {
|
|
|
149
207
|
debug.log(
|
|
150
208
|
`[Profiling] Root span ${spanId} started. Profiling active while there are active root spans (count=${rootSpanCount}).`,
|
|
151
209
|
);
|
|
152
|
-
this.
|
|
210
|
+
this._beginProfiling();
|
|
153
211
|
}
|
|
154
212
|
});
|
|
155
213
|
|
|
@@ -172,13 +230,13 @@ class UIProfiler {
|
|
|
172
230
|
this._collectCurrentChunk().catch(e => {
|
|
173
231
|
DEBUG_BUILD && debug.error('[Profiling] Failed to collect current profile chunk on last `spanEnd`:', e);
|
|
174
232
|
});
|
|
175
|
-
this.
|
|
233
|
+
this._endProfiling();
|
|
176
234
|
}
|
|
177
235
|
});
|
|
178
236
|
}
|
|
179
237
|
|
|
180
238
|
/**
|
|
181
|
-
* Resets profiling information from scope and resets running state
|
|
239
|
+
* Resets profiling information from scope and resets running state (used on failure)
|
|
182
240
|
*/
|
|
183
241
|
_resetProfilerInfo() {
|
|
184
242
|
this._isRunning = false;
|
|
@@ -193,7 +251,7 @@ class UIProfiler {
|
|
|
193
251
|
this._rootSpanTimeouts.clear();
|
|
194
252
|
}
|
|
195
253
|
|
|
196
|
-
/**
|
|
254
|
+
/** Keep track of root spans and schedule safeguard timeout (trace mode). */
|
|
197
255
|
_registerTraceRootSpan(spanId) {
|
|
198
256
|
this._activeRootSpanIds.add(spanId);
|
|
199
257
|
const timeout = setTimeout(() => this._onRootSpanTimeout(spanId), MAX_ROOT_SPAN_PROFILE_MS);
|
|
@@ -205,11 +263,11 @@ class UIProfiler {
|
|
|
205
263
|
*/
|
|
206
264
|
_startProfilerInstance() {
|
|
207
265
|
if (this._profiler?.stopped === false) {
|
|
208
|
-
return;
|
|
266
|
+
return; // already running
|
|
209
267
|
}
|
|
210
268
|
const profiler = startJSSelfProfile();
|
|
211
269
|
if (!profiler) {
|
|
212
|
-
DEBUG_BUILD && debug.log('[Profiling] Failed to start JS Profiler
|
|
270
|
+
DEBUG_BUILD && debug.log('[Profiling] Failed to start JS Profiler.');
|
|
213
271
|
return;
|
|
214
272
|
}
|
|
215
273
|
this._profiler = profiler;
|
|
@@ -266,14 +324,13 @@ class UIProfiler {
|
|
|
266
324
|
|
|
267
325
|
this._activeRootSpanIds.delete(rootSpanId);
|
|
268
326
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
this.stop();
|
|
327
|
+
if (this._activeRootSpanIds.size === 0) {
|
|
328
|
+
this._endProfiling();
|
|
272
329
|
}
|
|
273
330
|
}
|
|
274
331
|
|
|
275
332
|
/**
|
|
276
|
-
* Stop
|
|
333
|
+
* Stop current profiler instance, convert profile to chunk & send.
|
|
277
334
|
*/
|
|
278
335
|
async _collectCurrentChunk() {
|
|
279
336
|
const prevProfiler = this._profiler;
|