Span API
Calling the global startSpan
method always creates a root span.
Copied
span = sentry.tracing.startSpan({
name: "GET /",
op: "http.server",
});
This method sets the end timestamp on the span. If the span is a root span, it emits the entire span tree to Sentry.
Copied
span = sentry.tracing.startSpan({
name: "GET /",
op: "http.server",
});
span.end();
Creates a new root span which continues the trace based on the provided trace and parent span id.
Copied
span = sentry.tracing.startSpan({
traceId: '',
parentSpanId: '',
sampled: true,
name: 'GET /'
op: 'http.server'
})
Calling the global startSpan
method always creates a root span.
Copied
span = sentry.tracing.startSpan({
name: "GET /",
op: "http.server",
});
Copied
span = sentry.tracing.startSpan({
name: "GET /",
op: "http.server",
attributes: {
attr1: "value1",
attr2: 42,
attr3: true,
},
});
To create nested spans, you must call startSpan
on the parent span.
Copied
span = sentry.tracing.startSpan({ ... })
childSpan = span.startSpan({ ... })
Copied
span = scope.getSpan();
Copied
scope.setSpan(span);
Copied
rootSpan = scope.getRootSpan();
span.setStartTimestamp()
- overwrite the span’s start time
span.setEndTimestamp()
- overwrites the span’s end time
span.setStatus()
- success, error, unknown
span.getBaggage()
- returns the baggage string
span.getTraceparent()
- returns the sentry trace parent string
Copied
rootSpan = sentry.tracing.startSpan({
name: "GET /",
op: "http.server",
});
span = rootSpan.startSpan({
name: "middleware.handle",
op: "http.middleware",
});
span.end();
rootSpan.end();
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").