11import type { Client , IntegrationFn , Scope , ScopeData , Span , SpanAttributes , SpanV2JSON } from '@sentry/core' ;
22import {
3- attributesFromObject ,
43 createSpanV2Envelope ,
54 debug ,
65 defineIntegration ,
76 getCapturedScopesOnSpan ,
87 getDynamicSamplingContextFromSpan ,
98 getGlobalScope ,
10- getRootSpan as getSegmentSpan ,
11- httpHeadersToSpanAttributes ,
9+ INTERNAL_getSegmentSpan ,
1210 isV2BeforeSendSpanCallback ,
1311 mergeScopeData ,
1412 reparentChildSpans ,
@@ -18,7 +16,6 @@ import {
1816 SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME ,
1917 SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION ,
2018 SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME ,
21- SEMANTIC_ATTRIBUTE_URL_FULL ,
2219 SEMANTIC_ATTRIBUTE_USER_EMAIL ,
2320 SEMANTIC_ATTRIBUTE_USER_ID ,
2421 SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS ,
@@ -28,7 +25,6 @@ import {
2825 spanToV2JSON ,
2926} from '@sentry/core' ;
3027import { DEBUG_BUILD } from '../debug-build' ;
31- import { getHttpRequestData } from '../helpers' ;
3228
3329export interface SpanStreamingOptions {
3430 batchLimit : number ;
@@ -110,7 +106,7 @@ interface SpanProcessingOptions {
110106 * Just the traceid alone isn't enough because there can be multiple span trees with the same traceid.
111107 */
112108function getSpanTreeMapKey ( span : Span ) : string {
113- return `${ span . spanContext ( ) . traceId } -${ getSegmentSpan ( span ) . spanContext ( ) . spanId } ` ;
109+ return `${ span . spanContext ( ) . traceId } -${ INTERNAL_getSegmentSpan ( span ) . spanContext ( ) . spanId } ` ;
114110}
115111
116112function processAndSendSpans (
@@ -132,10 +128,6 @@ function processAndSendSpans(
132128 applyCommonSpanAttributes ( span , segmentSpanJson , client ) ;
133129 }
134130
135- applyScopeToSegmentSpan ( segmentSpan , segmentSpanJson , client ) ;
136-
137- // TODO: Apply scope data and contexts to segment span
138-
139131 const { ignoreSpans } = client . getOptions ( ) ;
140132
141133 // 1. Check if the entire span tree is ignored by ignoreSpans
@@ -166,6 +158,7 @@ function processAndSendSpans(
166158 }
167159
168160 // 3. Apply beforeSendSpan callback
161+ // TODO: validate beforeSendSpan result/pass in a copy and merge afterwards
169162 const processedSpan = beforeSendSpan ? applyBeforeSendSpanCallback ( span , beforeSendSpan ) : span ;
170163 processedSpans . push ( processedSpan ) ;
171164 }
@@ -224,38 +217,6 @@ function applyCommonSpanAttributes(span: Span, serializedSegmentSpan: SpanV2JSON
224217 } ) ;
225218}
226219
227- /**
228- * Adds span attributes from the scopes' contexts
229- * TODO: It's not set in stone yet if we actually want to flatmap contexts into span attributes.
230- * For now we do it but not yet extra or tags. It's still TBD how to proceed here.
231- */
232- function applyScopeToSegmentSpan ( segmentSpan : Span , serializedSegmentSpan : SpanV2JSON , client : Client ) : void {
233- const { isolationScope, scope } = getCapturedScopesOnSpan ( segmentSpan ) ;
234- const finalScopeData = getFinalScopeData ( isolationScope , scope ) ;
235-
236- const browserRequestData = getHttpRequestData ( ) ;
237-
238- const tags = finalScopeData . tags ?? { } ;
239-
240- let contextAttributes = { } ;
241- Object . keys ( finalScopeData . contexts ) . forEach ( key => {
242- const context = finalScopeData . contexts [ key ] ;
243- if ( context ) {
244- contextAttributes = { ...contextAttributes , ...attributesFromObject ( context ) } ;
245- }
246- } ) ;
247-
248- const extraAttributes = attributesFromObject ( finalScopeData . extra ) ;
249-
250- setAttributesIfNotPresent ( segmentSpan , Object . keys ( serializedSegmentSpan . attributes ?? { } ) , {
251- [ SEMANTIC_ATTRIBUTE_URL_FULL ] : browserRequestData . url ,
252- ...httpHeadersToSpanAttributes ( browserRequestData . headers , client . getOptions ( ) . sendDefaultPii ?? false ) ,
253- ...tags ,
254- ...contextAttributes ,
255- ...extraAttributes ,
256- } ) ;
257- }
258-
259220function applyBeforeSendSpanCallback ( span : SpanV2JSON , beforeSendSpan : ( span : SpanV2JSON ) => SpanV2JSON ) : SpanV2JSON {
260221 const modifedSpan = beforeSendSpan ( span ) ;
261222 if ( ! modifedSpan ) {
0 commit comments