Skip to content

Commit 6256e86

Browse files
authored
[eventhub] - Move tracing spec to internal (Azure#21258)
### Packages impacted by this PR event-hubs ### Issues associated with this PR Fixes Azure#21226 ### Describe the problem that is addressed by this PR The tracing client test adds an internal reference; however, the test is still not excluded during min/max due to the nesting of the tracing reference. That will be fixed separately, but it also makes sense to make this an internal test as it tests the internals of how we trace.
1 parent fb5e582 commit 6256e86

File tree

2 files changed

+107
-40
lines changed

2 files changed

+107
-40
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { EnvVarKeys, getEnvVars } from "../../public/utils/testUtils";
5+
import { EnvironmentCredential, TokenCredential } from "@azure/identity";
6+
import { EventHubConsumerClient, EventHubProducerClient } from "../../../src";
7+
import { assert, should as shouldFn } from "@azure/test-utils";
8+
9+
import Sinon from "sinon";
10+
import { createMockServer } from "../../public/utils/mockService";
11+
import { testWithServiceTypes } from "../../public/utils/testWithServiceTypes";
12+
import { tracingClient } from "../../../src/diagnostics/tracing";
13+
14+
const should = shouldFn();
15+
16+
testWithServiceTypes((serviceVersion) => {
17+
const env = getEnvVars();
18+
if (serviceVersion === "mock") {
19+
let service: ReturnType<typeof createMockServer>;
20+
before("Starting mock service", () => {
21+
service = createMockServer();
22+
return service.start();
23+
});
24+
25+
after("Stopping mock service", async () => {
26+
await service?.stop();
27+
});
28+
}
29+
30+
describe("Create clients using Azure Identity (Internal)", function (): void {
31+
let endpoint: string;
32+
let credential: TokenCredential;
33+
let client: EventHubConsumerClient | EventHubProducerClient;
34+
35+
afterEach(async () => {
36+
// The client must always be closed, or MockHub will hang on shutdown.
37+
await client?.close();
38+
});
39+
40+
before("validate environment", function () {
41+
should.exist(
42+
env[EnvVarKeys.AZURE_CLIENT_ID],
43+
"define AZURE_CLIENT_ID in your environment before running integration tests."
44+
);
45+
should.exist(
46+
env[EnvVarKeys.AZURE_TENANT_ID],
47+
"define AZURE_TENANT_ID in your environment before running integration tests."
48+
);
49+
should.exist(
50+
env[EnvVarKeys.AZURE_CLIENT_SECRET],
51+
"define AZURE_CLIENT_SECRET in your environment before running integration tests."
52+
);
53+
should.exist(
54+
env[EnvVarKeys.EVENTHUB_CONNECTION_STRING],
55+
"define EVENTHUB_CONNECTION_STRING in your environment before running integration tests."
56+
);
57+
// This is of the form <your-namespace>.servicebus.windows.net
58+
endpoint = (env.EVENTHUB_CONNECTION_STRING.match("Endpoint=sb://(.*)/;") || "")[1];
59+
if (serviceVersion === "mock") {
60+
// Create a mock credential that implements the TokenCredential interface.
61+
credential = {
62+
getToken(_args) {
63+
return Promise.resolve({ token: "token", expiresOnTimestamp: Date.now() + 360000 });
64+
},
65+
};
66+
} else {
67+
credential = new EnvironmentCredential();
68+
}
69+
});
70+
71+
it("getEventHubProperties() creates a span with a peer.address attribute as the FQNS", async () => {
72+
client = new EventHubConsumerClient(
73+
EventHubConsumerClient.defaultConsumerGroupName,
74+
endpoint,
75+
env.EVENTHUB_NAME,
76+
credential
77+
);
78+
should.equal(client.fullyQualifiedNamespace, endpoint);
79+
80+
const withSpanStub = Sinon.spy(tracingClient, "withSpan");
81+
82+
// Ensure tracing is implemented correctly
83+
await assert.supportsTracing(
84+
(options) => client.getEventHubProperties(options),
85+
["ManagementClient.getEventHubProperties"]
86+
);
87+
88+
// Additional validation that we created the correct initial span options
89+
const expectedSpanOptions = {
90+
spanAttributes: {
91+
"peer.address": client.fullyQualifiedNamespace,
92+
"message_bus.destination": client.eventHubName,
93+
},
94+
};
95+
96+
assert.isTrue(
97+
withSpanStub.calledWith(
98+
Sinon.match.any,
99+
Sinon.match.any,
100+
Sinon.match.any,
101+
expectedSpanOptions
102+
)
103+
);
104+
});
105+
});
106+
});

sdk/eventhub/event-hubs/test/public/node/client.spec.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
import { EnvVarKeys, getEnvVars } from "../utils/testUtils";
55
import { EnvironmentCredential, TokenCredential } from "@azure/identity";
66
import { EventHubConsumerClient, EventHubProducerClient } from "../../../src";
7-
import { chai, assert, should as shouldFn } from "@azure/test-utils";
7+
import { chai, should as shouldFn } from "@azure/test-utils";
88
import chaiString from "chai-string";
99
import { createMockServer } from "../utils/mockService";
1010
import { testWithServiceTypes } from "../utils/testWithServiceTypes";
11-
import Sinon from "sinon";
12-
import { tracingClient } from "../../../src/diagnostics/tracing";
1311

1412
chai.use(chaiString);
1513
const should = shouldFn();
@@ -91,42 +89,5 @@ testWithServiceTypes((serviceVersion) => {
9189
const hubInfo = await client.getEventHubProperties();
9290
should.equal(hubInfo.name, client.eventHubName);
9391
});
94-
95-
describe("tracing", () => {
96-
it("getEventHubProperties() creates a span with a peer.address attribute as the FQNS", async () => {
97-
client = new EventHubConsumerClient(
98-
EventHubConsumerClient.defaultConsumerGroupName,
99-
endpoint,
100-
env.EVENTHUB_NAME,
101-
credential
102-
);
103-
should.equal(client.fullyQualifiedNamespace, endpoint);
104-
105-
const withSpanStub = Sinon.spy(tracingClient, "withSpan");
106-
107-
// Ensure tracing is implemented correctly
108-
await assert.supportsTracing(
109-
(options) => client.getEventHubProperties(options),
110-
["ManagementClient.getEventHubProperties"]
111-
);
112-
113-
// Additional validation that we created the correct initial span options
114-
const expectedSpanOptions = {
115-
spanAttributes: {
116-
"peer.address": client.fullyQualifiedNamespace,
117-
"message_bus.destination": client.eventHubName,
118-
},
119-
};
120-
121-
assert.isTrue(
122-
withSpanStub.calledWith(
123-
Sinon.match.any,
124-
Sinon.match.any,
125-
Sinon.match.any,
126-
expectedSpanOptions
127-
)
128-
);
129-
});
130-
});
13192
});
13293
});

0 commit comments

Comments
 (0)