Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit ba070ae

Browse files
author
naseemkullah
committed
feat: add tracer.startActiveSpan()
Signed-off-by: naseemkullah <naseem@transit.app>
1 parent e938882 commit ba070ae

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/trace/tracer.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,34 @@ export interface Tracer {
3737
* span.end();
3838
*/
3939
startSpan(name: string, options?: SpanOptions, context?: Context): Span;
40+
41+
/**
42+
* Starts a new {@link Span} and activates it in the current Context.
43+
*
44+
* @param name The name of the span
45+
* @param [options] SpanOptions used for span creation
46+
* @param [context] Context to use to extract parent
47+
* @param callback called in the context of the span and receives the newly created span as an argument
48+
* @returns what is returned by the callback
49+
* @example
50+
* const span = tracer.startActiveSpan('op', {}, undefined, (err, span) => {
51+
* span.setAttribute('key', 'value');
52+
* span.end();
53+
* });
54+
*/
55+
startActiveSpan<F extends (err: Error, span: Span) => ReturnType<F>>(
56+
name: string,
57+
callback: F
58+
): ReturnType<F>;
59+
startActiveSpan<F extends (err: Error, span: Span) => ReturnType<F>>(
60+
name: string,
61+
options: SpanOptions,
62+
callback: F
63+
): ReturnType<F>;
64+
startActiveSpan<F extends (err: Error, span: Span) => ReturnType<F>>(
65+
name: string,
66+
options: SpanOptions,
67+
context: Context,
68+
callback: F
69+
): ReturnType<F>;
4070
}

0 commit comments

Comments
 (0)