Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/telemetry-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,11 @@ export class PubsubSpans {
if (span) {
// Also attempt to link from message spans back to the publish RPC span.
messages.forEach(m => {
if (m.parentSpan && isSampled(m.parentSpan)) {
if (
m.parentSpan &&
isSampled(m.parentSpan) &&
typeof m.parentSpan?.addLink === 'function'
) {
m.parentSpan.addLink({context: span.spanContext()});
}
});
Expand Down Expand Up @@ -549,7 +553,7 @@ export class PubsubSpans {
if (span) {
// Also attempt to link from the subscribe span(s) back to the publish RPC span.
messageSpans.forEach(m => {
if (m && isSampled(m)) {
if (m && isSampled(m) && typeof m?.addLink === 'function') {
m.addLink({context: span.spanContext()});
}
});
Expand Down Expand Up @@ -597,7 +601,7 @@ export class PubsubSpans {
if (span) {
// Also attempt to link from the subscribe span(s) back to the publish RPC span.
messageSpans.forEach(m => {
if (m && isSampled(m)) {
if (m && isSampled(m) && typeof m?.addLink === 'function') {
m.addLink({context: span.spanContext()});
}
});
Expand Down
3 changes: 2 additions & 1 deletion test/telemetry-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ describe('OpenTelemetryTracer', () => {
topicName,
'test',
) as trace.Span;
const parentSpanLink = sinon.spy(span, 'addLink');
message.parentSpan = span;
span.end();

Expand All @@ -374,7 +375,6 @@ describe('OpenTelemetryTracer', () => {
topicName,
'test',
);

publishSpan?.end();
const spans = exporter.getFinishedSpans();
const publishReadSpan = spans.pop();
Expand All @@ -387,6 +387,7 @@ describe('OpenTelemetryTracer', () => {
);
assert.strictEqual(publishReadSpan.links.length, 1);
assert.strictEqual(childReadSpan.links.length, 1);
assert.strictEqual(parentSpanLink.callCount, 1);
});
});
});
Loading