Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/astro/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export declare function init(options: Options | clientSdk.BrowserOptions | NodeO
export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration;
export declare const spanStreamingIntegration: typeof clientSdk.spanStreamingIntegration;
export declare const startSpan: typeof clientSdk.startSpan;
export declare const startSpanManual: typeof clientSdk.startSpanManual;
export declare const startInactiveSpan: typeof clientSdk.startInactiveSpan;
export declare const withStaticSpan: typeof clientSdk.withStaticSpan;
// oxlint-disable-next-line typescript/no-deprecated
export declare const withStreamedSpan: typeof clientSdk.withStreamedSpan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export { elementTimingIntegration } from '@sentry/browser-utils';
export { reportPageLoaded } from './tracing/reportPageLoaded';
export { setActiveSpanInBrowser } from './tracing/setActiveSpan';

export { spanStreamingIntegration } from './integrations/spanstreaming';
export { spanStreamingIntegration } from '@sentry/core/browser';
export { fetchStreamPerformanceIntegration } from './integrations/fetchStreamPerformance';
export { webVitalsIntegration } from './integrations/webVitals';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export { elementTimingIntegration } from '@sentry/browser-utils';
export { reportPageLoaded } from './tracing/reportPageLoaded';
export { setActiveSpanInBrowser } from './tracing/setActiveSpan';

export { spanStreamingIntegration } from './integrations/spanstreaming';
export { spanStreamingIntegration } from '@sentry/core/browser';
export { fetchStreamPerformanceIntegration } from './integrations/fetchStreamPerformance';
export { webVitalsIntegration } from './integrations/webVitals';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export { setActiveSpanInBrowser } from './tracing/setActiveSpan';

export { reportPageLoaded } from './tracing/reportPageLoaded';

export { spanStreamingIntegration } from './integrations/spanstreaming';
export { spanStreamingIntegration } from '@sentry/core/browser';
export { fetchStreamPerformanceIntegration } from './integrations/fetchStreamPerformance';
export { webVitalsIntegration } from './integrations/webVitals';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export { elementTimingIntegration } from '@sentry/browser-utils';
export { reportPageLoaded } from './tracing/reportPageLoaded';
export { setActiveSpanInBrowser } from './tracing/setActiveSpan';

export { spanStreamingIntegration } from './integrations/spanstreaming';
export { spanStreamingIntegration } from '@sentry/core/browser';
export { fetchStreamPerformanceIntegration } from './integrations/fetchStreamPerformance';
export { webVitalsIntegration } from './integrations/webVitals';

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/index.bundle.tracing.replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export { elementTimingIntegrationShim as elementTimingIntegration };
export { reportPageLoaded } from './tracing/reportPageLoaded';
export { setActiveSpanInBrowser } from './tracing/setActiveSpan';

export { spanStreamingIntegration } from './integrations/spanstreaming';
export { spanStreamingIntegration } from '@sentry/core/browser';
export { fetchStreamPerformanceIntegration } from './integrations/fetchStreamPerformance';
export { webVitalsIntegration } from './integrations/webVitals';

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/index.bundle.tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export { setActiveSpanInBrowser } from './tracing/setActiveSpan';

export { reportPageLoaded } from './tracing/reportPageLoaded';

export { spanStreamingIntegration } from './integrations/spanstreaming';
export { spanStreamingIntegration } from '@sentry/core/browser';
export { fetchStreamPerformanceIntegration } from './integrations/fetchStreamPerformance';
export { webVitalsIntegration } from './integrations/webVitals';

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export { elementTimingIntegration, getAbsoluteUrl } from '@sentry/browser-utils'
export { normalizeStringifyValue } from './normalizeStringifyValue';
export { reportPageLoaded } from './tracing/reportPageLoaded';
export { setActiveSpanInBrowser } from './tracing/setActiveSpan';
export { spanStreamingIntegration } from './integrations/spanstreaming';
export { spanStreamingIntegration } from '@sentry/core/browser';
export { fetchStreamPerformanceIntegration } from './integrations/fetchStreamPerformance';
export { webVitalsIntegration } from './integrations/webVitals';
export { userTimingIntegration } from './integrations/usertiming';
Expand Down
7 changes: 2 additions & 5 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getIntegrationsToSetup,
initAndBind,
setNormalizeStringifier,
spanStreamingIntegration,
stackParserFromStackParserOptions,
} from '@sentry/core/browser';
import type { BrowserClientOptions, BrowserOptions } from './client';
Expand All @@ -19,10 +20,6 @@ import { globalHandlersIntegration } from './integrations/globalhandlers';
import { httpContextIntegration } from './integrations/httpcontext';
import { linkedErrorsIntegration } from './integrations/linkederrors';
import { spotlightBrowserIntegration } from './integrations/spotlight';
import {
spanStreamingIntegration,
INTEGRATION_NAME as SPAN_STREAMING_INTEGRATION_NAME,
} from './integrations/spanstreaming';
import { defaultStackParser } from './stack-parsers';
import { makeFetchTransport } from './transports/fetch';
import { normalizeStringifyValue } from './normalizeStringifyValue';
Expand Down Expand Up @@ -122,7 +119,7 @@ export function init(options: BrowserOptions = {}): Client | undefined {
if (
(typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) &&
options.traceLifecycle !== 'static' &&
!integrations.some(integration => integration.name === SPAN_STREAMING_INTEGRATION_NAME)
!integrations.some(integration => integration.name === 'SpanStreaming')
) {
integrations.push(spanStreamingIntegration());
}
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/browser-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
*
* @module
*/

export {
startSpan,
startInactiveSpan,
startSpanManual,
startIdleSpan,
_INTERNAL_ensureBrowserSpanStreaming,
} from './tracing/browserSpanApi';

export { spanStreamingIntegration } from './integrations/browserSpanStreaming';

export {
getComponentName,
getLocationHref,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { HTTP_METHOD, SERVER_ADDRESS, URL_FRAGMENT, URL_FULL, URL_QUERY } from '
import type { Client } from './client';
import { getClient } from './currentScopes';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';
import { setHttpStatus, SPAN_STATUS_ERROR, spanIsIgnored, startInactiveSpan } from './tracing';
import { setHttpStatus, SPAN_STATUS_ERROR, spanIsIgnored } from './tracing';
import { startInactiveSpan } from './tracing/trace';
import { SentryNonRecordingSpan } from './tracing/sentryNonRecordingSpan';
import { hasSpanStreamingEnabled } from './tracing/spans/hasSpanStreamingEnabled';
import type { FetchBreadcrumbHint } from './types/breadcrumb';
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export * from './shared-exports';
export * from './server-exports';
export * from './browser-exports';

// `server-exports` and `browser-exports` both export these APIs.
// We need to re-export them here to disambiguate the exports for anyone importing
// from `@sentry/core`. Server exports win over browser exports.
export { startSpan, startInactiveSpan, startSpanManual } from './tracing/trace';
export { startIdleSpan } from './tracing/idleSpan';
export { spanStreamingIntegration } from './integrations/spanStreaming';
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { IntegrationFn } from '@sentry/core/browser';
import {
captureSpan,
debug,
defineIntegration,
hasSpanStreamingEnabled,
SpanBuffer,
spanIsSampled,
} from '@sentry/core/browser';
import type { IntegrationFn } from '../types/integration';
import { DEBUG_BUILD } from '../debug-build';
import { defineIntegration } from '../integration';
import { captureSpan } from '../tracing/spans/captureSpan';
import { hasSpanStreamingEnabled } from '../tracing/spans/hasSpanStreamingEnabled';
import { SpanBuffer } from '../tracing/spans/spanBuffer';
import { debug } from '../utils/debug-logger';
import { spanIsSampled } from '../utils/spanUtils';

export const INTEGRATION_NAME = 'SpanStreaming' as const;

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/integrations/express/patch-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { SENTRY_OP } from '@sentry/conventions/attributes';
import { WEB_SERVER_MIDDLEWARE_SPAN_OP } from '@sentry/conventions/op';
import { DEBUG_BUILD } from '../../debug-build';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
import { SPAN_STATUS_ERROR, startSpanManual, withActiveSpan } from '../../tracing';
import { SPAN_STATUS_ERROR, withActiveSpan } from '../../tracing';
import { startSpanManual } from '../../tracing/trace';
import { debug } from '../../utils/debug-logger';
import type { SpanAttributes } from '../../types/span';
import { getActiveSpan } from '../../utils/spanUtils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
isTracingSuppressed,
SPAN_STATUS_ERROR,
SPAN_STATUS_UNSET,
startInactiveSpan,
withActiveSpan,
} from '../../tracing';
import { startInactiveSpan } from '../../tracing/trace';
import { debug } from '../../utils/debug-logger';
import { LRUMap } from '../../utils/lru';
import { getOutgoingRequestSpanData, setIncomingResponseSpanData } from './get-outgoing-span-data';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/integrations/http/server-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { parseStringToURLObject, stripUrlQueryAndFragment } from '../../utils/ur
import { recordRequestSession } from './record-request-session';
import { generateSpanId, generateTraceId } from '../../utils/propagationContext';
import { continueTrace } from '../../tracing/trace';
import { getSpanStatusFromHttpCode, SPAN_STATUS_ERROR, startSpanManual } from '../../tracing';
import { getSpanStatusFromHttpCode, SPAN_STATUS_ERROR } from '../../tracing';
import { startSpanManual } from '../../tracing/trace';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/integrations/mcp-server/spans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
} from '../../semanticAttributes';
import { startSpan } from '../../tracing';
import { startSpan } from '../../tracing/trace';
import { buildTransportAttributes, buildTypeSpecificAttributes } from './attributeExtraction';
import {
MCP_FUNCTION_ORIGIN_VALUE,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/integrations/mcp-server/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { getIsolationScope, withIsolationScope } from '../../currentScopes';
import { startInactiveSpan, withActiveSpan } from '../../tracing';
import { withActiveSpan } from '../../tracing';
import { startInactiveSpan } from '../../tracing/trace';
import { isObjectLike } from '../../utils/is';
import { fill } from '../../utils/object';
import { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/integrations/postgresjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import { DEBUG_BUILD } from '../debug-build';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
import { SPAN_STATUS_ERROR, startSpanManual } from '../tracing';
import { SPAN_STATUS_ERROR } from '../tracing';
import { startSpanManual } from '../tracing/trace';
import type { Span } from '../types/span';
import { debug } from '../utils/debug-logger';
import { isObjectLike } from '../utils/is';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/integrations/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { DEBUG_BUILD } from '../debug-build';
import { captureException } from '../exports';
import { defineIntegration } from '../integration';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
import { setHttpStatus, SPAN_STATUS_ERROR, SPAN_STATUS_OK, startSpan } from '../tracing';
import { setHttpStatus, SPAN_STATUS_ERROR, SPAN_STATUS_OK } from '../tracing';
import { startSpan } from '../tracing/trace';
import type { IntegrationFn } from '../types/integration';
import type { WebFetchHeaders } from '../types/webfetchapi';
import { debug } from '../utils/debug-logger';
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/server-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* @module
*/

export { startSpan, startInactiveSpan, startSpanManual } from './tracing/trace';
export { startIdleSpan } from './tracing/idleSpan';
export { spanStreamingIntegration } from './integrations/spanStreaming';

export type { ServerRuntimeClientOptions } from './server-runtime-client';
export { ServerRuntimeClient } from './server-runtime-client';
export type { ServerRuntimeOptions } from './types/options';
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/shared-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export type { MetricOptions } from './metrics/public-api';
export { createConsolaReporter } from './integrations/consola';
export { SpanBuffer } from './tracing/spans/spanBuffer';
export { hasSpanStreamingEnabled } from './tracing/spans/hasSpanStreamingEnabled';
export { spanStreamingIntegration } from './integrations/spanStreaming';
export type { FeatureFlag } from './utils/featureFlags';
export {
_INTERNAL_copyFlagsFromScopeToEvent,
Expand Down
85 changes: 85 additions & 0 deletions packages/core/src/tracing/browserSpanApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import type { Client } from '../client';
import { getClient } from '../currentScopes';
import { spanStreamingIntegration } from '../integrations/browserSpanStreaming';
import type { Span } from '../types/span';
import type { StartSpanOptions } from '../types/startSpanOptions';
import { startIdleSpan as coreStartIdleSpan } from './idleSpan';
import { hasSpanStreamingEnabled } from './spans/hasSpanStreamingEnabled';
import {
startInactiveSpan as coreStartInactiveSpan,
startSpan as coreStartSpan,
startSpanManual as coreStartSpanManual,
} from './trace';

/**
* Browser variants of the span-start APIs.
*
* These exist purely so that the span streaming integration is only reachable from code that can
* actually start a span. `@sentry/browser`'s `init()` deliberately doesn't reference spanStreamingIntegration,
* so error-only apps tree-shake the entire span streaming graph away without needing
* the `__SENTRY_TRACING__` flag.
*/

const clientsWithIntegration = new WeakSet<Client>();

/**
* Lazily install the browser span streaming integration.
*
* Defaults to the current client; pass one explicitly from integration hooks, where the client being
* set up isn't necessarily the current one.
*
* @internal
*/
export function _INTERNAL_ensureBrowserSpanStreaming(client: Client | undefined = getClient()): void {
// The `WeakSet` is an allocation optimization, not a semantic gate — `addIntegration()` is already
// idempotent by integration name, including against a user-supplied instance.
if (!client || clientsWithIntegration.has(client) || !hasSpanStreamingEnabled(client)) {
return;
}

clientsWithIntegration.add(client);
client.addIntegration(spanStreamingIntegration());
}

/**
* Wraps a function with a span and finishes the span after the function is done.
*
* See {@link startSpan} in `@sentry/core` for details.
*/
export function startSpan<T>(options: StartSpanOptions, callback: (span: Span) => T): T {
_INTERNAL_ensureBrowserSpanStreaming();
return coreStartSpan(options, callback);
}

/**
* Similar to `startSpan`, but forces the span to be ended manually.
*
* See {@link startSpanManual} in `@sentry/core` for details.
*/
export function startSpanManual<T>(options: StartSpanOptions, callback: (span: Span, finish: () => void) => T): T {
_INTERNAL_ensureBrowserSpanStreaming();
return coreStartSpanManual(options, callback);
}

/**
* Creates a span that is not set as active.
*
* See {@link startInactiveSpan} in `@sentry/core` for details.
*/
export function startInactiveSpan(options: StartSpanOptions): Span {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: Did you check that our browser SDKs all use this method and not import from core directly? e.g. svelte still does import { debug, startInactiveSpan } from '@sentry/core';

_INTERNAL_ensureBrowserSpanStreaming();
return coreStartInactiveSpan(options);
}

/**
* Starts an idle span that automatically ends once no activity happens for a while.
*
* See {@link startIdleSpan} in `@sentry/core` for details.
*
* Typed via `typeof` because `IdleSpanOptions` is intentionally not part of the public type surface,
* and re-declaring the signature here would have to widen it.
*/
export const startIdleSpan: typeof coreStartIdleSpan = (startSpanOptions, options) => {
_INTERNAL_ensureBrowserSpanStreaming();
return coreStartIdleSpan(startSpanOptions, options);
};
5 changes: 1 addition & 4 deletions packages/core/src/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export {
markSpanAsTracerProviderSpan,
spanIsTracerProviderSpan,
} from './utils';
export { startIdleSpan, TRACING_DEFAULTS } from './idleSpan';
export { TRACING_DEFAULTS } from './idleSpan';
export { SentrySpan } from './sentrySpan';
export { _INTERNAL_setDeferSegmentSpanCapture } from './deferSegmentSpanCapture';
export { SentryNonRecordingSpan } from './sentryNonRecordingSpan';
Expand All @@ -18,10 +18,7 @@ export {
SPAN_STATUS_UNSET,
} from './spanstatus';
export {
startSpan,
startInactiveSpan,
_INTERNAL_startInactiveSpan,
startSpanManual,
continueTrace,
withActiveSpan,
suppressTracing,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { WEB_SERVER_RPC_SPAN_OP } from '@sentry/conventions/op';
import { getClient, withIsolationScope } from './currentScopes';
import { captureException } from './exports';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from './semanticAttributes';
import { startSpanManual } from './tracing';
import { startSpanManual } from './tracing/trace';
import { normalize } from './utils/normalize';
import { setNormalizationDepthOverrideHint } from './utils/normalizationHints';

Expand Down
Loading
Loading