Skip to content

Commit f7af73c

Browse files
committed
Add integrationName to fix _dd.integration tag in push subscription
Ensures pubsub.delivery spans are properly tagged with the correct integration name for test validation and proper categorization.
1 parent ea66657 commit f7af73c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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(/projects\/([^\\/]+)\/subscriptions/)

0 commit comments

Comments
 (0)