@@ -5,18 +5,21 @@ import { TraceState } from '@opentelemetry/core';
5
5
import type { Sampler , SamplingResult } from '@opentelemetry/sdk-trace-base' ;
6
6
import { SamplingDecision } from '@opentelemetry/sdk-trace-base' ;
7
7
import {
8
- SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD ,
9
8
SEMANTIC_ATTRIBUTE_SENTRY_OP ,
10
9
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE ,
11
- SEMANTIC_ATTRIBUTE_URL_FULL ,
12
10
hasTracingEnabled ,
13
11
sampleSpan ,
14
12
} from '@sentry/core' ;
15
13
import type { Client , SpanAttributes } from '@sentry/types' ;
16
14
import { logger } from '@sentry/utils' ;
17
15
import { SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING , SENTRY_TRACE_STATE_URL } from './constants' ;
18
16
19
- import { SEMATTRS_HTTP_METHOD , SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions' ;
17
+ import {
18
+ ATTR_HTTP_REQUEST_METHOD ,
19
+ ATTR_URL_FULL ,
20
+ SEMATTRS_HTTP_METHOD ,
21
+ SEMATTRS_HTTP_URL ,
22
+ } from '@opentelemetry/semantic-conventions' ;
20
23
import { DEBUG_BUILD } from './debug-build' ;
21
24
import { getPropagationContextFromSpan } from './propagator' ;
22
25
import { getSamplingDecision } from './utils/getSamplingDecision' ;
@@ -52,13 +55,13 @@ export class SentrySampler implements Sampler {
52
55
return wrapSamplingDecision ( { decision : undefined , context, spanAttributes } ) ;
53
56
}
54
57
58
+ // `ATTR_HTTP_REQUEST_METHOD` is the new attribute, but we still support the old one, `SEMATTRS_HTTP_METHOD`, for now.
59
+ // eslint-disable-next-line deprecation/deprecation
60
+ const maybeSpanHttpMethod = spanAttributes [ SEMATTRS_HTTP_METHOD ] || spanAttributes [ ATTR_HTTP_REQUEST_METHOD ] ;
61
+
55
62
// If we have a http.client span that has no local parent, we never want to sample it
56
63
// but we want to leave downstream sampling decisions up to the server
57
- if (
58
- spanKind === SpanKind . CLIENT &&
59
- ( spanAttributes [ SEMATTRS_HTTP_METHOD ] || spanAttributes [ SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD ] ) &&
60
- ( ! parentSpan || parentContext ?. isRemote )
61
- ) {
64
+ if ( spanKind === SpanKind . CLIENT && maybeSpanHttpMethod && ( ! parentSpan || parentContext ?. isRemote ) ) {
62
65
return wrapSamplingDecision ( { decision : undefined , context, spanAttributes } ) ;
63
66
}
64
67
@@ -109,7 +112,7 @@ export class SentrySampler implements Sampler {
109
112
[ SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE ] : sampleRate ,
110
113
} ;
111
114
112
- const method = `${ spanAttributes [ SEMATTRS_HTTP_METHOD ] } ` . toUpperCase ( ) ;
115
+ const method = `${ maybeSpanHttpMethod } ` . toUpperCase ( ) ;
113
116
if ( method === 'OPTIONS' || method === 'HEAD' ) {
114
117
DEBUG_BUILD && logger . log ( `[Tracing] Not sampling span because HTTP method is '${ method } ' for ${ spanName } ` ) ;
115
118
@@ -198,7 +201,9 @@ function getBaseTraceState(context: Context, spanAttributes: SpanAttributes): Tr
198
201
let traceState = parentContext ?. traceState || new TraceState ( ) ;
199
202
200
203
// We always keep the URL on the trace state, so we can access it in the propagator
201
- const url = spanAttributes [ SEMATTRS_HTTP_URL ] || spanAttributes [ SEMANTIC_ATTRIBUTE_URL_FULL ] ;
204
+ // `ATTR_URL_FULL` is the new attribute, but we still support the old one, `ATTR_HTTP_URL`, for now.
205
+ // eslint-disable-next-line deprecation/deprecation
206
+ const url = spanAttributes [ SEMATTRS_HTTP_URL ] || spanAttributes [ ATTR_URL_FULL ] ;
202
207
if ( url && typeof url === 'string' ) {
203
208
traceState = traceState . set ( SENTRY_TRACE_STATE_URL , url ) ;
204
209
}
0 commit comments