-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs(sdks): New Span API #11939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cleptric
wants to merge
1
commit into
master
Choose a base branch
from
spans-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
docs(sdks): New Span API #11939
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Spans | ||
sidebar_order: 8 | ||
--- | ||
|
||
<PageGrid /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: Span API | ||
--- | ||
|
||
<Alert level="info"> | ||
This document uses key words such as "MUST", "SHOULD", and "MAY" as defined in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) to indicate requirement levels. | ||
</Alert> | ||
|
||
Spans are measuring the duration of certain operations in an application. | ||
The topmost member of a span tree is called the root span. This span has no parent span and groups together its children with a representative name for the entire operation, such as `GET /` in case of a request to a backend application. | ||
|
||
## Creating a root span | ||
|
||
The SDK must expose a method for creating a root span. The user must be able to set certain properties on this root span, such as its name, the type of operation (`op`) and others. | ||
|
||
```js | ||
span = sentry.tracing.startSpan() | ||
->setName('GET /') | ||
->setOp('http.server') | ||
|
||
span.end() | ||
``` | ||
|
||
## Creating nested spans | ||
|
||
To create nested spans, the SDK must expose an explicit way for a user to perform this task. | ||
|
||
Additionally, the SDK may expose alternative APIs to create nested spans, such as allowing a user to wrap an operation into a callback or apply a decorator to certain blocks. These alternative APIs must never create a root span and no-op if no parent span is present. | ||
|
||
```js | ||
childSpan = span.startChild() | ||
->setName('authentication middleware') | ||
->setOp('middleware.handle') | ||
|
||
childSpan.end() | ||
``` | ||
|
||
## Setting the span status | ||
|
||
A span has two statuses, `ok` and `error`. By default, the status of a span is set to `ok`. | ||
The SDK must allow a user to modify the status of a span. | ||
|
||
```js | ||
span.setStatus('error') | ||
``` | ||
|
||
## Setting span attributes | ||
|
||
The SDK must expose a method to allow a user to set data attributes onto a span. | ||
These attributes should use pre-defined keys whenever possible. | ||
|
||
```js | ||
span.setAttribute(SpanAttributes.HTTP_METHOD, 'GET') | ||
span.setAttribute(SpanAttributes.HTTP_RESPONSE_STATUS_CODE, 200) | ||
``` | ||
|
||
## Additional, optional span APIs | ||
|
||
`span.setStartTimestamp()` - overwrite the span's start time | ||
|
||
`span.setEndTimestamp()` - overwrites the span's end time |
28 changes: 28 additions & 0 deletions
28
develop-docs/sdk/telemetry/spans/span-trace-propagation.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: Span Trace Propagation | ||
--- | ||
|
||
<Alert level="info"> | ||
This document uses key words such as "MUST", "SHOULD", and "MAY" as defined in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) to indicate requirement levels. | ||
</Alert> | ||
|
||
## Continue an incoming trace | ||
|
||
To continue a trace from an upstream service, the SDK must expose a method to extract the traceparent and baggage information and apply these to the applicable scope. | ||
|
||
```js | ||
scope.setPropagationContext({ | ||
traceparent: request.headers.SENTRY_TRACE, | ||
baggage: request.headers.SENTRY_BAGGAGE, | ||
}) | ||
``` | ||
Newly created root spans should now contain these properties, such as `trace_id` and `parent_span_id`. | ||
|
||
## Continue an outgoing trace | ||
|
||
To propagate a trace to a downstream service, the SDK must expose methods to fetch the required information to allow the next service to continue the trace. | ||
|
||
```js | ||
traceparent = scope.getTraceparent() | ||
baggage = scope.getBaggage() | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention here that this only applies to non-OTEL SDKs.
Generally, I still feel a bit conflicted about designing a new Span API that is not compatible out of the box and by design with OTEL-based SDKs, which are the most important SDKs AFAIK (JS & Python, though not sure if python can possibly do these changes anyhow).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As soon as we're clear with the Performance teams roadmap, I'd like to revamp the API discussion and make sure each team proposes, what they would think would make most sense. I think this puts us in a better situation to actually discuss different solutions and understand the reasoning behind them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR will stay a draft until then, so work that has been done up until now does not get lost