Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eventhub] - Move tracing spec to internal #21258

Merged
merged 3 commits into from
Apr 6, 2022
Merged
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
106 changes: 106 additions & 0 deletions sdk/eventhub/event-hubs/test/internal/node/client.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { EnvVarKeys, getEnvVars } from "../../public/utils/testUtils";
import { EnvironmentCredential, TokenCredential } from "@azure/identity";
import { EventHubConsumerClient, EventHubProducerClient } from "../../../src";
import { assert, should as shouldFn } from "@azure/test-utils";

import Sinon from "sinon";
import { createMockServer } from "../../public/utils/mockService";
import { testWithServiceTypes } from "../../public/utils/testWithServiceTypes";
import { tracingClient } from "../../../src/diagnostics/tracing";

const should = shouldFn();

testWithServiceTypes((serviceVersion) => {
const env = getEnvVars();
if (serviceVersion === "mock") {
let service: ReturnType<typeof createMockServer>;
before("Starting mock service", () => {
service = createMockServer();
return service.start();
});

after("Stopping mock service", async () => {
await service?.stop();
});
}

describe("Create clients using Azure Identity (Internal)", function (): void {
let endpoint: string;
let credential: TokenCredential;
let client: EventHubConsumerClient | EventHubProducerClient;

afterEach(async () => {
// The client must always be closed, or MockHub will hang on shutdown.
await client?.close();
});

before("validate environment", function () {
should.exist(
env[EnvVarKeys.AZURE_CLIENT_ID],
"define AZURE_CLIENT_ID in your environment before running integration tests."
);
should.exist(
env[EnvVarKeys.AZURE_TENANT_ID],
"define AZURE_TENANT_ID in your environment before running integration tests."
);
should.exist(
env[EnvVarKeys.AZURE_CLIENT_SECRET],
"define AZURE_CLIENT_SECRET in your environment before running integration tests."
);
should.exist(
env[EnvVarKeys.EVENTHUB_CONNECTION_STRING],
"define EVENTHUB_CONNECTION_STRING in your environment before running integration tests."
);
// This is of the form <your-namespace>.servicebus.windows.net
endpoint = (env.EVENTHUB_CONNECTION_STRING.match("Endpoint=sb://(.*)/;") || "")[1];
if (serviceVersion === "mock") {
// Create a mock credential that implements the TokenCredential interface.
credential = {
getToken(_args) {
return Promise.resolve({ token: "token", expiresOnTimestamp: Date.now() + 360000 });
},
};
} else {
credential = new EnvironmentCredential();
}
});

it("getEventHubProperties() creates a span with a peer.address attribute as the FQNS", async () => {
client = new EventHubConsumerClient(
EventHubConsumerClient.defaultConsumerGroupName,
endpoint,
env.EVENTHUB_NAME,
credential
);
should.equal(client.fullyQualifiedNamespace, endpoint);

const withSpanStub = Sinon.spy(tracingClient, "withSpan");

// Ensure tracing is implemented correctly
await assert.supportsTracing(
(options) => client.getEventHubProperties(options),
["ManagementClient.getEventHubProperties"]
);

// Additional validation that we created the correct initial span options
const expectedSpanOptions = {
spanAttributes: {
"peer.address": client.fullyQualifiedNamespace,
"message_bus.destination": client.eventHubName,
},
};

assert.isTrue(
withSpanStub.calledWith(
Sinon.match.any,
Sinon.match.any,
Sinon.match.any,
expectedSpanOptions
)
);
});
});
});
41 changes: 1 addition & 40 deletions sdk/eventhub/event-hubs/test/public/node/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import { EnvVarKeys, getEnvVars } from "../utils/testUtils";
import { EnvironmentCredential, TokenCredential } from "@azure/identity";
import { EventHubConsumerClient, EventHubProducerClient } from "../../../src";
import { chai, assert, should as shouldFn } from "@azure/test-utils";
import { chai, should as shouldFn } from "@azure/test-utils";
import chaiString from "chai-string";
import { createMockServer } from "../utils/mockService";
import { testWithServiceTypes } from "../utils/testWithServiceTypes";
import Sinon from "sinon";
import { tracingClient } from "../../../src/diagnostics/tracing";

chai.use(chaiString);
const should = shouldFn();
Expand Down Expand Up @@ -91,42 +89,5 @@ testWithServiceTypes((serviceVersion) => {
const hubInfo = await client.getEventHubProperties();
should.equal(hubInfo.name, client.eventHubName);
});

describe("tracing", () => {
it("getEventHubProperties() creates a span with a peer.address attribute as the FQNS", async () => {
client = new EventHubConsumerClient(
EventHubConsumerClient.defaultConsumerGroupName,
endpoint,
env.EVENTHUB_NAME,
credential
);
should.equal(client.fullyQualifiedNamespace, endpoint);

const withSpanStub = Sinon.spy(tracingClient, "withSpan");

// Ensure tracing is implemented correctly
await assert.supportsTracing(
(options) => client.getEventHubProperties(options),
["ManagementClient.getEventHubProperties"]
);

// Additional validation that we created the correct initial span options
const expectedSpanOptions = {
spanAttributes: {
"peer.address": client.fullyQualifiedNamespace,
"message_bus.destination": client.eventHubName,
},
};

assert.isTrue(
withSpanStub.calledWith(
Sinon.match.any,
Sinon.match.any,
Sinon.match.any,
expectedSpanOptions
)
);
});
});
});
});