@azure/opentelemetry-instrumentation-azure-sdk 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -5
- package/dist/index.js +49 -9
- package/dist/index.js.map +1 -1
- package/dist-esm/src/configuration.js +31 -0
- package/dist-esm/src/configuration.js.map +1 -0
- package/dist-esm/src/instrumentation.browser.js +2 -2
- package/dist-esm/src/instrumentation.browser.js.map +1 -1
- package/dist-esm/src/instrumentation.js +2 -2
- package/dist-esm/src/instrumentation.js.map +1 -1
- package/dist-esm/src/instrumenter.js +20 -6
- package/dist-esm/src/instrumenter.js.map +1 -1
- package/package.json +22 -25
- package/types/3.1/opentelemetry-instrumentation-azure-sdk.d.ts +1 -1
- package/types/latest/opentelemetry-instrumentation-azure-sdk.d.ts +1 -1
- package/types/latest/tsdoc-metadata.json +1 -1
- package/CHANGELOG.md +0 -5
- package/dist-esm/src/constants.js +0 -4
- package/dist-esm/src/constants.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### Currently supported environments
|
|
6
6
|
|
|
7
|
-
- [LTS versions of Node.js](https://
|
|
7
|
+
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
|
|
8
8
|
- Latest versions of Safari, Chrome, Edge, and Firefox.
|
|
9
9
|
|
|
10
10
|
See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
|
|
@@ -42,8 +42,14 @@ To use this client library in the browser, first you need to use a bundler. For
|
|
|
42
42
|
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
|
|
43
43
|
const { createAzureSdkInstrumentation } = require("@azure/opentelemetry-instrumentation-azure-sdk");
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
|
|
45
|
+
// Set-up and configure a Node Tracer Provider using OpenTelemetry
|
|
46
|
+
const opentelemetry = require("@opentelemetry/api");
|
|
47
|
+
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
|
|
48
|
+
const { SimpleSpanProcessor, ConsoleSpanExporter } = require("@opentelemetry/tracing");
|
|
49
|
+
|
|
50
|
+
const provider = new NodeTracerProvider();
|
|
51
|
+
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
|
|
52
|
+
provider.register();
|
|
47
53
|
|
|
48
54
|
registerInstrumentations({
|
|
49
55
|
instrumentations: [createAzureSdkInstrumentation()],
|
|
@@ -53,7 +59,24 @@ registerInstrumentations({
|
|
|
53
59
|
|
|
54
60
|
const { keyClient } = require("@azure/keyvault-keys");
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
async function main() {
|
|
63
|
+
// Tracing is now enabled using automatic span propagation with an active context.
|
|
64
|
+
await keyClient.getKey("MyKeyName");
|
|
65
|
+
|
|
66
|
+
// If your scenario requires manual span propagation, all Azure client libraries
|
|
67
|
+
// support explicitly passing a parent context via an `options` parameter.
|
|
68
|
+
// Get a tracer from a registered provider, create a span, and get the current context.
|
|
69
|
+
const tracer = opentelemetry.trace.getTracer("my-tracer");
|
|
70
|
+
const span = tracer.startSpan("main");
|
|
71
|
+
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), span);
|
|
72
|
+
|
|
73
|
+
await keyClient.getKey("MyKeyName", {
|
|
74
|
+
tracingOptions: {
|
|
75
|
+
// ctx will be used as the parent context for all operations.
|
|
76
|
+
tracingContext: ctx,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
57
80
|
```
|
|
58
81
|
|
|
59
82
|
## Troubleshooting
|
|
@@ -63,7 +86,7 @@ const { keyClient } = require("@azure/keyvault-keys");
|
|
|
63
86
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
64
87
|
|
|
65
88
|
```javascript
|
|
66
|
-
|
|
89
|
+
const { setLogLevel } = require("@azure/logger");
|
|
67
90
|
|
|
68
91
|
setLogLevel("info");
|
|
69
92
|
```
|
package/dist/index.js
CHANGED
|
@@ -57,6 +57,37 @@ class OpenTelemetrySpanWrapper {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// Copyright (c) Microsoft Corporation.
|
|
61
|
+
// Licensed under the MIT license.
|
|
62
|
+
const SDK_VERSION = "1.0.0-beta.3";
|
|
63
|
+
/**
|
|
64
|
+
* @internal
|
|
65
|
+
*
|
|
66
|
+
* Cached values of environment variables that were fetched.
|
|
67
|
+
*/
|
|
68
|
+
const environmentCache = new Map();
|
|
69
|
+
/**
|
|
70
|
+
* Converts an environment variable to Boolean.
|
|
71
|
+
* the strings "false" and "0" are treated as falsy values.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
function envVarToBoolean(key) {
|
|
76
|
+
var _a;
|
|
77
|
+
if (!environmentCache.has(key)) {
|
|
78
|
+
loadEnvironmentVariable(key);
|
|
79
|
+
}
|
|
80
|
+
const value = ((_a = environmentCache.get(key)) !== null && _a !== void 0 ? _a : "").toLowerCase();
|
|
81
|
+
return value !== "false" && value !== "0" && Boolean(value);
|
|
82
|
+
}
|
|
83
|
+
function loadEnvironmentVariable(key) {
|
|
84
|
+
var _a;
|
|
85
|
+
if (typeof process !== "undefined" && process.env) {
|
|
86
|
+
const rawValue = (_a = process.env[key]) !== null && _a !== void 0 ? _a : process.env[key.toLowerCase()];
|
|
87
|
+
environmentCache.set(key, rawValue);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
60
91
|
// Copyright (c) Microsoft Corporation.
|
|
61
92
|
/**
|
|
62
93
|
* Converts our TracingSpanKind to the corresponding OpenTelemetry SpanKind.
|
|
@@ -126,10 +157,23 @@ function toSpanOptions(spanOptions) {
|
|
|
126
157
|
const propagator = new core.W3CTraceContextPropagator();
|
|
127
158
|
class OpenTelemetryInstrumenter {
|
|
128
159
|
startSpan(name, spanOptions) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
160
|
+
let ctx = (spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.tracingContext) || api.context.active();
|
|
161
|
+
let span;
|
|
162
|
+
if (envVarToBoolean("AZURE_TRACING_DISABLED")) {
|
|
163
|
+
// disable only our spans but not any downstream spans
|
|
164
|
+
span = api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Create our span
|
|
168
|
+
span = api.trace
|
|
169
|
+
.getTracer(spanOptions.packageName, spanOptions.packageVersion)
|
|
170
|
+
.startSpan(name, toSpanOptions(spanOptions), ctx);
|
|
171
|
+
if (envVarToBoolean("AZURE_HTTP_TRACING_CHILDREN_DISABLED") &&
|
|
172
|
+
name.toUpperCase().startsWith("HTTP")) {
|
|
173
|
+
// disable downstream spans
|
|
174
|
+
ctx = core.suppressTracing(ctx);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
133
177
|
return {
|
|
134
178
|
span: new OpenTelemetrySpanWrapper(span),
|
|
135
179
|
tracingContext: api.trace.setSpan(ctx, span),
|
|
@@ -149,10 +193,6 @@ class OpenTelemetryInstrumenter {
|
|
|
149
193
|
}
|
|
150
194
|
}
|
|
151
195
|
|
|
152
|
-
// Copyright (c) Microsoft Corporation.
|
|
153
|
-
// Licensed under the MIT license.
|
|
154
|
-
const SDK_VERSION = "1.0.0-beta.1";
|
|
155
|
-
|
|
156
196
|
// Copyright (c) Microsoft Corporation.
|
|
157
197
|
/**
|
|
158
198
|
* The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
|
|
@@ -181,7 +221,7 @@ class AzureSdkInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
181
221
|
/**
|
|
182
222
|
* Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
|
|
183
223
|
*
|
|
184
|
-
* When
|
|
224
|
+
* When registered, any Azure data plane package will begin emitting tracing spans for internal calls
|
|
185
225
|
* as well as network calls
|
|
186
226
|
*
|
|
187
227
|
* Example usage:
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/logger.ts","../src/spanWrapper.ts","../src/transformations.ts","../src/instrumenter.ts","../src/constants.ts","../src/instrumentation.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The \\@azure/logger configuration for this package.\n */\nexport const logger = createClientLogger(\"opentelemetry-instrumentation-azure-sdk\");\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Span, SpanAttributeValue, SpanStatusCode } from \"@opentelemetry/api\";\nimport { SpanStatus, TracingSpan } from \"@azure/core-tracing\";\n\nexport class OpenTelemetrySpanWrapper implements TracingSpan {\n private _span: Span;\n\n constructor(span: Span) {\n this._span = span;\n }\n\n setStatus(status: SpanStatus): void {\n if (status.status === \"error\") {\n if (status.error) {\n this._span.setStatus({ code: SpanStatusCode.ERROR, message: status.error.toString() });\n this.recordException(status.error);\n } else {\n this._span.setStatus({ code: SpanStatusCode.ERROR });\n }\n } else if (status.status === \"success\") {\n this._span.setStatus({ code: SpanStatusCode.OK });\n }\n }\n\n setAttribute(name: string, value: unknown): void {\n if (value !== null && value !== undefined) {\n this._span.setAttribute(name, value as SpanAttributeValue);\n }\n }\n\n end(): void {\n this._span.end();\n }\n\n recordException(exception: string | Error): void {\n this._span.recordException(exception);\n }\n\n isRecording(): boolean {\n return this._span.isRecording();\n }\n\n /**\n * Allows getting the wrapped span as needed.\n * @internal\n *\n * @returns The underlying span\n */\n unwrap(): Span {\n return this._span;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { InstrumenterSpanOptions, TracingSpanKind, TracingSpanLink } from \"@azure/core-tracing\";\nimport {\n Link,\n SpanAttributeValue,\n SpanAttributes,\n SpanKind,\n SpanOptions,\n trace,\n} from \"@opentelemetry/api\";\n\n/**\n * Converts our TracingSpanKind to the corresponding OpenTelemetry SpanKind.\n *\n * By default it will return {@link SpanKind.INTERNAL}\n * @param tracingSpanKind - The core tracing {@link TracingSpanKind}\n * @returns - The OpenTelemetry {@link SpanKind}\n */\nexport function toOpenTelemetrySpanKind<K extends TracingSpanKind>(\n tracingSpanKind?: K\n): SpanKindMapping[K] {\n const key = (tracingSpanKind || \"internal\").toUpperCase() as keyof typeof SpanKind;\n return SpanKind[key] as SpanKindMapping[K];\n}\n\n/**\n * A mapping between our {@link TracingSpanKind} union type and OpenTelemetry's {@link SpanKind}.\n */\ntype SpanKindMapping = {\n client: SpanKind.CLIENT;\n server: SpanKind.SERVER;\n producer: SpanKind.PRODUCER;\n consumer: SpanKind.CONSUMER;\n internal: SpanKind.INTERNAL;\n};\n\n/**\n * Converts core-tracing's TracingSpanLink to OpenTelemetry's Link\n *\n * @param spanLinks - The core tracing {@link TracingSpanLink} to convert\n * @returns A set of {@link Link}s\n */\nfunction toOpenTelemetryLinks(spanLinks: TracingSpanLink[] = []): Link[] {\n return spanLinks.reduce((acc, tracingSpanLink) => {\n const spanContext = trace.getSpanContext(tracingSpanLink.tracingContext);\n if (spanContext) {\n acc.push({\n context: spanContext,\n attributes: toOpenTelemetrySpanAttributes(tracingSpanLink.attributes),\n });\n }\n return acc;\n }, [] as Link[]);\n}\n\n/**\n * Converts core-tracing's span attributes to OpenTelemetry attributes.\n *\n * @param spanAttributes - The set of attributes to convert.\n * @returns An {@link SpanAttributes} to set on a span.\n */\nfunction toOpenTelemetrySpanAttributes(\n spanAttributes: { [key: string]: unknown } | undefined\n): SpanAttributes {\n const attributes: ReturnType<typeof toOpenTelemetrySpanAttributes> = {};\n for (const key in spanAttributes) {\n // Any non-nullish value is allowed.\n if (spanAttributes[key] !== null && spanAttributes[key] !== undefined) {\n attributes[key] = spanAttributes[key] as SpanAttributeValue;\n }\n }\n return attributes;\n}\n\n/**\n * Converts core-tracing span options to OpenTelemetry options.\n *\n * @param spanOptions - The {@link InstrumenterSpanOptions} to convert.\n * @returns An OpenTelemetry {@link SpanOptions} that can be used when creating a span.\n */\nexport function toSpanOptions(spanOptions?: InstrumenterSpanOptions): SpanOptions {\n const { spanAttributes, spanLinks, spanKind } = spanOptions || {};\n\n const attributes: SpanAttributes = toOpenTelemetrySpanAttributes(spanAttributes);\n const kind = toOpenTelemetrySpanKind(spanKind);\n const links = toOpenTelemetryLinks(spanLinks);\n\n return {\n attributes,\n kind,\n links,\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n Instrumenter,\n InstrumenterSpanOptions,\n TracingContext,\n TracingSpan,\n} from \"@azure/core-tracing\";\nimport { context, defaultTextMapGetter, defaultTextMapSetter, trace } from \"@opentelemetry/api\";\n\nimport { OpenTelemetrySpanWrapper } from \"./spanWrapper\";\nimport { W3CTraceContextPropagator } from \"@opentelemetry/core\";\nimport { toSpanOptions } from \"./transformations\";\n\n// While default propagation is user-configurable, Azure services always use the W3C implementation.\nexport const propagator = new W3CTraceContextPropagator();\n\nexport class OpenTelemetryInstrumenter implements Instrumenter {\n startSpan(\n name: string,\n spanOptions: InstrumenterSpanOptions\n ): { span: TracingSpan; tracingContext: TracingContext } {\n const span = trace\n .getTracer(spanOptions.packageName, spanOptions.packageVersion)\n .startSpan(name, toSpanOptions(spanOptions));\n\n const ctx = spanOptions?.tracingContext || context.active();\n\n return {\n span: new OpenTelemetrySpanWrapper(span),\n tracingContext: trace.setSpan(ctx, span),\n };\n }\n withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n tracingContext: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback> {\n return context.with(\n tracingContext,\n callback,\n /** Assume caller will bind `this` or use arrow functions */ undefined,\n ...callbackArgs\n );\n }\n\n parseTraceparentHeader(traceparentHeader: string): TracingContext {\n return propagator.extract(\n context.active(),\n { traceparent: traceparentHeader },\n defaultTextMapGetter\n );\n }\n\n createRequestHeaders(tracingContext?: TracingContext): Record<string, string> {\n const headers: Record<string, string> = {};\n propagator.inject(tracingContext || context.active(), headers, defaultTextMapSetter);\n return headers;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const SDK_VERSION: string = \"1.0.0-beta.1\";\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as coreTracing from \"@azure/core-tracing\";\nimport {\n Instrumentation,\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from \"@opentelemetry/instrumentation\";\nimport { OpenTelemetryInstrumenter } from \"./instrumenter\";\nimport { SDK_VERSION } from \"./constants\";\n\n/**\n * Configuration options that can be passed to {@link createAzureSdkInstrumentation} function.\n */\nexport interface AzureSdkInstrumentationOptions extends InstrumentationConfig {}\n\n/**\n * The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.\n */\nclass AzureSdkInstrumentation extends InstrumentationBase {\n constructor(options: AzureSdkInstrumentationOptions = {}) {\n super(\n \"@azure/opentelemetry-instrumentation-azure-sdk\",\n SDK_VERSION,\n Object.assign({}, options)\n );\n }\n /**\n * Entrypoint for the module registration.\n *\n * @returns The patched \\@azure/core-tracing module after setting its instrumenter.\n */\n protected init():\n | void\n | InstrumentationModuleDefinition<typeof coreTracing>\n | InstrumentationModuleDefinition<typeof coreTracing>[] {\n const result: InstrumentationModuleDefinition<typeof coreTracing> =\n new InstrumentationNodeModuleDefinition(\n \"@azure/core-tracing\",\n [\"^1.0.0-preview.14\", \"^1.0.0\"],\n (moduleExports) => {\n if (typeof moduleExports.useInstrumenter === \"function\") {\n moduleExports.useInstrumenter(new OpenTelemetryInstrumenter());\n }\n\n return moduleExports;\n }\n );\n // Needed to support 1.0.0-preview.14\n result.includePrerelease = true;\n return result;\n }\n}\n\n/**\n * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.\n *\n * When registerd, any Azure data plane package will begin emitting tracing spans for internal calls\n * as well as network calls\n *\n * Example usage:\n * ```ts\n * const openTelemetryInstrumentation = require(\"@opentelemetry/instrumentation\");\n * openTelemetryInstrumentation.registerInstrumentations({\n * instrumentations: [createAzureSdkInstrumentation()],\n * })\n * ```\n *\n * @remarks\n *\n * As OpenTelemetry instrumentations rely on patching required modules, you should register\n * this instrumentation as early as possible and before loading any Azure Client Libraries.\n */\nexport function createAzureSdkInstrumentation(\n options: AzureSdkInstrumentationOptions = {}\n): Instrumentation {\n return new AzureSdkInstrumentation(options);\n}\n"],"names":["createClientLogger","SpanStatusCode","SpanKind","trace","W3CTraceContextPropagator","context","defaultTextMapGetter","defaultTextMapSetter","InstrumentationBase","InstrumentationNodeModuleDefinition"],"mappings":";;;;;;;;;AAAA;AAKA;;;MAGa,MAAM,GAAGA,2BAAkB,CAAC,yCAAyC;;ACRlF;MAMa,wBAAwB;IAGnC,YAAY,IAAU;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;KACnB;IAED,SAAS,CAAC,MAAkB;QAC1B,IAAI,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE;YAC7B,IAAI,MAAM,CAAC,KAAK,EAAE;gBAChB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAEC,kBAAc,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBACvF,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACpC;iBAAM;gBACL,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAEA,kBAAc,CAAC,KAAK,EAAE,CAAC,CAAC;aACtD;SACF;aAAM,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;YACtC,IAAI,CAAC,K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/logger.ts","../src/spanWrapper.ts","../src/configuration.ts","../src/transformations.ts","../src/instrumenter.ts","../src/instrumentation.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The \\@azure/logger configuration for this package.\n */\nexport const logger = createClientLogger(\"opentelemetry-instrumentation-azure-sdk\");\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Span, SpanAttributeValue, SpanStatusCode } from \"@opentelemetry/api\";\nimport { SpanStatus, TracingSpan } from \"@azure/core-tracing\";\n\nexport class OpenTelemetrySpanWrapper implements TracingSpan {\n private _span: Span;\n\n constructor(span: Span) {\n this._span = span;\n }\n\n setStatus(status: SpanStatus): void {\n if (status.status === \"error\") {\n if (status.error) {\n this._span.setStatus({ code: SpanStatusCode.ERROR, message: status.error.toString() });\n this.recordException(status.error);\n } else {\n this._span.setStatus({ code: SpanStatusCode.ERROR });\n }\n } else if (status.status === \"success\") {\n this._span.setStatus({ code: SpanStatusCode.OK });\n }\n }\n\n setAttribute(name: string, value: unknown): void {\n if (value !== null && value !== undefined) {\n this._span.setAttribute(name, value as SpanAttributeValue);\n }\n }\n\n end(): void {\n this._span.end();\n }\n\n recordException(exception: string | Error): void {\n this._span.recordException(exception);\n }\n\n isRecording(): boolean {\n return this._span.isRecording();\n }\n\n /**\n * Allows getting the wrapped span as needed.\n * @internal\n *\n * @returns The underlying span\n */\n unwrap(): Span {\n return this._span;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const SDK_VERSION: string = \"1.0.0-beta.3\";\n\n/**\n * @internal\n *\n * Keys of known environment variables we look up.\n */\nexport type KnownEnvironmentKey = \"AZURE_HTTP_TRACING_CHILDREN_DISABLED\" | \"AZURE_TRACING_DISABLED\";\n\n/**\n * @internal\n *\n * Cached values of environment variables that were fetched.\n */\nexport const environmentCache = new Map<KnownEnvironmentKey, string | undefined>();\n\n/**\n * Converts an environment variable to Boolean.\n * the strings \"false\" and \"0\" are treated as falsy values.\n *\n * @internal\n */\nexport function envVarToBoolean(key: KnownEnvironmentKey): boolean {\n if (!environmentCache.has(key)) {\n loadEnvironmentVariable(key);\n }\n const value = (environmentCache.get(key) ?? \"\").toLowerCase();\n return value !== \"false\" && value !== \"0\" && Boolean(value);\n}\n\nfunction loadEnvironmentVariable(key: KnownEnvironmentKey): void {\n if (typeof process !== \"undefined\" && process.env) {\n const rawValue = process.env[key] ?? process.env[key.toLowerCase()];\n environmentCache.set(key, rawValue);\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { InstrumenterSpanOptions, TracingSpanKind, TracingSpanLink } from \"@azure/core-tracing\";\nimport {\n Link,\n SpanAttributeValue,\n SpanAttributes,\n SpanKind,\n SpanOptions,\n trace,\n} from \"@opentelemetry/api\";\n\n/**\n * Converts our TracingSpanKind to the corresponding OpenTelemetry SpanKind.\n *\n * By default it will return {@link SpanKind.INTERNAL}\n * @param tracingSpanKind - The core tracing {@link TracingSpanKind}\n * @returns - The OpenTelemetry {@link SpanKind}\n */\nexport function toOpenTelemetrySpanKind<K extends TracingSpanKind>(\n tracingSpanKind?: K\n): SpanKindMapping[K] {\n const key = (tracingSpanKind || \"internal\").toUpperCase() as keyof typeof SpanKind;\n return SpanKind[key] as SpanKindMapping[K];\n}\n\n/**\n * A mapping between our {@link TracingSpanKind} union type and OpenTelemetry's {@link SpanKind}.\n */\ntype SpanKindMapping = {\n client: SpanKind.CLIENT;\n server: SpanKind.SERVER;\n producer: SpanKind.PRODUCER;\n consumer: SpanKind.CONSUMER;\n internal: SpanKind.INTERNAL;\n};\n\n/**\n * Converts core-tracing's TracingSpanLink to OpenTelemetry's Link\n *\n * @param spanLinks - The core tracing {@link TracingSpanLink} to convert\n * @returns A set of {@link Link}s\n */\nfunction toOpenTelemetryLinks(spanLinks: TracingSpanLink[] = []): Link[] {\n return spanLinks.reduce((acc, tracingSpanLink) => {\n const spanContext = trace.getSpanContext(tracingSpanLink.tracingContext);\n if (spanContext) {\n acc.push({\n context: spanContext,\n attributes: toOpenTelemetrySpanAttributes(tracingSpanLink.attributes),\n });\n }\n return acc;\n }, [] as Link[]);\n}\n\n/**\n * Converts core-tracing's span attributes to OpenTelemetry attributes.\n *\n * @param spanAttributes - The set of attributes to convert.\n * @returns An {@link SpanAttributes} to set on a span.\n */\nfunction toOpenTelemetrySpanAttributes(\n spanAttributes: { [key: string]: unknown } | undefined\n): SpanAttributes {\n const attributes: ReturnType<typeof toOpenTelemetrySpanAttributes> = {};\n for (const key in spanAttributes) {\n // Any non-nullish value is allowed.\n if (spanAttributes[key] !== null && spanAttributes[key] !== undefined) {\n attributes[key] = spanAttributes[key] as SpanAttributeValue;\n }\n }\n return attributes;\n}\n\n/**\n * Converts core-tracing span options to OpenTelemetry options.\n *\n * @param spanOptions - The {@link InstrumenterSpanOptions} to convert.\n * @returns An OpenTelemetry {@link SpanOptions} that can be used when creating a span.\n */\nexport function toSpanOptions(spanOptions?: InstrumenterSpanOptions): SpanOptions {\n const { spanAttributes, spanLinks, spanKind } = spanOptions || {};\n\n const attributes: SpanAttributes = toOpenTelemetrySpanAttributes(spanAttributes);\n const kind = toOpenTelemetrySpanKind(spanKind);\n const links = toOpenTelemetryLinks(spanLinks);\n\n return {\n attributes,\n kind,\n links,\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n INVALID_SPAN_CONTEXT,\n Span,\n context,\n defaultTextMapGetter,\n defaultTextMapSetter,\n trace,\n} from \"@opentelemetry/api\";\nimport {\n Instrumenter,\n InstrumenterSpanOptions,\n TracingContext,\n TracingSpan,\n} from \"@azure/core-tracing\";\nimport { W3CTraceContextPropagator, suppressTracing } from \"@opentelemetry/core\";\n\nimport { OpenTelemetrySpanWrapper } from \"./spanWrapper\";\nimport { envVarToBoolean } from \"./configuration\";\nimport { toSpanOptions } from \"./transformations\";\n\n// While default propagation is user-configurable, Azure services always use the W3C implementation.\nexport const propagator = new W3CTraceContextPropagator();\n\nexport class OpenTelemetryInstrumenter implements Instrumenter {\n startSpan(\n name: string,\n spanOptions: InstrumenterSpanOptions\n ): { span: TracingSpan; tracingContext: TracingContext } {\n let ctx = spanOptions?.tracingContext || context.active();\n let span: Span;\n\n if (envVarToBoolean(\"AZURE_TRACING_DISABLED\")) {\n // disable only our spans but not any downstream spans\n span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);\n } else {\n // Create our span\n span = trace\n .getTracer(spanOptions.packageName, spanOptions.packageVersion)\n .startSpan(name, toSpanOptions(spanOptions), ctx);\n\n if (\n envVarToBoolean(\"AZURE_HTTP_TRACING_CHILDREN_DISABLED\") &&\n name.toUpperCase().startsWith(\"HTTP\")\n ) {\n // disable downstream spans\n ctx = suppressTracing(ctx);\n }\n }\n\n return {\n span: new OpenTelemetrySpanWrapper(span),\n tracingContext: trace.setSpan(ctx, span),\n };\n }\n withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n tracingContext: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback> {\n return context.with(\n tracingContext,\n callback,\n /** Assume caller will bind `this` or use arrow functions */ undefined,\n ...callbackArgs\n );\n }\n\n parseTraceparentHeader(traceparentHeader: string): TracingContext {\n return propagator.extract(\n context.active(),\n { traceparent: traceparentHeader },\n defaultTextMapGetter\n );\n }\n\n createRequestHeaders(tracingContext?: TracingContext): Record<string, string> {\n const headers: Record<string, string> = {};\n propagator.inject(tracingContext || context.active(), headers, defaultTextMapSetter);\n return headers;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as coreTracing from \"@azure/core-tracing\";\nimport {\n Instrumentation,\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from \"@opentelemetry/instrumentation\";\nimport { OpenTelemetryInstrumenter } from \"./instrumenter\";\nimport { SDK_VERSION } from \"./configuration\";\n\n/**\n * Configuration options that can be passed to {@link createAzureSdkInstrumentation} function.\n */\nexport interface AzureSdkInstrumentationOptions extends InstrumentationConfig {}\n\n/**\n * The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.\n */\nclass AzureSdkInstrumentation extends InstrumentationBase {\n constructor(options: AzureSdkInstrumentationOptions = {}) {\n super(\n \"@azure/opentelemetry-instrumentation-azure-sdk\",\n SDK_VERSION,\n Object.assign({}, options)\n );\n }\n /**\n * Entrypoint for the module registration.\n *\n * @returns The patched \\@azure/core-tracing module after setting its instrumenter.\n */\n protected init():\n | void\n | InstrumentationModuleDefinition<typeof coreTracing>\n | InstrumentationModuleDefinition<typeof coreTracing>[] {\n const result: InstrumentationModuleDefinition<typeof coreTracing> =\n new InstrumentationNodeModuleDefinition(\n \"@azure/core-tracing\",\n [\"^1.0.0-preview.14\", \"^1.0.0\"],\n (moduleExports) => {\n if (typeof moduleExports.useInstrumenter === \"function\") {\n moduleExports.useInstrumenter(new OpenTelemetryInstrumenter());\n }\n\n return moduleExports;\n }\n );\n // Needed to support 1.0.0-preview.14\n result.includePrerelease = true;\n return result;\n }\n}\n\n/**\n * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.\n *\n * When registered, any Azure data plane package will begin emitting tracing spans for internal calls\n * as well as network calls\n *\n * Example usage:\n * ```ts\n * const openTelemetryInstrumentation = require(\"@opentelemetry/instrumentation\");\n * openTelemetryInstrumentation.registerInstrumentations({\n * instrumentations: [createAzureSdkInstrumentation()],\n * })\n * ```\n *\n * @remarks\n *\n * As OpenTelemetry instrumentations rely on patching required modules, you should register\n * this instrumentation as early as possible and before loading any Azure Client Libraries.\n */\nexport function createAzureSdkInstrumentation(\n options: AzureSdkInstrumentationOptions = {}\n): Instrumentation {\n return new AzureSdkInstrumentation(options);\n}\n"],"names":["createClientLogger","SpanStatusCode","SpanKind","trace","W3CTraceContextPropagator","context","INVALID_SPAN_CONTEX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A,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C;;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
export const SDK_VERSION = "1.0.0-beta.3";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* Cached values of environment variables that were fetched.
|
|
8
|
+
*/
|
|
9
|
+
export const environmentCache = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Converts an environment variable to Boolean.
|
|
12
|
+
* the strings "false" and "0" are treated as falsy values.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export function envVarToBoolean(key) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (!environmentCache.has(key)) {
|
|
19
|
+
loadEnvironmentVariable(key);
|
|
20
|
+
}
|
|
21
|
+
const value = ((_a = environmentCache.get(key)) !== null && _a !== void 0 ? _a : "").toLowerCase();
|
|
22
|
+
return value !== "false" && value !== "0" && Boolean(value);
|
|
23
|
+
}
|
|
24
|
+
function loadEnvironmentVariable(key) {
|
|
25
|
+
var _a;
|
|
26
|
+
if (typeof process !== "undefined" && process.env) {
|
|
27
|
+
const rawValue = (_a = process.env[key]) !== null && _a !== void 0 ? _a : process.env[key.toLowerCase()];
|
|
28
|
+
environmentCache.set(key, rawValue);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../src/configuration.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,cAAc,CAAC;AASlD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA2C,CAAC;AAEnF;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAwB;;IACtD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QAC9B,uBAAuB,CAAC,GAAG,CAAC,CAAC;KAC9B;IACD,MAAM,KAAK,GAAG,CAAC,MAAA,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9D,OAAO,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,uBAAuB,CAAC,GAAwB;;IACvD,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE;QACjD,MAAM,QAAQ,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,mCAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QACpE,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;KACrC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const SDK_VERSION: string = \"1.0.0-beta.3\";\n\n/**\n * @internal\n *\n * Keys of known environment variables we look up.\n */\nexport type KnownEnvironmentKey = \"AZURE_HTTP_TRACING_CHILDREN_DISABLED\" | \"AZURE_TRACING_DISABLED\";\n\n/**\n * @internal\n *\n * Cached values of environment variables that were fetched.\n */\nexport const environmentCache = new Map<KnownEnvironmentKey, string | undefined>();\n\n/**\n * Converts an environment variable to Boolean.\n * the strings \"false\" and \"0\" are treated as falsy values.\n *\n * @internal\n */\nexport function envVarToBoolean(key: KnownEnvironmentKey): boolean {\n if (!environmentCache.has(key)) {\n loadEnvironmentVariable(key);\n }\n const value = (environmentCache.get(key) ?? \"\").toLowerCase();\n return value !== \"false\" && value !== \"0\" && Boolean(value);\n}\n\nfunction loadEnvironmentVariable(key: KnownEnvironmentKey): void {\n if (typeof process !== \"undefined\" && process.env) {\n const rawValue = process.env[key] ?? process.env[key.toLowerCase()];\n environmentCache.set(key, rawValue);\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { InstrumentationBase, } from "@opentelemetry/instrumentation";
|
|
4
4
|
import { OpenTelemetryInstrumenter } from "./instrumenter";
|
|
5
|
-
import { SDK_VERSION } from "./
|
|
5
|
+
import { SDK_VERSION } from "./configuration";
|
|
6
6
|
import { useInstrumenter } from "@azure/core-tracing";
|
|
7
7
|
/**
|
|
8
8
|
* The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
|
|
@@ -28,7 +28,7 @@ class AzureSdkInstrumentation extends InstrumentationBase {
|
|
|
28
28
|
/**
|
|
29
29
|
* Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
|
|
30
30
|
*
|
|
31
|
-
* When
|
|
31
|
+
* When registered, any Azure data plane package will begin emitting tracing spans for internal calls
|
|
32
32
|
* as well as network calls
|
|
33
33
|
*
|
|
34
34
|
* Example usage:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.browser.js","sourceRoot":"","sources":["../../src/instrumentation.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAEL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"instrumentation.browser.js","sourceRoot":"","sources":["../../src/instrumentation.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAEL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAOtD;;GAEG;AACH,MAAM,uBAAwB,SAAQ,mBAAmB;IACvD,YAAY,UAA0C,EAAE;QACtD,KAAK,CACH,gDAAgD,EAChD,WAAW,EACX,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAC3B,CAAC;IACJ,CAAC;IACD,2GAA2G;IACjG,IAAI;QACZ,QAAQ;IACV,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,eAAe,CAAC,IAAI,yBAAyB,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO;QACL,QAAQ;IACV,CAAC;CACF;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,6BAA6B,CAC3C,UAA0C,EAAE;IAE5C,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n Instrumentation,\n InstrumentationBase,\n InstrumentationConfig,\n} from \"@opentelemetry/instrumentation\";\nimport { OpenTelemetryInstrumenter } from \"./instrumenter\";\nimport { SDK_VERSION } from \"./configuration\";\nimport { useInstrumenter } from \"@azure/core-tracing\";\n\n/**\n * Configuration options that can be passed to {@link createAzureSdkInstrumentation} function.\n */\nexport interface AzureSdkInstrumentationOptions extends InstrumentationConfig {}\n\n/**\n * The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.\n */\nclass AzureSdkInstrumentation extends InstrumentationBase {\n constructor(options: AzureSdkInstrumentationOptions = {}) {\n super(\n \"@azure/opentelemetry-instrumentation-azure-sdk\",\n SDK_VERSION,\n Object.assign({}, options)\n );\n }\n /** In the browser we rely on overriding the `enable` function instead as there are no modules to patch. */\n protected init(): void {\n // no-op\n }\n\n /**\n * Entrypoint for the module registration. Ensures the global instrumenter is set to use OpenTelemetry.\n */\n enable(): void {\n useInstrumenter(new OpenTelemetryInstrumenter());\n }\n\n disable(): void {\n // no-op\n }\n}\n\n/**\n * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.\n *\n * When registered, any Azure data plane package will begin emitting tracing spans for internal calls\n * as well as network calls\n *\n * Example usage:\n * ```ts\n * const openTelemetryInstrumentation = require(\"@opentelemetry/instrumentation\");\n * openTelemetryInstrumentation.registerInstrumentations({\n * instrumentations: [createAzureSdkInstrumentation()],\n * })\n * ```\n */\nexport function createAzureSdkInstrumentation(\n options: AzureSdkInstrumentationOptions = {}\n): Instrumentation {\n return new AzureSdkInstrumentation(options);\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition, } from "@opentelemetry/instrumentation";
|
|
4
4
|
import { OpenTelemetryInstrumenter } from "./instrumenter";
|
|
5
|
-
import { SDK_VERSION } from "./
|
|
5
|
+
import { SDK_VERSION } from "./configuration";
|
|
6
6
|
/**
|
|
7
7
|
* The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
|
|
8
8
|
*/
|
|
@@ -30,7 +30,7 @@ class AzureSdkInstrumentation extends InstrumentationBase {
|
|
|
30
30
|
/**
|
|
31
31
|
* Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
|
|
32
32
|
*
|
|
33
|
-
* When
|
|
33
|
+
* When registered, any Azure data plane package will begin emitting tracing spans for internal calls
|
|
34
34
|
* as well as network calls
|
|
35
35
|
*
|
|
36
36
|
* Example usage:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAEL,mBAAmB,EAGnB,mCAAmC,GACpC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAEL,mBAAmB,EAGnB,mCAAmC,GACpC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C;;GAEG;AACH,MAAM,uBAAwB,SAAQ,mBAAmB;IACvD,YAAY,UAA0C,EAAE;QACtD,KAAK,CACH,gDAAgD,EAChD,WAAW,EACX,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAC3B,CAAC;IACJ,CAAC;IACD;;;;OAIG;IACO,IAAI;QAIZ,MAAM,MAAM,GACV,IAAI,mCAAmC,CACrC,qBAAqB,EACrB,CAAC,mBAAmB,EAAE,QAAQ,CAAC,EAC/B,CAAC,aAAa,EAAE,EAAE;YAChB,IAAI,OAAO,aAAa,CAAC,eAAe,KAAK,UAAU,EAAE;gBACvD,aAAa,CAAC,eAAe,CAAC,IAAI,yBAAyB,EAAE,CAAC,CAAC;aAChE;YAED,OAAO,aAAa,CAAC;QACvB,CAAC,CACF,CAAC;QACJ,qCAAqC;QACrC,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,6BAA6B,CAC3C,UAA0C,EAAE;IAE5C,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as coreTracing from \"@azure/core-tracing\";\nimport {\n Instrumentation,\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from \"@opentelemetry/instrumentation\";\nimport { OpenTelemetryInstrumenter } from \"./instrumenter\";\nimport { SDK_VERSION } from \"./configuration\";\n\n/**\n * Configuration options that can be passed to {@link createAzureSdkInstrumentation} function.\n */\nexport interface AzureSdkInstrumentationOptions extends InstrumentationConfig {}\n\n/**\n * The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.\n */\nclass AzureSdkInstrumentation extends InstrumentationBase {\n constructor(options: AzureSdkInstrumentationOptions = {}) {\n super(\n \"@azure/opentelemetry-instrumentation-azure-sdk\",\n SDK_VERSION,\n Object.assign({}, options)\n );\n }\n /**\n * Entrypoint for the module registration.\n *\n * @returns The patched \\@azure/core-tracing module after setting its instrumenter.\n */\n protected init():\n | void\n | InstrumentationModuleDefinition<typeof coreTracing>\n | InstrumentationModuleDefinition<typeof coreTracing>[] {\n const result: InstrumentationModuleDefinition<typeof coreTracing> =\n new InstrumentationNodeModuleDefinition(\n \"@azure/core-tracing\",\n [\"^1.0.0-preview.14\", \"^1.0.0\"],\n (moduleExports) => {\n if (typeof moduleExports.useInstrumenter === \"function\") {\n moduleExports.useInstrumenter(new OpenTelemetryInstrumenter());\n }\n\n return moduleExports;\n }\n );\n // Needed to support 1.0.0-preview.14\n result.includePrerelease = true;\n return result;\n }\n}\n\n/**\n * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.\n *\n * When registered, any Azure data plane package will begin emitting tracing spans for internal calls\n * as well as network calls\n *\n * Example usage:\n * ```ts\n * const openTelemetryInstrumentation = require(\"@opentelemetry/instrumentation\");\n * openTelemetryInstrumentation.registerInstrumentations({\n * instrumentations: [createAzureSdkInstrumentation()],\n * })\n * ```\n *\n * @remarks\n *\n * As OpenTelemetry instrumentations rely on patching required modules, you should register\n * this instrumentation as early as possible and before loading any Azure Client Libraries.\n */\nexport function createAzureSdkInstrumentation(\n options: AzureSdkInstrumentationOptions = {}\n): Instrumentation {\n return new AzureSdkInstrumentation(options);\n}\n"]}
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
import { context, defaultTextMapGetter, defaultTextMapSetter, trace } from "@opentelemetry/api";
|
|
3
|
+
import { INVALID_SPAN_CONTEXT, context, defaultTextMapGetter, defaultTextMapSetter, trace, } from "@opentelemetry/api";
|
|
4
|
+
import { W3CTraceContextPropagator, suppressTracing } from "@opentelemetry/core";
|
|
4
5
|
import { OpenTelemetrySpanWrapper } from "./spanWrapper";
|
|
5
|
-
import {
|
|
6
|
+
import { envVarToBoolean } from "./configuration";
|
|
6
7
|
import { toSpanOptions } from "./transformations";
|
|
7
8
|
// While default propagation is user-configurable, Azure services always use the W3C implementation.
|
|
8
9
|
export const propagator = new W3CTraceContextPropagator();
|
|
9
10
|
export class OpenTelemetryInstrumenter {
|
|
10
11
|
startSpan(name, spanOptions) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
let ctx = (spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.tracingContext) || context.active();
|
|
13
|
+
let span;
|
|
14
|
+
if (envVarToBoolean("AZURE_TRACING_DISABLED")) {
|
|
15
|
+
// disable only our spans but not any downstream spans
|
|
16
|
+
span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// Create our span
|
|
20
|
+
span = trace
|
|
21
|
+
.getTracer(spanOptions.packageName, spanOptions.packageVersion)
|
|
22
|
+
.startSpan(name, toSpanOptions(spanOptions), ctx);
|
|
23
|
+
if (envVarToBoolean("AZURE_HTTP_TRACING_CHILDREN_DISABLED") &&
|
|
24
|
+
name.toUpperCase().startsWith("HTTP")) {
|
|
25
|
+
// disable downstream spans
|
|
26
|
+
ctx = suppressTracing(ctx);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
15
29
|
return {
|
|
16
30
|
span: new OpenTelemetrySpanWrapper(span),
|
|
17
31
|
tracingContext: trace.setSpan(ctx, span),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,oBAAoB,EAEpB,OAAO,EACP,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,GACN,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,oGAAoG;AACpG,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,yBAAyB,EAAE,CAAC;AAE1D,MAAM,OAAO,yBAAyB;IACpC,SAAS,CACP,IAAY,EACZ,WAAoC;QAEpC,IAAI,GAAG,GAAG,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,KAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1D,IAAI,IAAU,CAAC;QAEf,IAAI,eAAe,CAAC,wBAAwB,CAAC,EAAE;YAC7C,sDAAsD;YACtD,IAAI,GAAG,KAAK,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC;SACpD;aAAM;YACL,kBAAkB;YAClB,IAAI,GAAG,KAAK;iBACT,SAAS,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,CAAC,cAAc,CAAC;iBAC9D,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,CAAC;YAEpD,IACE,eAAe,CAAC,sCAAsC,CAAC;gBACvD,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EACrC;gBACA,2BAA2B;gBAC3B,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;aAC5B;SACF;QAED,OAAO;YACL,IAAI,EAAE,IAAI,wBAAwB,CAAC,IAAI,CAAC;YACxC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC;SACzC,CAAC;IACJ,CAAC;IACD,WAAW,CAIT,cAA8B,EAC9B,QAAkB,EAClB,GAAG,YAA0B;QAE7B,OAAO,OAAO,CAAC,IAAI,CACjB,cAAc,EACd,QAAQ;QACR,4DAA4D,CAAC,SAAS,EACtE,GAAG,YAAY,CAChB,CAAC;IACJ,CAAC;IAED,sBAAsB,CAAC,iBAAyB;QAC9C,OAAO,UAAU,CAAC,OAAO,CACvB,OAAO,CAAC,MAAM,EAAE,EAChB,EAAE,WAAW,EAAE,iBAAiB,EAAE,EAClC,oBAAoB,CACrB,CAAC;IACJ,CAAC;IAED,oBAAoB,CAAC,cAA+B;QAClD,MAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,UAAU,CAAC,MAAM,CAAC,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC;QACrF,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n INVALID_SPAN_CONTEXT,\n Span,\n context,\n defaultTextMapGetter,\n defaultTextMapSetter,\n trace,\n} from \"@opentelemetry/api\";\nimport {\n Instrumenter,\n InstrumenterSpanOptions,\n TracingContext,\n TracingSpan,\n} from \"@azure/core-tracing\";\nimport { W3CTraceContextPropagator, suppressTracing } from \"@opentelemetry/core\";\n\nimport { OpenTelemetrySpanWrapper } from \"./spanWrapper\";\nimport { envVarToBoolean } from \"./configuration\";\nimport { toSpanOptions } from \"./transformations\";\n\n// While default propagation is user-configurable, Azure services always use the W3C implementation.\nexport const propagator = new W3CTraceContextPropagator();\n\nexport class OpenTelemetryInstrumenter implements Instrumenter {\n startSpan(\n name: string,\n spanOptions: InstrumenterSpanOptions\n ): { span: TracingSpan; tracingContext: TracingContext } {\n let ctx = spanOptions?.tracingContext || context.active();\n let span: Span;\n\n if (envVarToBoolean(\"AZURE_TRACING_DISABLED\")) {\n // disable only our spans but not any downstream spans\n span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);\n } else {\n // Create our span\n span = trace\n .getTracer(spanOptions.packageName, spanOptions.packageVersion)\n .startSpan(name, toSpanOptions(spanOptions), ctx);\n\n if (\n envVarToBoolean(\"AZURE_HTTP_TRACING_CHILDREN_DISABLED\") &&\n name.toUpperCase().startsWith(\"HTTP\")\n ) {\n // disable downstream spans\n ctx = suppressTracing(ctx);\n }\n }\n\n return {\n span: new OpenTelemetrySpanWrapper(span),\n tracingContext: trace.setSpan(ctx, span),\n };\n }\n withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n tracingContext: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback> {\n return context.with(\n tracingContext,\n callback,\n /** Assume caller will bind `this` or use arrow functions */ undefined,\n ...callbackArgs\n );\n }\n\n parseTraceparentHeader(traceparentHeader: string): TracingContext {\n return propagator.extract(\n context.active(),\n { traceparent: traceparentHeader },\n defaultTextMapGetter\n );\n }\n\n createRequestHeaders(tracingContext?: TracingContext): Record<string, string> {\n const headers: Record<string, string> = {};\n propagator.inject(tracingContext || context.active(), headers, defaultTextMapSetter);\n return headers;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/opentelemetry-instrumentation-azure-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "Instrumentation client for the Azure SDK.",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist-esm/src/index.js",
|
|
8
8
|
"browser": {
|
|
9
|
-
"./dist-esm/src/instrumentation.js": "./dist-esm/src/instrumentation.browser.js"
|
|
9
|
+
"./dist-esm/src/instrumentation.js": "./dist-esm/src/instrumentation.browser.js",
|
|
10
|
+
"./dist-esm/test/public/util/tracerProvider.js": "./dist-esm/test/public/util/tracerProvider.browser.js"
|
|
10
11
|
},
|
|
11
12
|
"//metadata": {
|
|
12
13
|
"constantPaths": [
|
|
13
14
|
{
|
|
14
|
-
"path": "src/
|
|
15
|
+
"path": "src/configuration.ts",
|
|
15
16
|
"prefix": "SDK_VERSION"
|
|
16
17
|
}
|
|
17
18
|
]
|
|
@@ -32,16 +33,15 @@
|
|
|
32
33
|
"build": "npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local && npm run build:types",
|
|
33
34
|
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
34
35
|
"clean": "rimraf dist dist-* temp types *.tgz *.log",
|
|
35
|
-
"docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src",
|
|
36
36
|
"execute:samples": "dev-tool samples run samples-dev",
|
|
37
37
|
"extract-api": "tsc -p . && api-extractor run --local",
|
|
38
|
-
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"
|
|
38
|
+
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
39
39
|
"generate:client": "autorest --typescript ./swagger/README.md",
|
|
40
40
|
"integration-test:browser": "karma start --single-run",
|
|
41
41
|
"integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}/*.spec.js\"",
|
|
42
42
|
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
|
43
|
-
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
|
|
44
|
-
"lint": "eslint package.json api-extractor.json src test --ext .ts",
|
|
43
|
+
"lint:fix": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]",
|
|
44
|
+
"lint": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js",
|
|
45
45
|
"pack": "npm pack 2>&1",
|
|
46
46
|
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
|
|
47
47
|
"test:node": "npm run clean && tsc -p . && npm run unit-test:node && npm run integration-test:node",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
],
|
|
61
61
|
"repository": "github:Azure/azure-sdk-for-js",
|
|
62
62
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
63
|
+
"node": ">=14.0.0"
|
|
64
64
|
},
|
|
65
65
|
"keywords": [
|
|
66
66
|
"azure",
|
|
@@ -77,50 +77,47 @@
|
|
|
77
77
|
"sideEffects": false,
|
|
78
78
|
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@azure/core-tracing": "1.0.0
|
|
80
|
+
"@azure/core-tracing": "^1.0.0",
|
|
81
81
|
"@azure/logger": "^1.0.0",
|
|
82
|
-
"@opentelemetry/api": "
|
|
83
|
-
"@opentelemetry/core": "
|
|
84
|
-
"@opentelemetry/instrumentation": "^0.
|
|
82
|
+
"@opentelemetry/api": "^1.4.0",
|
|
83
|
+
"@opentelemetry/core": "^1.9.0",
|
|
84
|
+
"@opentelemetry/instrumentation": "^0.35.0",
|
|
85
85
|
"tslib": "^2.2.0"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
|
-
"@azure
|
|
88
|
+
"@azure/core-rest-pipeline": "^1.5.1",
|
|
89
89
|
"@azure/dev-tool": "^1.0.0",
|
|
90
90
|
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
91
|
-
"@microsoft/api-extractor": "^7.
|
|
91
|
+
"@microsoft/api-extractor": "^7.31.1",
|
|
92
|
+
"@opentelemetry/sdk-trace-base": "^1.9.0",
|
|
93
|
+
"@opentelemetry/sdk-trace-node": "^1.9.0",
|
|
92
94
|
"@types/chai": "^4.1.6",
|
|
93
95
|
"@types/mocha": "^7.0.2",
|
|
94
|
-
"@types/node": "^
|
|
96
|
+
"@types/node": "^14.0.0",
|
|
95
97
|
"@types/sinon": "^10.0.6",
|
|
96
98
|
"chai": "^4.2.0",
|
|
97
99
|
"cross-env": "^7.0.2",
|
|
98
|
-
"dotenv": "^
|
|
99
|
-
"downlevel-dts": "
|
|
100
|
-
"eslint": "^
|
|
100
|
+
"dotenv": "^16.0.0",
|
|
101
|
+
"downlevel-dts": "^0.10.0",
|
|
102
|
+
"eslint": "^8.0.0",
|
|
101
103
|
"esm": "^3.2.18",
|
|
102
104
|
"inherits": "^2.0.3",
|
|
103
105
|
"karma": "^6.2.0",
|
|
104
106
|
"karma-chrome-launcher": "^3.0.0",
|
|
105
107
|
"karma-coverage": "^2.0.0",
|
|
106
|
-
"karma-edge-launcher": "^0.4.2",
|
|
107
108
|
"karma-env-preprocessor": "^0.1.1",
|
|
108
109
|
"karma-firefox-launcher": "^1.1.0",
|
|
109
|
-
"karma-ie-launcher": "^1.0.0",
|
|
110
|
-
"karma-json-preprocessor": "^0.3.3",
|
|
111
|
-
"karma-json-to-file-reporter": "^1.0.1",
|
|
112
110
|
"karma-junit-reporter": "^2.0.1",
|
|
113
111
|
"karma-mocha": "^2.0.1",
|
|
114
112
|
"karma-mocha-reporter": "^2.2.5",
|
|
115
113
|
"mocha": "^7.1.1",
|
|
116
114
|
"mocha-junit-reporter": "^1.18.0",
|
|
117
|
-
"nyc": "^
|
|
115
|
+
"nyc": "^15.0.0",
|
|
118
116
|
"prettier": "^2.5.1",
|
|
119
117
|
"rimraf": "^3.0.0",
|
|
120
118
|
"sinon": "^12.0.1",
|
|
121
119
|
"source-map-support": "^0.5.9",
|
|
122
|
-
"
|
|
123
|
-
"typescript": "~4.2.0",
|
|
120
|
+
"typescript": "~5.0.0",
|
|
124
121
|
"util": "^0.12.1"
|
|
125
122
|
},
|
|
126
123
|
"//sampleConfiguration": {
|
|
@@ -9,7 +9,7 @@ export declare interface AzureSdkInstrumentationOptions extends InstrumentationC
|
|
|
9
9
|
/**
|
|
10
10
|
* Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
|
|
11
11
|
*
|
|
12
|
-
* When
|
|
12
|
+
* When registered, any Azure data plane package will begin emitting tracing spans for internal calls
|
|
13
13
|
* as well as network calls
|
|
14
14
|
*
|
|
15
15
|
* Example usage:
|
|
@@ -11,7 +11,7 @@ export declare interface AzureSdkInstrumentationOptions extends InstrumentationC
|
|
|
11
11
|
/**
|
|
12
12
|
* Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
|
|
13
13
|
*
|
|
14
|
-
* When
|
|
14
|
+
* When registered, any Azure data plane package will begin emitting tracing spans for internal calls
|
|
15
15
|
* as well as network calls
|
|
16
16
|
*
|
|
17
17
|
* Example usage:
|
package/CHANGELOG.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,cAAc,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const SDK_VERSION: string = \"1.0.0-beta.1\";\n"]}
|