UNPKG

@sentry/core

Version:
57 lines (56 loc) • 2.29 kB
import { DEBUG_BUILD } from "../../debug-build.js"; import { addNonEnumerableProperty } from "../../utils/object.js"; import { safeCallback } from "../../utils/safeCallback.js"; // src/tracing/spans/beforeSendSpan.ts /** * A wrapper to use the static, transaction-based span format in your `beforeSendSpan` callback. * * When using `traceLifecycle: 'static'`, wrap your callback with this function * to receive and return a static span instead of a {@link StreamedSpanJSON}. * * @example * * Sentry.init({ * traceLifecycle: 'static', * beforeSendSpan: withStaticSpan((span) => { * // span is of type SpanJSON * return span; * }), * }); * * @param callback - A {@link BeforeSendStaticSpanCallback} that receives and returns a static span. * @returns A callback that is compatible with the `beforeSendSpan` option when using `traceLifecycle: 'static'`. */ function withStaticSpan(callback) { addNonEnumerableProperty(callback, "_static", true); return callback; } /** * A wrapper to explicitly use the streamed span format in your `beforeSendSpan` callback. * * @deprecated `beforeSendSpan` callbacks receive {@link StreamedSpanJSON} by default. * This function returns the callback unchanged and will be removed in SDK version 12. * * @param callback - The callback function that receives and returns a {@link StreamedSpanJSON}. * @returns The provided callback. */ function withStreamedSpan(callback) { return callback; } /** * Typesafe check to identify if a `beforeSendSpan` callback expects the static span JSON format. * * @param callback - The `beforeSendSpan` callback to check. * @returns `true` if the callback was wrapped with {@link withStaticSpan}. */ function isStaticBeforeSendSpanCallback(callback) { return !!callback && typeof callback === "function" && "_static" in callback && !!callback._static; } /** * Apply a user-provided beforeSendSpan callback to a span JSON. */ function applyBeforeSendSpanCallback(span, beforeSendSpan) { return safeCallback(DEBUG_BUILD ? "The `beforeSendSpan` callback threw an error, sending the span unmodified:" : "", () => beforeSendSpan(span), () => span) || span; } export { applyBeforeSendSpanCallback, isStaticBeforeSendSpanCallback, withStaticSpan, withStreamedSpan }; //# sourceMappingURL=beforeSendSpan.js.map