@@ -14,6 +14,7 @@ import type {
1414import { createLogger } from '@sim/logger'
1515import { TraceAttr } from '@/lib/copilot/generated/trace-attributes-v1'
1616import { env } from './lib/core/config/env'
17+ import { parseOtlpHeaders } from './lib/monitoring/otlp'
1718
1819diag . setLogger ( new DiagConsoleLogger ( ) , DiagLogLevel . ERROR )
1920
@@ -47,29 +48,6 @@ function isBusinessSpan(spanName: string): boolean {
4748 return ALLOWED_SPAN_PREFIXES . some ( ( prefix ) => spanName . startsWith ( prefix ) )
4849}
4950
50- // Parse `OTEL_EXPORTER_OTLP_HEADERS`: `key1=value1,key2=value2`
51- // (URL-encoded values, whitespace tolerated).
52- function parseOtlpHeadersEnv ( raw : string ) : Record < string , string > {
53- const out : Record < string , string > = { }
54- if ( ! raw ) return out
55- for ( const part of raw . split ( ',' ) ) {
56- const trimmed = part . trim ( )
57- if ( ! trimmed ) continue
58- const eq = trimmed . indexOf ( '=' )
59- if ( eq <= 0 ) continue
60- const key = trimmed . slice ( 0 , eq ) . trim ( )
61- const rawVal = trimmed . slice ( eq + 1 ) . trim ( )
62- let val = rawVal
63- try {
64- val = decodeURIComponent ( rawVal )
65- } catch {
66- // value wasn't URL-encoded; keep as-is.
67- }
68- if ( key ) out [ key ] = val
69- }
70- return out
71- }
72-
7351// Append `/v1/traces` to the OTLP base URL unless already present.
7452// The HTTP exporter doesn't auto-suffix the signal path even though
7553// the spec says the env var is a base URL.
@@ -214,7 +192,7 @@ async function initializeOpenTelemetry() {
214192 } ,
215193 } )
216194
217- const otlpHeaders = parseOtlpHeadersEnv ( process . env . OTEL_EXPORTER_OTLP_HEADERS || '' )
195+ const otlpHeaders = parseOtlpHeaders ( process . env . OTEL_EXPORTER_OTLP_HEADERS || '' )
218196 const exporterUrl = normalizeOtlpTracesUrl ( telemetryConfig . endpoint )
219197
220198 const exporter = new OTLPTraceExporter ( {
0 commit comments