@@ -22,11 +22,13 @@ test('Sends an HTTP transaction', async ({ baseURL }) => {
2222 ) ;
2323} ) ;
2424
25- // Trace context does not propagate over NestJS TCP transport.
26- // The manual span created inside the microservice handler is orphaned, not a child of the HTTP transaction.
27- // This test documents this gap — if trace propagation is ever fixed, test.fail() will alert us.
28- test . fail ( 'Microservice spans are captured as children of the HTTP transaction' , async ( { baseURL } ) => {
29- const transactionEventPromise = waitForTransaction ( 'nestjs-microservices' , transactionEvent => {
25+ // Trace context does not propagate over NestJS TCP transport, so RPC spans are disconnected from
26+ // the HTTP transaction. Instead of appearing as child spans of the HTTP transaction, auto-instrumented
27+ // NestJS guard/interceptor/pipe spans become separate standalone transactions.
28+ // This documents the current (broken) behavior — ideally these should be connected to the HTTP trace.
29+
30+ test ( 'Microservice spans are not connected to the HTTP transaction' , async ( { baseURL } ) => {
31+ const httpTransactionPromise = waitForTransaction ( 'nestjs-microservices' , transactionEvent => {
3032 return (
3133 transactionEvent ?. contexts ?. trace ?. op === 'http.server' &&
3234 transactionEvent ?. transaction === 'GET /test-microservice-sum'
@@ -36,19 +38,49 @@ test.fail('Microservice spans are captured as children of the HTTP transaction',
3638 const response = await fetch ( `${ baseURL } /test-microservice-sum` ) ;
3739 expect ( response . status ) . toBe ( 200 ) ;
3840
39- const body = await response . json ( ) ;
40- expect ( body . result ) . toBe ( 6 ) ;
41+ const httpTransaction = await httpTransactionPromise ;
4142
42- const transactionEvent = await transactionEventPromise ;
43+ // The microservice span should be part of this transaction but isn't due to missing trace propagation
44+ const microserviceSpan = httpTransaction . spans ?. find ( span => span . description === 'microservice-sum-operation' ) ;
45+ expect ( microserviceSpan ) . toBeUndefined ( ) ;
46+ } ) ;
4347
44- expect ( transactionEvent . contexts ?. trace ) . toEqual (
45- expect . objectContaining ( {
46- op : 'http.server' ,
47- status : 'ok' ,
48- } ) ,
49- ) ;
48+ test ( 'Microservice guard is emitted as a standalone transaction instead of being part of the HTTP trace' , async ( {
49+ baseURL,
50+ } ) => {
51+ const guardTransactionPromise = waitForTransaction ( 'nestjs-microservices' , transactionEvent => {
52+ return transactionEvent ?. transaction === 'ExampleGuard' ;
53+ } ) ;
54+
55+ await fetch ( `${ baseURL } /test-microservice-guard` ) ;
5056
51- const microserviceSpan = transactionEvent . spans ?. find ( span => span . description === 'microservice-sum-operation' ) ;
52- expect ( microserviceSpan ) . toBeDefined ( ) ;
53- expect ( microserviceSpan . trace_id ) . toBe ( transactionEvent . contexts ?. trace ?. trace_id ) ;
57+ const guardTransaction = await guardTransactionPromise ;
58+ expect ( guardTransaction ) . toBeDefined ( ) ;
5459} ) ;
60+
61+ test ( 'Microservice interceptor is emitted as a standalone transaction instead of being part of the HTTP trace' , async ( {
62+ baseURL,
63+ } ) => {
64+ const interceptorTransactionPromise = waitForTransaction ( 'nestjs-microservices' , transactionEvent => {
65+ return transactionEvent ?. transaction === 'ExampleInterceptor' ;
66+ } ) ;
67+
68+ await fetch ( `${ baseURL } /test-microservice-interceptor` ) ;
69+
70+ const interceptorTransaction = await interceptorTransactionPromise ;
71+ expect ( interceptorTransaction ) . toBeDefined ( ) ;
72+ } ) ;
73+
74+ test ( 'Microservice pipe is emitted as a standalone transaction instead of being part of the HTTP trace' , async ( {
75+ baseURL,
76+ } ) => {
77+ const pipeTransactionPromise = waitForTransaction ( 'nestjs-microservices' , transactionEvent => {
78+ return transactionEvent ?. transaction === 'ExamplePipe' ;
79+ } ) ;
80+
81+ await fetch ( `${ baseURL } /test-microservice-pipe` ) ;
82+
83+ const pipeTransaction = await pipeTransactionPromise ;
84+ expect ( pipeTransaction ) . toBeDefined ( ) ;
85+ } ) ;
86+
0 commit comments