Skip to content

Commit

Permalink
fix: only include googclient_OpenTelemetrySpanContext-attribute
Browse files Browse the repository at this point in the history
when valid span context exists
  • Loading branch information
tapico-weyert committed Apr 6, 2021
1 parent 818013a commit 2cbaa28
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/publisher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {promisify, promisifyAll} from '@google-cloud/promisify';
import * as extend from 'extend';
import {CallOptions} from 'google-gax';
import {MessagingAttribute} from '@opentelemetry/semantic-conventions';
import {Span, SpanKind} from '@opentelemetry/api';
import {isSpanContextValid, Span, SpanKind} from '@opentelemetry/api';

import {BatchPublishOptions} from './message-batch';
import {Queue, OrderedQueue} from './message-queues';
Expand Down Expand Up @@ -278,7 +278,9 @@ export class Publisher {
SpanKind.PRODUCER,
spanAttributes
);
if (span) {

// If the span's context is valid we should pass the span context special attribute
if (isSpanContextValid(span.context())) {
if (
message.attributes &&
message.attributes['googclient_OpenTelemetrySpanContext']
Expand All @@ -290,6 +292,7 @@ export class Publisher {
if (!message.attributes) {
message.attributes = {};
}

message.attributes[
'googclient_OpenTelemetrySpanContext'
] = JSON.stringify(span.context());
Expand Down

0 comments on commit 2cbaa28

Please sign in to comment.