-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EventHubs][DistributedTracing] add destination and peer.address attr…
…ibutes (#10389)
- Loading branch information
Showing
5 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
sdk/eventhub/event-hubs/test/diagnostics/messageSpan.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import chai from "chai"; | ||
import { createMessageSpan } from "../../src/diagnostics/messageSpan"; | ||
import { TraceFlags, SpanContext } from "@opentelemetry/api"; | ||
import { TestTracer, setTracer, getTracer } from "@azure/core-tracing"; | ||
import { EventHubConnectionConfig } from '@azure/core-amqp'; | ||
|
||
const should = chai.should(); | ||
const assert = chai.assert; | ||
|
||
describe("#createMessageSpan()", () => { | ||
const origTracer = getTracer(); | ||
|
||
before(() => { | ||
setTracer(new TestTracer()); | ||
}); | ||
|
||
after(() => { | ||
setTracer(origTracer); | ||
}); | ||
|
||
const mockSpanContext: SpanContext = { | ||
traceId: "d4cda95b652f4a1592b449d5929fda1b", | ||
spanId: "6e0c63257de34c92", | ||
traceFlags: TraceFlags.SAMPLED | ||
}; | ||
const mockEventHubConnectionConfig: Pick<EventHubConnectionConfig, "entityPath" | "host"> = { | ||
entityPath: "entity", | ||
host: "foo.example.com" | ||
}; | ||
|
||
it("should create a span without a parent", () => { | ||
const span = createMessageSpan(); | ||
|
||
should.exist(span); | ||
should.exist(span.context().spanId); | ||
should.exist(span.context().traceId); | ||
|
||
should.equal((span as any).name, "Azure.EventHubs.message"); | ||
assert.deepStrictEqual((span as any).attributes, { | ||
"az.namespace": "Microsoft.EventHub" | ||
}); | ||
|
||
span.end(); | ||
}); | ||
|
||
it("should create a span with a parent", () => { | ||
const span = createMessageSpan(mockSpanContext); | ||
|
||
should.exist(span); | ||
should.equal(span.context().traceId, mockSpanContext.traceId); | ||
should.exist(span.context().spanId); | ||
should.not.equal(span.context().spanId, mockSpanContext.spanId); | ||
|
||
should.equal((span as any).name, "Azure.EventHubs.message"); | ||
assert.deepStrictEqual((span as any).attributes, { | ||
"az.namespace": "Microsoft.EventHub" | ||
}); | ||
|
||
span.end(); | ||
}); | ||
|
||
it("should create a span with an eventHubConfig", () => { | ||
const span = createMessageSpan(mockSpanContext, mockEventHubConnectionConfig); | ||
|
||
should.exist(span); | ||
should.equal(span.context().traceId, mockSpanContext.traceId); | ||
should.exist(span.context().spanId); | ||
should.not.equal(span.context().spanId, mockSpanContext.spanId); | ||
|
||
should.equal((span as any).name, "Azure.EventHubs.message"); | ||
assert.deepStrictEqual((span as any).attributes, { | ||
"az.namespace": "Microsoft.EventHub", | ||
"message_bus.destination": mockEventHubConnectionConfig.entityPath, | ||
"peer.address": mockEventHubConnectionConfig.host | ||
}); | ||
|
||
span.end(); | ||
}); | ||
}); |