11import { opentelemetry } from '@traceloop/otel-proto' ;
2+ import { SemanticAttributes } from '@opentelemetry/semantic-conventions' ;
23import { setTimeout } from 'timers/promises' ;
34import { httpGetBinary } from '../utils' ;
45
5- const TRACELOOP_ID_REQUEST_HEADER = 'http.request.header.traceloop_id' ;
6- const TRACELOOP_ID_RESPONSE_HEADER = 'http.response.header.traceloop_id' ;
7-
86export interface FetchTracesConfig {
97 maxPollTime : number ;
108 pollInterval : number ;
@@ -22,7 +20,7 @@ export const fetchTracesConfigBase: FetchTracesConfig = {
2220} ;
2321
2422/**
25- * Searches in the traces for a trace with the given traceLoopId contained in the attribute http.request.header.trace_loop_id
23+ * Searches in the traces for a trace with the given traceLoopId contained in the attribute http.user_agent
2624 *
2725 * @param traces all traces from the otel receiver
2826 * @param traceLoopId traceLoopId to search for
@@ -37,11 +35,9 @@ export const findTraceLoopIdMatch = (
3735 for ( const span of scopeSpan . spans || [ ] ) {
3836 if ( span . attributes ) {
3937 for ( const attribute of span . attributes ) {
40- // http: check in headers stringified json
41- if ( attribute . key === 'http.request.headers' ) {
42- const matches = attribute . value ?. stringValue ?. match (
43- / " t r a c e l o o p _ i d " : " ( .* ) " / ,
44- ) ;
38+ if ( attribute . key === SemanticAttributes . HTTP_USER_AGENT ) {
39+ const matches =
40+ attribute . value ?. stringValue ?. match ( / t r a c e l o o p _ i d = ( .* ) / ) ;
4541 if ( matches ?. length > 1 ) {
4642 if ( matches [ 1 ] === traceLoopId ) {
4743 return span . traceId
@@ -50,21 +46,6 @@ export const findTraceLoopIdMatch = (
5046 }
5147 }
5248 }
53-
54- // check in specific header key
55- if (
56- attribute . key === TRACELOOP_ID_REQUEST_HEADER ||
57- attribute . key === TRACELOOP_ID_RESPONSE_HEADER
58- ) {
59- if (
60- attribute . value ?. arrayValue ?. values ?. [ 0 ] ?. stringValue ===
61- traceLoopId
62- ) {
63- return span . traceId
64- ? Buffer . from ( span . traceId ) . toString ( 'hex' )
65- : undefined ;
66- }
67- }
6849 }
6950 }
7051 }
0 commit comments