-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Create types and utilities for span links #15375
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10337a5
feat(core): Create types and utilities for span links
s1gr1d 6db209c
Merge branch 'develop' into sig/span-link-types
s1gr1d 3f28bf9
review suggestions
s1gr1d 1e5f6d1
remove unknown typing
s1gr1d 8dfb073
Merge branch 'develop' into sig/span-link-types
s1gr1d 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
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
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
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
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,30 @@ | ||
import type { SpanAttributeValue, SpanContextData } from './span'; | ||
|
||
type SpanLinkAttributes = { | ||
/** | ||
* Setting the link type to 'previous_trace' helps the Sentry product linking to the previous trace | ||
*/ | ||
'sentry.link.type'?: string | 'previous_trace'; | ||
} & Record<string, SpanAttributeValue | undefined>; | ||
|
||
export interface SpanLink { | ||
/** | ||
* Contains the SpanContext of the span to link to | ||
*/ | ||
context: SpanContextData; | ||
/** | ||
* A key-value pair with primitive values or an array of primitive values | ||
*/ | ||
attributes?: SpanLinkAttributes; | ||
} | ||
|
||
/** | ||
* Link interface for the event envelope item. It's a flattened representation of `SpanLink`. | ||
* Can include additional fields defined by OTel. | ||
*/ | ||
export interface SpanLinkJSON extends Record<string, unknown> { | ||
span_id: string; | ||
trace_id: string; | ||
sampled?: boolean; | ||
attributes?: SpanLinkAttributes; | ||
} |
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
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 |
---|---|---|
|
@@ -14,6 +14,8 @@ import type { | |
Span, | ||
SpanAttributes, | ||
SpanJSON, | ||
SpanLink, | ||
SpanLinkJSON, | ||
SpanOrigin, | ||
SpanStatus, | ||
SpanTimeInput, | ||
|
@@ -81,6 +83,19 @@ export function spanToTraceHeader(span: Span): string { | |
return generateSentryTraceHeader(traceId, spanId, sampled); | ||
} | ||
|
||
/** | ||
* Converts the span links array to a flattened version to be sent within an envelope | ||
*/ | ||
export function convertSpanLinksForEnvelope(links: SpanLink[]): SpanLinkJSON[] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: I assume this is getting tested in subsequent PRs when we serialize envelopes? If so, ignore me and no objections :) |
||
return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({ | ||
span_id: spanId, | ||
trace_id: traceId, | ||
sampled: traceFlags === TRACE_FLAG_SAMPLED, | ||
s1gr1d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
attributes, | ||
...restContext, | ||
})); | ||
} | ||
|
||
/** | ||
* Convert a span time input into a timestamp in seconds. | ||
*/ | ||
|
@@ -180,7 +195,7 @@ function spanIsSentrySpan(span: Span): span is SentrySpan { | |
* However, this has a slightly different semantic, as it also returns false if the span is finished. | ||
* So in the case where this distinction is important, use this method. | ||
*/ | ||
export function spanIsSampled(span: Span): boolean { | ||
export function spanIsSampled(span: { spanContext: Span['spanContext'] }): boolean { | ||
s1gr1d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// We align our trace flags with the ones OpenTelemetry use | ||
// So we also check for sampled the same way they do. | ||
const { traceFlags } = span.spanContext(); | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.