File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ export default {
2626
2727 const serviceBindingSpan = span . startSpan ( SPAN_NAME . SERVICE_FETCH , { attributes : { service : 'basic' } } ) ;
2828 const res = await env . SERVICE . fetch ( 'https://service/test' , {
29- headers : { 'x-trace-id' : `${ serviceBindingSpan . getContext ( ) . traceId } :${ serviceBindingSpan . getContext ( ) . spanId } ` } ,
29+ cf : {
30+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31+ // @ts -ignore
32+ spanContext : serviceBindingSpan . getContext ( ) ,
33+ } ,
3034 } ) ;
3135 serviceBindingSpan . end ( ) ;
3236
Original file line number Diff line number Diff line change @@ -9,21 +9,14 @@ export function createTrace(
99 tracerOptions : TracerOptions ,
1010 spanOptions ?: SpanCreationOptions ,
1111) : Trace {
12- // This is ugly
13- // TODO: Fix this - https://www.w3.org/TR/trace-context/#traceparent-header
14- // https://zipkin.io/pages/architecture.html - https://github.com/openzipkin/b3-propagation#overall-process
1512 // This parent context will allow properly tracing across services (and other Workers)
1613 let parentContext : SpanContext | undefined ;
14+ // Allow passing SpanContext through the `cf` object for service bindings
1715 if ( ( req . cf as CfWithTrace ) ?. traceContext ) {
1816 parentContext = ( req . cf as CfWithTrace ) ?. traceContext ;
1917 }
20- if ( req . headers . get ( 'x-trace-id' ) ) {
21- const ids = req . headers . get ( 'x-trace-id' ) ?. split ( ':' , 2 ) ;
22- if ( ids ?. length === 2 ) {
23- parentContext = { traceId : ids [ 0 ] , spanId : ids [ 1 ] } ;
24- }
25- }
2618
19+ // Read context from the spec-compliant ways
2720 const exporter = tracerOptions . collector . exporter ?? new OtlpExporter ( ) ;
2821 const context = exporter . readContextHeaders ( req . headers ) ;
2922 if ( context !== null ) {
You can’t perform that action at this time.
0 commit comments