@@ -18,12 +18,9 @@ import {
1818} from '../../semanticAttributes' ;
1919import type { RequestDataIncludeOptions } from '../../integrations/requestdata' ;
2020import type { Integration } from '../../types-hoist/integration' ;
21- import type { QueryParams , RequestEventData } from '../../types-hoist/request' ;
2221import type { SerializedStreamedSpan , Span , StreamedSpanJSON } from '../../types-hoist/span' ;
23- import { httpHeadersToSpanAttributes } from '../../utils/request' ;
2422import { getCombinedScopeData } from '../../utils/scopeData' ;
2523import { getSanitizedUrlString , parseUrl , stripUrlQueryAndFragment } from '../../utils/url' ;
26- import { getClientIPAddress , ipHeaderNames } from '../../vendor/getIpAddress' ;
2724import {
2825 INTERNAL_getSegmentSpan ,
2926 showSpanDropWarning ,
@@ -32,6 +29,7 @@ import {
3229} from '../../utils/spanUtils' ;
3330import { getCapturedScopesOnSpan } from '../utils' ;
3431import { isStreamedBeforeSendSpanCallback } from './beforeSendSpan' ;
32+ import { applyRequestDataToSegmentSpan } from './requestData' ;
3533
3634export type SerializedStreamedSpanWithSegmentSpan = SerializedStreamedSpan & {
3735 _segmentSpan : Span ;
@@ -115,92 +113,6 @@ function applyScopeToSegmentSpan(segmentSpanJSON: StreamedSpanJSON, scopeData: S
115113 }
116114}
117115
118- // Span-streaming counterpart of requestDataIntegration's processEvent.
119- function applyRequestDataToSegmentSpan (
120- segmentSpanJSON : StreamedSpanJSON ,
121- normalizedRequest : RequestEventData ,
122- ipAddress : string | undefined ,
123- include : RequestDataIncludeOptions ,
124- sendDefaultPii : boolean | undefined ,
125- ) : void {
126- const attributes : Record < string , unknown > = { } ;
127-
128- if ( include . url && normalizedRequest . url ) {
129- attributes [ 'url.full' ] = normalizedRequest . url ;
130- }
131-
132- if ( normalizedRequest . method ) {
133- attributes [ 'http.request.method' ] = normalizedRequest . method ;
134- }
135-
136- if ( include . query_string && normalizedRequest . query_string ) {
137- attributes [ 'url.query' ] = normalizeQueryString ( normalizedRequest . query_string ) ;
138- }
139-
140- safeSetSpanJSONAttributes ( segmentSpanJSON , attributes ) ;
141-
142- if ( include . headers && normalizedRequest . headers ) {
143- const headers = { ...normalizedRequest . headers } ;
144-
145- if ( ! include . cookies ) {
146- delete headers . cookie ;
147- }
148-
149- if ( ! include . ip ) {
150- const ipHeaderNamesLower = new Set ( ipHeaderNames . map ( name => name . toLowerCase ( ) ) ) ;
151- for ( const key of Object . keys ( headers ) ) {
152- if ( ipHeaderNamesLower . has ( key . toLowerCase ( ) ) ) {
153- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
154- delete headers [ key ] ;
155- }
156- }
157- }
158-
159- const headerAttributes = httpHeadersToSpanAttributes ( headers , sendDefaultPii ?? false , 'request' ) ;
160- safeSetSpanJSONAttributes ( segmentSpanJSON , headerAttributes ) ;
161- }
162-
163- if ( include . cookies && normalizedRequest . cookies ) {
164- const cookieString = Object . entries ( normalizedRequest . cookies )
165- . map ( ( [ name , value ] ) => `${ name } =${ value } ` )
166- . join ( '; ' ) ;
167- if ( cookieString ) {
168- const cookieAttributes = httpHeadersToSpanAttributes (
169- { cookie : cookieString } ,
170- sendDefaultPii ?? false ,
171- 'request' ,
172- ) ;
173- safeSetSpanJSONAttributes ( segmentSpanJSON , cookieAttributes ) ;
174- }
175- }
176-
177- if ( include . data && normalizedRequest . data != null ) {
178- const serialized =
179- typeof normalizedRequest . data === 'string' ? normalizedRequest . data : JSON . stringify ( normalizedRequest . data ) ;
180- if ( serialized ) {
181- safeSetSpanJSONAttributes ( segmentSpanJSON , { 'http.request.body.data' : serialized } ) ;
182- }
183- }
184-
185- if ( include . ip ) {
186- const ip = ( normalizedRequest . headers && getClientIPAddress ( normalizedRequest . headers ) ) || ipAddress || undefined ;
187- if ( ip ) {
188- safeSetSpanJSONAttributes ( segmentSpanJSON , { [ SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS ] : ip } ) ;
189- }
190- }
191- }
192-
193- function normalizeQueryString ( queryString : QueryParams ) : string | undefined {
194- if ( typeof queryString === 'string' ) {
195- return queryString || undefined ;
196- }
197-
198- const pairs = Array . isArray ( queryString ) ? queryString : Object . entries ( queryString ) ;
199- const result = pairs . map ( ( [ key , value ] ) => `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( value ) } ` ) . join ( '&' ) ;
200-
201- return result || undefined ;
202- }
203-
204116function applyCommonSpanAttributes (
205117 spanJSON : StreamedSpanJSON ,
206118 serializedSegmentSpan : StreamedSpanJSON ,
0 commit comments