11import type { BeforeSendStaticSpanCallback , BeforeSendStreamedSpanCallback } from '../../types/options' ;
2- import type { SpanJSON , StreamedSpanJSON } from '../../types/span' ;
2+ import type { StreamedSpanJSON } from '../../types/span' ;
33import { addNonEnumerableProperty } from '../../utils/object' ;
44
55/**
66 * A wrapper to use the static, transaction-based span format in your `beforeSendSpan` callback.
77 *
88 * When using `traceLifecycle: 'static'`, wrap your callback with this function
9- * to receive and return { @link SpanJSON} instead of {@link StreamedSpanJSON}.
9+ * to receive and return a static span instead of a {@link StreamedSpanJSON}.
1010 *
1111 * @example
1212 *
@@ -18,12 +18,15 @@ import { addNonEnumerableProperty } from '../../utils/object';
1818 * }),
1919 * });
2020 *
21- * @param callback - The callback function that receives and returns a { @link SpanJSON} .
21+ * @param callback - A { @link BeforeSendStaticSpanCallback} that receives and returns a static span .
2222 * @returns A callback that is compatible with the `beforeSendSpan` option when using `traceLifecycle: 'static'`.
2323 */
24- export function withStaticSpan ( callback : ( span : SpanJSON ) => SpanJSON ) : BeforeSendStaticSpanCallback {
24+ export function withStaticSpan ( callback : BeforeSendStaticSpanCallback ) : BeforeSendStreamedSpanCallback {
2525 addNonEnumerableProperty ( callback , '_static' , true ) ;
26- return callback as BeforeSendStaticSpanCallback ;
26+ // `beforeSendSpan` is typed as a single streamed callback so that an unwrapped callback's parameter
27+ // is contextually typed as `StreamedSpanJSON`. The `_static` marker tells the SDK to hand this
28+ // callback a `SpanJSON` instead, so the declared parameter type is deliberately not what it receives.
29+ return callback as unknown as BeforeSendStreamedSpanCallback ;
2730}
2831
2932/**
@@ -50,13 +53,3 @@ export function withStreamedSpan(
5053export function isStaticBeforeSendSpanCallback ( callback : unknown ) : callback is BeforeSendStaticSpanCallback {
5154 return ! ! callback && typeof callback === 'function' && '_static' in callback && ! ! callback . _static ;
5255}
53-
54- /**
55- * Typesafe check to identify if a `beforeSendSpan` callback expects the streamed span JSON format.
56- *
57- * @param callback - The `beforeSendSpan` callback to check.
58- * @returns `true` unless the callback was marked as a static span callback.
59- */
60- export function isStreamedBeforeSendSpanCallback ( callback : unknown ) : callback is BeforeSendStreamedSpanCallback {
61- return ! ! callback && typeof callback === 'function' && ! isStaticBeforeSendSpanCallback ( callback ) ;
62- }
0 commit comments