UNPKG

@sentry/core

Version:
57 lines (56 loc) • 2.21 kB
import { getClient } from "../currentScopes.js"; import { spanStreamingIntegration } from "../integrations/spanStreaming.js"; import { hasSpanStreamingEnabled } from "./spans/hasSpanStreamingEnabled.js"; import { startInactiveSpan as startInactiveSpan$1, startSpan as startSpan$1, startSpanManual as startSpanManual$1 } from "./trace.js"; // src/tracing/browserSpanApi.ts /** * 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 = /* @__PURE__ */ new WeakSet(); /** * 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 */ function _INTERNAL_ensureBrowserSpanStreaming(client = getClient()) { 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. */ function startSpan(options, callback) { _INTERNAL_ensureBrowserSpanStreaming(); return startSpan$1(options, callback); } /** * Similar to `startSpan`, but forces the span to be ended manually. * * See {@link startSpanManual} in `@sentry/core` for details. */ function startSpanManual(options, callback) { _INTERNAL_ensureBrowserSpanStreaming(); return startSpanManual$1(options, callback); } /** * Creates a span that is not set as active. * * See {@link startInactiveSpan} in `@sentry/core` for details. */ function startInactiveSpan(options) { _INTERNAL_ensureBrowserSpanStreaming(); return startInactiveSpan$1(options); } export { _INTERNAL_ensureBrowserSpanStreaming, startInactiveSpan, startSpan, startSpanManual }; //# sourceMappingURL=browserSpanApi.js.map