@@ -117,6 +117,7 @@ function ensureInitialContextManagerSet() {
117117 context . setGlobalContextManager ( contextManager ) ;
118118 }
119119}
120+ export { ensureInitialContextManagerSet } ;
120121
121122const debugTraces = process . env . SPANNER_DEBUG_TRACES === 'true' ;
122123
@@ -138,14 +139,19 @@ export function startTrace<T>(
138139 config = { } as traceConfig ;
139140 }
140141
141- ensureInitialContextManagerSet ( ) ;
142+ const tracer = getTracer ( config . opts ?. tracerProvider ) ;
143+ let parentSpanId : string | undefined ;
144+ if ( debugTraces ) {
145+ const parentSpan = trace . getActiveSpan ( ) ;
146+ parentSpanId = parentSpan ?. spanContext ( ) ! . spanId ;
147+ }
142148
143- return getTracer ( config . opts ?. tracerProvider ) . startActiveSpan (
149+ return tracer . startActiveSpan (
144150 SPAN_NAMESPACE_PREFIX + '.' + spanNameSuffix ,
145151 { kind : SpanKind . CLIENT } ,
146152 span => {
147153 if ( debugTraces ) {
148- patchSpanEndForDebugging ( span , spanNameSuffix ) ;
154+ patchSpanEndForDebugging ( span , spanNameSuffix , parentSpanId ) ;
149155 }
150156
151157 span . setAttribute ( SEMATTRS_DB_SYSTEM , 'spanner' ) ;
@@ -305,10 +311,19 @@ class noopSpan implements Span {
305311 }
306312}
307313
308- function patchSpanEndForDebugging ( span : Span , spanNameSuffix : string ) {
314+ function patchSpanEndForDebugging (
315+ span : Span ,
316+ spanNameSuffix : string ,
317+ parentSpanId : string | undefined
318+ ) {
319+ console . trace (
320+ `\x1b[33m${ spanNameSuffix } .start id=${ span . spanContext ( ) . spanId } with parentSpanId: ${ parentSpanId } \x1b[00m`
321+ ) ;
309322 const origSpanEnd = span . end ;
310323 const wrapSpanEnd = function ( this : Span ) {
311- console . trace ( `\x1b[35m${ spanNameSuffix } .end()\x1b[00m` ) ;
324+ console . trace (
325+ `\x1b[35m${ spanNameSuffix } .end() id=${ span . spanContext ( ) . spanId } with parentSpanId: ${ parentSpanId } \x1b[00m`
326+ ) ;
312327 return origSpanEnd . apply ( this ) ;
313328 } ;
314329 Object . defineProperty ( span , 'end' , {
0 commit comments