Skip to content

Commit 85702c8

Browse files
authored
[instrumentation] Fix snippets imports for named imports (#33891)
### Packages impacted by this PR - @azure/opentelemetry-instrumentation-azure-sdk ### Issues associated with this PR - #33880 ### Describe the problem that is addressed by this PR Fixes the snippets extraction by using explicit imports instead of default imports. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent 3767f22 commit 85702c8

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

sdk/instrumentation/opentelemetry-instrumentation-azure-sdk/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { registerInstrumentations } from "@opentelemetry/instrumentation";
4545
import { createAzureSdkInstrumentation } from "@azure/opentelemetry-instrumentation-azure-sdk";
4646
import { KeyClient } from "@azure/keyvault-keys";
4747
import { DefaultAzureCredential } from "@azure/identity";
48+
import { trace, context } from "@opentelemetry/api";
4849

4950
// Set-up and configure a Node Tracer Provider using OpenTelemetry SDK.
5051
const provider = new NodeTracerProvider();
@@ -67,9 +68,9 @@ await keyClient.getKey("MyKeyName");
6768
// If your scenario requires manual span propagation, all Azure client libraries
6869
// support explicitly passing a parent context via an `options` parameter.
6970
// Get a tracer from a registered provider, create a span, and get the current context.
70-
const tracer = opentelemetry.trace.getTracer("my-tracer");
71+
const tracer = trace.getTracer("my-tracer");
7172
const span = tracer.startSpan("main");
72-
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), span);
73+
const ctx = trace.setSpan(context.active(), span);
7374

7475
await keyClient.getKey("MyKeyName", {
7576
tracingOptions: {

sdk/instrumentation/opentelemetry-instrumentation-azure-sdk/test/snippets.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { describe, it } from "vitest";
55
import { registerInstrumentations } from "@opentelemetry/instrumentation";
66
import { createAzureSdkInstrumentation } from "@azure/opentelemetry-instrumentation-azure-sdk";
7-
import opentelemetry from "@opentelemetry/api";
7+
import { context, trace } from "@opentelemetry/api";
88
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
99
import { SimpleSpanProcessor, ConsoleSpanExporter } from "@opentelemetry/tracing";
1010
import { KeyClient } from "@azure/keyvault-keys";
@@ -35,9 +35,9 @@ describe("snippets", function () {
3535
// If your scenario requires manual span propagation, all Azure client libraries
3636
// support explicitly passing a parent context via an `options` parameter.
3737
// Get a tracer from a registered provider, create a span, and get the current context.
38-
const tracer = opentelemetry.trace.getTracer("my-tracer");
38+
const tracer = trace.getTracer("my-tracer");
3939
const span = tracer.startSpan("main");
40-
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), span);
40+
const ctx = trace.setSpan(context.active(), span);
4141
// @ts-preserve-whitespace
4242
await keyClient.getKey("MyKeyName", {
4343
tracingOptions: {

0 commit comments

Comments
 (0)