@@ -305,6 +305,7 @@ export class PubsubSpans {
305
305
params : AttributeParams ,
306
306
message ?: PubsubMessage ,
307
307
caller ?: string ,
308
+ operation ?: string ,
308
309
) : SpanAttributes {
309
310
const destinationName = params . topicName ?? params . subName ;
310
311
const destinationId = params . topicId ?? params . subId ;
@@ -351,6 +352,9 @@ export class PubsubSpans {
351
352
if ( message . ackId ) {
352
353
spanAttributes [ 'messaging.gcp_pubsub.message.ack_id' ] = message . ackId ;
353
354
}
355
+ if ( operation ) {
356
+ spanAttributes [ 'messaging.operation' ] = operation ;
357
+ }
354
358
}
355
359
356
360
return spanAttributes ;
@@ -368,11 +372,15 @@ export class PubsubSpans {
368
372
const topicInfo = getTopicInfo ( topicName ) ;
369
373
const span : Span = getTracer ( ) . startSpan ( `${ topicName } create` , {
370
374
kind : SpanKind . PRODUCER ,
371
- attributes : PubsubSpans . createAttributes ( topicInfo , message , caller ) ,
375
+ attributes : PubsubSpans . createAttributes (
376
+ topicInfo ,
377
+ message ,
378
+ caller ,
379
+ 'create' ,
380
+ ) ,
372
381
} ) ;
373
382
if ( topicInfo . topicId ) {
374
383
span . updateName ( `${ topicInfo . topicId } create` ) ;
375
- span . setAttribute ( 'messaging.operation' , 'create' ) ;
376
384
span . setAttribute ( 'messaging.destination.name' , topicInfo . topicId ) ;
377
385
}
378
386
@@ -404,10 +412,14 @@ export class PubsubSpans {
404
412
405
413
const subInfo = getSubscriptionInfo ( subName ) ;
406
414
const name = `${ subInfo . subId ?? subName } subscribe` ;
407
- const attributes = this . createAttributes ( subInfo , message , caller ) ;
415
+ const attributes = this . createAttributes (
416
+ subInfo ,
417
+ message ,
418
+ caller ,
419
+ 'receive' ,
420
+ ) ;
408
421
if ( subInfo . subId ) {
409
422
attributes [ 'messaging.destination.name' ] = subInfo . subId ;
410
- attributes [ 'messaging.operation' ] = 'receive' ;
411
423
}
412
424
413
425
if ( context ) {
@@ -473,6 +485,7 @@ export class PubsubSpans {
473
485
getTopicInfo ( topicName ) ,
474
486
undefined ,
475
487
caller ,
488
+ 'create' ,
476
489
) ;
477
490
const links : Link [ ] = messages
478
491
. filter ( m => m . parentSpan && isSampled ( m . parentSpan ) )
@@ -515,6 +528,7 @@ export class PubsubSpans {
515
528
subInfo ,
516
529
undefined ,
517
530
caller ,
531
+ 'receive' ,
518
532
) ;
519
533
const links : Link [ ] = messageSpans
520
534
. filter ( m => m && isSampled ( m ) )
@@ -531,7 +545,6 @@ export class PubsubSpans {
531
545
) ;
532
546
533
547
span ?. setAttribute ( 'messaging.batch.message_count' , messageSpans . length ) ;
534
- span ?. setAttribute ( 'messaging.operation' , 'receive' ) ;
535
548
536
549
if ( span ) {
537
550
// Also attempt to link from the subscribe span(s) back to the publish RPC span.
@@ -563,6 +576,7 @@ export class PubsubSpans {
563
576
subInfo ,
564
577
undefined ,
565
578
caller ,
579
+ 'receive' ,
566
580
) ;
567
581
const links : Link [ ] = messageSpans
568
582
. filter ( m => m && isSampled ( m ) )
@@ -579,7 +593,6 @@ export class PubsubSpans {
579
593
) ;
580
594
581
595
span ?. setAttribute ( 'messaging.batch.message_count' , messageSpans . length ) ;
582
- span ?. setAttribute ( 'messaging.operation' , 'receive' ) ;
583
596
584
597
if ( span ) {
585
598
// Also attempt to link from the subscribe span(s) back to the publish RPC span.
0 commit comments