From 4a3ded9789c9e00c1d9909237e376d42d5779e0a Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Tue, 25 Mar 2025 09:38:41 -0700 Subject: [PATCH 1/2] Add required messaging.operation span attrs for OTel sem convs 1.31 --- src/telemetry-tracing.ts | 11 +++++++++-- test/pubsub.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/telemetry-tracing.ts b/src/telemetry-tracing.ts index b921518ab..a8ea35afb 100644 --- a/src/telemetry-tracing.ts +++ b/src/telemetry-tracing.ts @@ -347,7 +347,7 @@ export class PubsubSpans { const spanAttributes = { // Add Opentelemetry semantic convention attributes to the span, based on: - // https://github.com/open-telemetry/opentelemetry-specification/blob/v1.1.0/specification/trace/semantic_conventions/messaging.md + // https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#messaging-attributes ['messaging.system']: 'gcp_pubsub', ['messaging.destination.name']: destinationId ?? destinationName, ['gcp.project_id']: projectId, @@ -396,6 +396,8 @@ export class PubsubSpans { }); if (topicInfo.topicId) { span.updateName(`${topicInfo.topicId} create`); + span.setAttribute('messaging.operation.name', 'send'); + span.setAttribute('messaging.operation.type', 'create'); span.setAttribute('messaging.destination.name', topicInfo.topicId); } @@ -430,6 +432,7 @@ export class PubsubSpans { const attributes = this.createAttributes(subInfo, message, caller); if (subInfo.subId) { attributes['messaging.destination.name'] = subInfo.subId; + attributes['messaging.operation.type'] = 'receive'; } if (context) { @@ -553,6 +556,7 @@ export class PubsubSpans { ); span?.setAttribute('messaging.batch.message_count', messageSpans.length); + span?.setAttribute('messaging.operation.type', 'receive'); if (span) { // Also attempt to link from the subscribe span(s) back to the publish RPC span. @@ -600,6 +604,7 @@ export class PubsubSpans { ); span?.setAttribute('messaging.batch.message_count', messageSpans.length); + span?.setAttribute('messaging.operation.type', 'receive'); if (span) { // Also attempt to link from the subscribe span(s) back to the publish RPC span. @@ -651,7 +656,9 @@ export class PubsubSpans { } static setReceiveProcessResult(span: Span, isAck: boolean) { - span.setAttribute('messaging.gcp_pubsub.result', isAck ? 'ack' : 'nack'); + const op_name = isAck ? 'ack' : 'nack'; + span?.setAttribute('messaging.gcp_pubsub.result', op_name); + span?.setAttribute('messaging.operation.name', op_name); } } diff --git a/test/pubsub.ts b/test/pubsub.ts index d4ceef18b..71efbef8e 100644 --- a/test/pubsub.ts +++ b/test/pubsub.ts @@ -689,7 +689,7 @@ describe('PubSub', () => { const apiResponse = { name: 'new-topic', }; - let requestStub: sinon.SinonStub; + let requestStub: sinon.SinonStub; beforeEach(() => { requestStub = sandbox From a2154528614b8a7079ebe7768b1d986c567f2f26 Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Wed, 26 Mar 2025 08:30:50 -0700 Subject: [PATCH 2/2] fix: Use 1.24 instead of 1.31 as it's not stable --- src/telemetry-tracing.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/telemetry-tracing.ts b/src/telemetry-tracing.ts index a8ea35afb..422b2d904 100644 --- a/src/telemetry-tracing.ts +++ b/src/telemetry-tracing.ts @@ -347,7 +347,7 @@ export class PubsubSpans { const spanAttributes = { // Add Opentelemetry semantic convention attributes to the span, based on: - // https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#messaging-attributes + // https://github.com/open-telemetry/semantic-conventions/blob/v1.24.0/docs/messaging/messaging-spans.md ['messaging.system']: 'gcp_pubsub', ['messaging.destination.name']: destinationId ?? destinationName, ['gcp.project_id']: projectId, @@ -396,8 +396,7 @@ export class PubsubSpans { }); if (topicInfo.topicId) { span.updateName(`${topicInfo.topicId} create`); - span.setAttribute('messaging.operation.name', 'send'); - span.setAttribute('messaging.operation.type', 'create'); + span.setAttribute('messaging.operation', 'create'); span.setAttribute('messaging.destination.name', topicInfo.topicId); } @@ -432,7 +431,7 @@ export class PubsubSpans { const attributes = this.createAttributes(subInfo, message, caller); if (subInfo.subId) { attributes['messaging.destination.name'] = subInfo.subId; - attributes['messaging.operation.type'] = 'receive'; + attributes['messaging.operation'] = 'receive'; } if (context) { @@ -556,7 +555,7 @@ export class PubsubSpans { ); span?.setAttribute('messaging.batch.message_count', messageSpans.length); - span?.setAttribute('messaging.operation.type', 'receive'); + span?.setAttribute('messaging.operation', 'receive'); if (span) { // Also attempt to link from the subscribe span(s) back to the publish RPC span. @@ -604,7 +603,7 @@ export class PubsubSpans { ); span?.setAttribute('messaging.batch.message_count', messageSpans.length); - span?.setAttribute('messaging.operation.type', 'receive'); + span?.setAttribute('messaging.operation', 'receive'); if (span) { // Also attempt to link from the subscribe span(s) back to the publish RPC span. @@ -656,9 +655,7 @@ export class PubsubSpans { } static setReceiveProcessResult(span: Span, isAck: boolean) { - const op_name = isAck ? 'ack' : 'nack'; - span?.setAttribute('messaging.gcp_pubsub.result', op_name); - span?.setAttribute('messaging.operation.name', op_name); + span?.setAttribute('messaging.gcp_pubsub.result', isAck ? 'ack' : 'nack'); } }