@@ -2,6 +2,8 @@ import { SpanKind } from '@opentelemetry/api';
22import { HTTP_RESPONSE_STATUS_CODE , HTTP_STATUS_CODE } from '@sentry/conventions/attributes' ;
33import {
44 addNonEnumerableProperty ,
5+ getClient ,
6+ hasSpanStreamingEnabled ,
57 SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME ,
68 SEMANTIC_ATTRIBUTE_SENTRY_OP ,
79 SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
@@ -81,7 +83,8 @@ export function applyOtelSpanData(span: Span, options: { finalizeStatus?: boolea
8183
8284 if ( options . finalizeStatus ) {
8385 applyOtelCompatibilityAttributes ( span , attributes ) ;
84- applyOtelSpanStatus ( span , attributes , spanJSON . status ) ;
86+ const client = getClient ( ) ;
87+ applyOtelSpanStatus ( span , attributes , spanJSON . status , ! ! client && hasSpanStreamingEnabled ( client ) ) ;
8588 }
8689
8790 // Only re-infer the name for spans branded for OTel source inference (those the provider created
@@ -103,13 +106,23 @@ export function applyOtelSpanKind(span: Span, kind: SpanKind | undefined): void
103106 addNonEnumerableProperty ( span as SentrySpanWithOtelKind , 'kind' , kind ?? SpanKind . INTERNAL ) ;
104107}
105108
106- function applyOtelSpanStatus ( span : Span , attributes : SpanAttributes , status : string | undefined ) : void {
109+ function applyOtelSpanStatus (
110+ span : Span ,
111+ attributes : SpanAttributes ,
112+ status : string | undefined ,
113+ spanStreamingEnabled : boolean ,
114+ ) : void {
107115 if ( status === undefined ) {
108116 span . setStatus ( inferStatusFromAttributes ( attributes ) || { code : SPAN_STATUS_OK } ) ;
109117 return ;
110118 }
111119
112- if ( status !== 'ok' && ! isStatusErrorMessageValid ( status ) ) {
120+ // Normalize a non-canonical error message to `internal_error` for the (non-streamed) transaction
121+ // `status` field, matching the OTel SDK exporter's `mapStatus`. Skip this under span streaming: the
122+ // streamed serializer preserves the raw message as `sentry.status.message` by reading the live span
123+ // status, and the OTel SDK path keeps it too because `mapStatus` maps at export without mutating the
124+ // span. Overwriting it here would replace that message with `internal_error`.
125+ if ( ! spanStreamingEnabled && status !== 'ok' && ! isStatusErrorMessageValid ( status ) ) {
113126 span . setStatus ( { code : SPAN_STATUS_ERROR , message : 'internal_error' } ) ;
114127 }
115128}
0 commit comments