forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[instrumentation] - Add integration tests (Azure#20462)
### Packages impacted by this PR @azure/opentelemetry-instrumentation-azure-sdk ### Issues associated with this PR Resolves Azure#18738 ### Describe the problem that is addressed by this PR This PR solves the following: 1. I would like to have an end-to-end test that uses our pipeline and ensures tracing works as expected. The idea here is to ensure we do not regress in the future when making core changes. I added a node-only integration test that uses core-rest-pipeline and a fake client. 1. We currently maintain a TestTracer, TestTracerProvider, and TestSpan independently in multiple places. OpenTelemetry already provides testing utils in their base package. I replaced our Test* objects with an InMemorySpanExporter which allows us to grab all exported spans and inspect them. 1. In-passing, I realized that for a bit there could be a drift between client packages that use the new naming conventions and core packages that use the old naming conventions to pull az.namespace into a span. While it doesn't feel appropriate to add compatibility code in our core packages, this package will be in beta for quite some time so I think it's fine to add it here temporarily.
- Loading branch information
Showing
14 changed files
with
286 additions
and
427 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
53 changes: 53 additions & 0 deletions
53
...tation/opentelemetry-instrumentation-azure-sdk/test/internal/node/instrumentation.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,53 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { SpanKind, SpanStatusCode } from "@opentelemetry/api"; | ||
import { TestClient, tracingClientAttributes } from "../../public/util/testClient"; | ||
|
||
import { assert } from "chai"; | ||
import { inMemoryExporter } from "../../public/util/setup"; | ||
|
||
describe("instrumentation end-to-end tests", () => { | ||
beforeEach(() => { | ||
inMemoryExporter.reset(); | ||
}); | ||
|
||
// This is node-only since we use the BasicTracerProvider in the browser | ||
// which does not set up a context manager. Altenatively we can always pull in | ||
// @opentelemetry/sdk-trace-web but it did not feel necessary at this time. | ||
describe("with a configured client", () => { | ||
it("works when using withSpan", async () => { | ||
await new TestClient().exampleOperation(); | ||
const spans = inMemoryExporter.getFinishedSpans(); | ||
assert.lengthOf(spans, 3); | ||
const [coreRestPipeline, inner, outer] = spans; | ||
|
||
// Check parenting chain | ||
assert.equal(coreRestPipeline.parentSpanId, inner.spanContext().spanId); | ||
assert.equal(inner.parentSpanId, outer.spanContext().spanId); | ||
assert.notExists(outer.parentSpanId); | ||
|
||
// Check default span kind | ||
assert.equal(outer.kind, SpanKind.INTERNAL); | ||
|
||
// Check specified span kind | ||
assert.equal(inner.kind, SpanKind.CLIENT); | ||
|
||
// Check status | ||
assert.deepEqual(coreRestPipeline.status, { code: SpanStatusCode.OK }); | ||
assert.deepEqual(inner.status, { code: SpanStatusCode.OK }); | ||
assert.deepEqual(outer.status, { code: SpanStatusCode.OK }); | ||
|
||
// Check instrumentationLibrary | ||
assert.deepEqual(outer.instrumentationLibrary, { | ||
name: tracingClientAttributes.packageName, | ||
version: tracingClientAttributes.packageVersion, | ||
}); | ||
|
||
// Check attributes on all spans | ||
assert.equal(coreRestPipeline.attributes["az.namespace"], tracingClientAttributes.namespace); | ||
assert.equal(inner.attributes["az.namespace"], tracingClientAttributes.namespace); | ||
assert.equal(outer.attributes["az.namespace"], tracingClientAttributes.namespace); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.