File tree 2 files changed +7
-10
lines changed
2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ export default {
26
26
27
27
const serviceBindingSpan = span . startSpan ( SPAN_NAME . SERVICE_FETCH , { attributes : { service : 'basic' } } ) ;
28
28
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
+ } ,
30
34
} ) ;
31
35
serviceBindingSpan . end ( ) ;
32
36
Original file line number Diff line number Diff line change @@ -9,21 +9,14 @@ export function createTrace(
9
9
tracerOptions : TracerOptions ,
10
10
spanOptions ?: SpanCreationOptions ,
11
11
) : 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
15
12
// This parent context will allow properly tracing across services (and other Workers)
16
13
let parentContext : SpanContext | undefined ;
14
+ // Allow passing SpanContext through the `cf` object for service bindings
17
15
if ( ( req . cf as CfWithTrace ) ?. traceContext ) {
18
16
parentContext = ( req . cf as CfWithTrace ) ?. traceContext ;
19
17
}
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
- }
26
18
19
+ // Read context from the spec-compliant ways
27
20
const exporter = tracerOptions . collector . exporter ?? new OtlpExporter ( ) ;
28
21
const context = exporter . readContextHeaders ( req . headers ) ;
29
22
if ( context !== null ) {
You can’t perform that action at this time.
0 commit comments