Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(core): Serialize streamed span status message to sentry.status.message attribute#21811
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -31,6 +31,16 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_OP = 'sentry.op'; | ||
| */ | ||
| export const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin'; | ||
| /** | ||
| * Holds the human-readable span status message (e.g. set via | ||
| * `span.setStatus({ code, message })`). | ||
| * | ||
| * Streamed (v2) span statuses are reduced to `ok`/`error`, so we preserve the | ||
| * message as an attribute instead of dropping it. This mirrors the attribute | ||
| * Sentry's OTLP ingestion uses for the same purpose. | ||
| */ | ||
| export const SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE = 'sentry.status.message'; | ||
Member 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 know core doesn't have MemberAuthor 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. yup, we need to add conventions to core. | ||
| /** The reason why an idle span finished. */ | ||
| export const SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON = 'sentry.idle_span_finish_reason'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // oxlint-disable max-lines | ||
| import { getAsyncContextStrategy } from '../asyncContext'; | ||
| import type { RawAttributes } from '../attributes'; | ||
| import { serializeAttributes } from '../attributes'; | ||
| @@ -8,6 +9,7 @@ import { | ||
| SEMANTIC_ATTRIBUTE_SENTRY_OP, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, | ||
| } from '../semanticAttributes'; | ||
| import type { SentrySpan } from '../tracing/sentrySpan'; | ||
| import { SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus'; | ||
| @@ -228,8 +230,8 @@ export function spanToStreamedSpanJSON(span: Span): StreamedSpanJSON { | ||
| start_timestamp: spanTimeInputToSeconds(startTime), | ||
| end_timestamp: spanTimeInputToSeconds(endTime), | ||
| is_segment: span === INTERNAL_getSegmentSpan(span), | ||
| status: getSimpleStatusMessage(status), | ||
| attributes, | ||
| status: getSimpleStatus(status), | ||
| attributes: addStatusMessageAttribute(attributes, status), | ||
| links: getStreamedSpanLinks(links), | ||
| }; | ||
| } | ||
| @@ -330,7 +332,7 @@ export function getStatusMessage(status: SpanStatus | undefined): string | undef | ||
| /** | ||
| * Convert the various statuses to the simple ones expected by Sentry for streamed spans ('ok' is default). | ||
| */ | ||
| export function getSimpleStatusMessage(status: SpanStatus | undefined): 'ok' | 'error' { | ||
| export function getSimpleStatus(status: SpanStatus | undefined): 'ok' | 'error' { | ||
| return !status || | ||
| status.code === SPAN_STATUS_OK || | ||
| status.code === SPAN_STATUS_UNSET || | ||
| @@ -339,6 +341,23 @@ export function getSimpleStatusMessage(status: SpanStatus | undefined): 'ok' | ' | ||
| : 'error'; | ||
| } | ||
| /** | ||
| * Returns the span's attributes with the SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE attribute added | ||
| * if the span has an error status message worth preserving. | ||
| * | ||
| * An explicitly set attribute is never overwritten. | ||
| */ | ||
| export function addStatusMessageAttribute( | ||
| attributes: SpanAttributes, | ||
| status: SpanStatus | undefined, | ||
| ): RawAttributes<Record<string, unknown>> { | ||
| const statusMessage = getSimpleStatus(status) === 'error' ? status?.message : undefined; | ||
| return { | ||
| ...(statusMessage && { [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: statusMessage }), | ||
| ...attributes, | ||
| }; | ||
Lms24 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| const CHILD_SPANS_FIELD = '_sentryChildSpans'; | ||
| const ROOT_SPAN_FIELD = '_sentryRootSpan'; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.