@@ -71,11 +71,14 @@ class GoogleCloudPubsubPushSubscriptionPlugin extends TracingPlugin {
7171 }
7272
7373 _createDeliverySpan ( messageData , parentContext , tracer ) {
74- const { message, subscription, topicName } = messageData
74+ const { message, subscription, topicName, attrs } = messageData
7575 const subscriptionName = subscription . split ( '/' ) . pop ( ) || subscription
76+ const publishStartTime = attrs [ 'x-dd-publish-start-time' ]
77+ const startTime = publishStartTime ? Number . parseInt ( publishStartTime , 10 ) : undefined
7678
7779 const span = tracer . _tracer . startSpan ( 'pubsub.delivery' , {
7880 childOf : parentContext ,
81+ startTime,
7982 integrationName : 'google-cloud-pubsub' ,
8083 tags : {
8184 'span.kind' : 'consumer' ,
@@ -93,10 +96,35 @@ class GoogleCloudPubsubPushSubscriptionPlugin extends TracingPlugin {
9396 } )
9497
9598 span . setTag ( 'resource.name' , `Push Subscription ${ subscriptionName } ` )
99+ this . _addBatchMetadata ( span , attrs )
96100
97101 return span
98102 }
99103
104+ _addBatchMetadata ( span , attrs ) {
105+ const batchSize = attrs [ '_dd.batch.size' ]
106+ const batchIndex = attrs [ '_dd.batch.index' ]
107+
108+ if ( batchSize && batchIndex !== undefined ) {
109+ const size = Number . parseInt ( batchSize , 10 )
110+ const index = Number . parseInt ( batchIndex , 10 )
111+
112+ span . setTag ( 'pubsub.batch.message_count' , size )
113+ span . setTag ( 'pubsub.batch.message_index' , index )
114+ span . setTag ( 'pubsub.batch.description' , `Message ${ index + 1 } of ${ size } ` )
115+
116+ const requestTraceId = attrs [ '_dd.pubsub_request.trace_id' ]
117+ const requestSpanId = attrs [ '_dd.pubsub_request.span_id' ]
118+
119+ if ( requestTraceId ) {
120+ span . setTag ( 'pubsub.batch.request_trace_id' , requestTraceId )
121+ }
122+ if ( requestSpanId ) {
123+ span . setTag ( 'pubsub.batch.request_span_id' , requestSpanId )
124+ }
125+ }
126+ }
127+
100128 _extractProjectTopic ( attrs , subscription ) {
101129 const topicName = attrs [ 'pubsub.topic' ]
102130 const projectId = subscription . match ( / p r o j e c t s \/ ( [ ^ \\ / ] + ) \/ s u b s c r i p t i o n s / )
0 commit comments