@@ -36,6 +36,7 @@ import {
3636import * as assert from 'assert' ;
3737import { OracleInstrumentation } from '../src' ;
3838import { SpanNames } from '../src/constants' ;
39+ import { buildTraceparent } from '../src/OracleTelemetryTraceHandler' ;
3940
4041import {
4142 ATTR_DB_NAMESPACE ,
@@ -512,6 +513,7 @@ describe('oracledb', () => {
512513 instrumentation . setConfig ( {
513514 enhancedDatabaseReporting : false ,
514515 dbStatementDump : false ,
516+ traceContextPropagation : false ,
515517 } ) ;
516518 } ) ;
517519
@@ -963,6 +965,28 @@ describe('oracledb', () => {
963965 } ) ;
964966 } ) ;
965967
968+ it ( 'should propagate trace context via connection.action when enabled' , async ( ) => {
969+ instrumentation . setConfig ( { traceContextPropagation : true } ) ;
970+ const result = await connection . execute (
971+ "select sys_context('USERENV', 'ACTION') as action from dual" ,
972+ [ ] ,
973+ { outFormat : oracledb . OUT_FORMAT_OBJECT }
974+ ) ;
975+ const row = result . rows ?. [ 0 ] as Record < string , string > | undefined ;
976+ const actionValue = row ?. ACTION ;
977+ const spans = memoryExporter . getFinishedSpans ( ) ;
978+ const executeSpan = spans [ spans . length - 1 ] ;
979+ assert . ok ( executeSpan , 'expected span to verify trace propagation' ) ;
980+ assert . ok (
981+ executeSpan . name . startsWith ( SpanNames . EXECUTE ) ,
982+ `expected execute span, got ${ executeSpan . name } `
983+ ) ;
984+ const expectedTraceparent = buildTraceparent (
985+ executeSpan . spanContext ( )
986+ ) ;
987+ assert . strictEqual ( actionValue , expectedTraceparent ) ;
988+ } ) ;
989+
966990 it ( 'should intercept connection.execute(sql, values) bind-by-name' , async ( ) => {
967991 const span = tracer . startSpan ( 'test span' ) ;
968992 await context . with ( trace . setSpan ( context . active ( ) , span ) , async ( ) => {
0 commit comments