-
Notifications
You must be signed in to change notification settings - Fork 344
[SVLS-7168] Create inferred Span for GCP Push Subscriptions (including Cloud Events) #6320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: nina.rei/SVLS-7168/gcp-push-pubsub-plugin
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -120,13 +120,66 @@ class GoogleCloudPubsubTransitHandlerPlugin extends TracingPlugin { | |||||
const producerParent = this.tracer.extract('text_map', attrs) || null | ||||||
const effectiveParent = producerParent || undefined | ||||||
|
||||||
// ToDo: create pubsub.delivery; create HTTP span directly as child of producer | ||||||
// Compute pubsub scheduling duration (publish → HTTP receipt) | ||||||
const publishStartTimeRawForHttp = attrs['x-dd-publish-start-time'] | ||||||
let schedulingMs = null | ||||||
if (publishStartTimeRawForHttp) { | ||||||
const t0 = Number.parseInt(publishStartTimeRawForHttp, 10) | ||||||
if (Number.isFinite(t0) && t0 > 0) schedulingMs = Date.now() - t0 | ||||||
Comment on lines
+127
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks rather complicated. What values can we expect in such attribute? I guess we could potentially simplify it a tad :) The same applies below. |
||||||
} | ||||||
|
||||||
// Create pubsub.delivery span to represent infra delivery latency and parent the HTTP span | ||||||
let parentForHttp = effectiveParent | ||||||
const publishStartTimeRaw = attrs['x-dd-publish-start-time'] | ||||||
if (publishStartTimeRaw) { | ||||||
const publishStartTime = Number.parseInt(publishStartTimeRaw, 10) | ||||||
if (Number.isFinite(publishStartTime) && publishStartTime > 0) { | ||||||
const messageId = (message && message.messageId) || req.headers['ce-id'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const deliveryTags = { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think it's fine to use the shorter name. We always want to deliver tags :) |
||||||
component: 'google-cloud-pubsub', | ||||||
'span.kind': 'consumer', | ||||||
'span.type': 'pubsub', | ||||||
'gcloud.project_id': projectId, | ||||||
'pubsub.topic': topicName, | ||||||
'pubsub.subscription': subscription, | ||||||
'pubsub.message_id': messageId, | ||||||
'pubsub.delivery_method': isCloudEvent ? 'eventarc' : 'push', | ||||||
'pubsub.operation': 'delivery', | ||||||
'pubsub.scheduling_duration_ms': schedulingMs | ||||||
} | ||||||
// Add CloudEvents/Eventarc tags for CloudEvent requests | ||||||
if (isCloudEvent) { | ||||||
if (attrs['ce-source'] || req.headers['ce-source']) { | ||||||
deliveryTags['cloudevents.source'] = attrs['ce-source'] || req.headers['ce-source'] | ||||||
} | ||||||
if (attrs['ce-type'] || req.headers['ce-type']) { | ||||||
deliveryTags['cloudevents.type'] = attrs['ce-type'] || req.headers['ce-type'] | ||||||
} | ||||||
if (req.headers['ce-id']) deliveryTags['cloudevents.id'] = req.headers['ce-id'] | ||||||
if (req.headers['ce-specversion']) deliveryTags['cloudevents.specversion'] = req.headers['ce-specversion'] | ||||||
if (req.headers['ce-time']) deliveryTags['cloudevents.time'] = req.headers['ce-time'] | ||||||
deliveryTags['eventarc.trigger'] = 'pubsub' | ||||||
} | ||||||
const deliverySpan = this.tracer.startSpan('pubsub.delivery', { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I guess span would also be fine here? |
||||||
childOf: effectiveParent, | ||||||
service: this.tracer._service ? `${this.tracer._service}-pubsub-scheduling` : undefined, | ||||||
resource: `${topicName} → ${subscription}`, | ||||||
type: 'pubsub', | ||||||
tags: deliveryTags, | ||||||
startTime: publishStartTime | ||||||
}) | ||||||
const deliveryEnd = Date.now() | ||||||
try { deliverySpan.setTag('pubsub.delivery.duration_ms', deliveryEnd - publishStartTime) } catch {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It would be very bad if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the duration on the span not be sufficient here? |
||||||
deliverySpan.finish(deliveryEnd) | ||||||
parentForHttp = deliverySpan | ||||||
} | ||||||
} | ||||||
|
||||||
// Add parsed body for downstream middleware that expects it | ||||||
req.body = json | ||||||
// Create enhanced HTTP span as child of producer | ||||||
const httpSpan = this.tracer.startSpan('http.request', { | ||||||
childOf: effectiveParent, | ||||||
childOf: parentForHttp, | ||||||
tags: { | ||||||
'http.method': req.method, | ||||||
'http.url': `${req.headers['x-forwarded-proto'] || 'http'}://${req.headers.host}${req.url}`, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit