Skip to content

Commit

Permalink
[event-hubs] prevent invalid spans from instrumenting EventData (#16439)
Browse files Browse the repository at this point in the history
The live tests for event hubs currently have 3 test failures due to some changes introduced in core-tracing preview 13. The changes to core-tracing cause EventData to be instrumented (via Diagnostic-Id) with invalid span context data.

This change adds a check to ensure the span context is valid before instrumenting the EventData to be sent to the service.

Note: I didn't add a changelog entry because from a user's point of view, nothing has changed, since this issue did not exist in the previously released version of the event-hubs package.
  • Loading branch information
chradek authored and deyaaeldeen committed Jul 26, 2021
1 parent 08a4182 commit b20358b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { extractSpanContextFromTraceParentHeader, getTraceParentHeader } from "@azure/core-tracing";
import {
extractSpanContextFromTraceParentHeader,
getTraceParentHeader,
isSpanContextValid
} from "@azure/core-tracing";
import { Span, SpanContext } from "@azure/core-tracing";
import { AmqpAnnotatedMessage } from "@azure/core-amqp";
import { EventData, isAmqpAnnotatedMessage } from "../eventData";
Expand Down Expand Up @@ -40,7 +44,7 @@ export function instrumentEventData(
}

const traceParent = getTraceParentHeader(span.spanContext());
if (traceParent) {
if (traceParent && isSpanContextValid(span.spanContext())) {
copiedProps[TRACEPARENT_PROPERTY] = traceParent;
}

Expand Down

0 comments on commit b20358b

Please sign in to comment.