@azure/opentelemetry-instrumentation-azure-sdk 1.0.0-alpha.20220118.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Release History
2
+
3
+ ## 1.0.0-beta.1 (Unreleased)
4
+
5
+ ### Features Added
6
+
7
+ This marks the first beta release of the OpenTelemetry Instrumentation library for the Azure SDK which will enable OpenTelemetry Span creation for Azure SDK client libraries.
8
+
9
+ ### Breaking Changes
10
+
11
+ ### Bugs Fixed
12
+
13
+ ### Other Changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Microsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Azure OpenTelemetry Instrumentation library for JavaScript
2
+
3
+ ## Getting started
4
+
5
+ ### Currently supported environments
6
+
7
+ - [LTS versions of Node.js](https://nodejs.org/about/releases/)
8
+ - Latest versions of Safari, Chrome, Edge, and Firefox.
9
+
10
+ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
11
+
12
+ ### Prerequisites
13
+
14
+ - An [Azure subscription][azure_sub].
15
+ - The [@opentelemetry/instrumentation][otel_instrumentation] package.
16
+
17
+ You'll need to configure the OpenTelemetry SDK in order to produce Telemetry data. While configuring OpenTelemetry is outside the scope of this README, we encourage you to review the [OpenTelemetry documentation][otel_documentation] in order to get started using OpenTelemetry.
18
+
19
+ ### Install the `@azure/opentelemetry-instrumentation-azure-sdk` package
20
+
21
+ Install the Azure OpenTelemetry Instrumentation client library with `npm`:
22
+
23
+ ```bash
24
+ npm install @azure/opentelemetry-instrumentation-azure-sdk
25
+ ```
26
+
27
+ ### Browser support
28
+
29
+ #### JavaScript Bundle
30
+
31
+ To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).
32
+
33
+ ## Key concepts
34
+
35
+ - The **createAzureSdkInstrumentation** function is the main hook exported by this library which provides a way to create an Azure SDK Instrumentation object to be registered with OpenTelemetry.
36
+
37
+ ### Compatibility with existing Client Libraries
38
+
39
+ - TODO, we should describe what versions of core-tracing are compatible here...
40
+
41
+ ## Examples
42
+
43
+ ### Enable OpenTelemetry instrumentation
44
+
45
+ ```javascript
46
+ const { registerInstrumentations } = require("@opentelemetry/instrumentation");
47
+ const { createAzureSdkInstrumentation } = require("@azure/opentelemetry-instrumentation-azure-sdk");
48
+
49
+ // Configure exporters, tracer providers, etc.
50
+ // Please refer to the OpenTelemetry documentation for more information.
51
+
52
+ registerInstrumentations({
53
+ instrumentations: [createAzureSdkInstrumentation()],
54
+ });
55
+
56
+ // Continue to import any Azure SDK client libraries after registering the instrumentation.
57
+
58
+ const { keyClient } = require("@azure/keyvault-keys");
59
+
60
+ // Do something cool with the keyClient...
61
+ ```
62
+
63
+ ## Troubleshooting
64
+
65
+ ### Logging
66
+
67
+ 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`:
68
+
69
+ ```javascript
70
+ import { setLogLevel } from "@azure/logger";
71
+
72
+ setLogLevel("info");
73
+ ```
74
+
75
+ For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
76
+
77
+ ## Next steps
78
+
79
+ - TODO: no samples yet, so the link verification fails. Add link to samples...
80
+
81
+ ## Contributing
82
+
83
+ If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
84
+
85
+ ## Related projects
86
+
87
+ - [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
88
+
89
+ ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Ftemplate%2Ftemplate%2FREADME.png)
90
+
91
+ [azure_cli]: https://docs.microsoft.com/cli/azure
92
+ [azure_sub]: https://azure.microsoft.com/free/
93
+ [otel_instrumentation]: https://www.npmjs.com/package/@opentelemetry/instrumentation
94
+ [otel_documentation]: https://opentelemetry.io/docs/js/
package/dist/index.js ADDED
@@ -0,0 +1,206 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var logger$1 = require('@azure/logger');
6
+ var instrumentation = require('@opentelemetry/instrumentation');
7
+ var api = require('@opentelemetry/api');
8
+ var core = require('@opentelemetry/core');
9
+
10
+ // Copyright (c) Microsoft Corporation.
11
+ /**
12
+ * The \@azure/logger configuration for this package.
13
+ */
14
+ const logger = logger$1.createClientLogger("opentelemetry-instrumentation-azure-sdk");
15
+
16
+ // Copyright (c) Microsoft Corporation.
17
+ class OpenTelemetrySpanWrapper {
18
+ constructor(span) {
19
+ this._span = span;
20
+ }
21
+ setStatus(status) {
22
+ if (status.status === "error") {
23
+ if (status.error) {
24
+ this._span.setStatus({ code: api.SpanStatusCode.ERROR, message: status.error.toString() });
25
+ this.recordException(status.error);
26
+ }
27
+ else {
28
+ this._span.setStatus({ code: api.SpanStatusCode.ERROR });
29
+ }
30
+ }
31
+ else if (status.status === "success") {
32
+ this._span.setStatus({ code: api.SpanStatusCode.OK });
33
+ }
34
+ }
35
+ setAttribute(name, value) {
36
+ if (value !== null && value !== undefined) {
37
+ this._span.setAttribute(name, value);
38
+ }
39
+ }
40
+ end() {
41
+ this._span.end();
42
+ }
43
+ recordException(exception) {
44
+ this._span.recordException(exception);
45
+ }
46
+ isRecording() {
47
+ return this._span.isRecording();
48
+ }
49
+ /**
50
+ * Allows getting the wrapped span as needed.
51
+ * @internal
52
+ *
53
+ * @returns The underlying span
54
+ */
55
+ unwrap() {
56
+ return this._span;
57
+ }
58
+ }
59
+
60
+ // Copyright (c) Microsoft Corporation.
61
+ /**
62
+ * Converts our TracingSpanKind to the corresponding OpenTelemetry SpanKind.
63
+ *
64
+ * By default it will return {@link SpanKind.INTERNAL}
65
+ * @param tracingSpanKind - The core tracing {@link TracingSpanKind}
66
+ * @returns - The OpenTelemetry {@link SpanKind}
67
+ */
68
+ function toOpenTelemetrySpanKind(tracingSpanKind) {
69
+ const key = (tracingSpanKind || "internal").toUpperCase();
70
+ return api.SpanKind[key];
71
+ }
72
+ /**
73
+ * Converts core-tracing's TracingSpanLink to OpenTelemetry's Link
74
+ *
75
+ * @param spanLinks - The core tracing {@link TracingSpanLink} to convert
76
+ * @returns A set of {@link Link}s
77
+ */
78
+ function toOpenTelemetryLinks(spanLinks = []) {
79
+ return spanLinks.reduce((acc, tracingSpanLink) => {
80
+ const spanContext = api.trace.getSpanContext(tracingSpanLink.tracingContext);
81
+ if (spanContext) {
82
+ acc.push({
83
+ context: spanContext,
84
+ attributes: toOpenTelemetrySpanAttributes(tracingSpanLink.attributes),
85
+ });
86
+ }
87
+ return acc;
88
+ }, []);
89
+ }
90
+ /**
91
+ * Converts core-tracing's span attributes to OpenTelemetry attributes.
92
+ *
93
+ * @param spanAttributes - The set of attributes to convert.
94
+ * @returns An {@link SpanAttributes} to set on a span.
95
+ */
96
+ function toOpenTelemetrySpanAttributes(spanAttributes) {
97
+ const attributes = {};
98
+ for (const key in spanAttributes) {
99
+ // Any non-nullish value is allowed.
100
+ if (spanAttributes[key] !== null && spanAttributes[key] !== undefined) {
101
+ attributes[key] = spanAttributes[key];
102
+ }
103
+ }
104
+ return attributes;
105
+ }
106
+ /**
107
+ * Converts core-tracing span options to OpenTelemetry options.
108
+ *
109
+ * @param spanOptions - The {@link InstrumenterSpanOptions} to convert.
110
+ * @returns An OpenTelemetry {@link SpanOptions} that can be used when creating a span.
111
+ */
112
+ function toSpanOptions(spanOptions) {
113
+ const { spanAttributes, spanLinks, spanKind } = spanOptions || {};
114
+ const attributes = toOpenTelemetrySpanAttributes(spanAttributes);
115
+ const kind = toOpenTelemetrySpanKind(spanKind);
116
+ const links = toOpenTelemetryLinks(spanLinks);
117
+ return {
118
+ attributes,
119
+ kind,
120
+ links,
121
+ };
122
+ }
123
+
124
+ // Copyright (c) Microsoft Corporation.
125
+ // While default propagation is user-configurable, Azure services always use the W3C implementation.
126
+ const propagator = new core.W3CTraceContextPropagator();
127
+ class OpenTelemetryInstrumenter {
128
+ startSpan(name, spanOptions) {
129
+ const span = api.trace
130
+ .getTracer(spanOptions.packageName, spanOptions.packageVersion)
131
+ .startSpan(name, toSpanOptions(spanOptions));
132
+ const ctx = (spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.tracingContext) || api.context.active();
133
+ return {
134
+ span: new OpenTelemetrySpanWrapper(span),
135
+ tracingContext: api.trace.setSpan(ctx, span),
136
+ };
137
+ }
138
+ withContext(tracingContext, callback, ...callbackArgs) {
139
+ return api.context.with(tracingContext, callback,
140
+ /** Assume caller will bind `this` or use arrow functions */ undefined, ...callbackArgs);
141
+ }
142
+ parseTraceparentHeader(traceparentHeader) {
143
+ return propagator.extract(api.context.active(), { traceparent: traceparentHeader }, api.defaultTextMapGetter);
144
+ }
145
+ createRequestHeaders(tracingContext) {
146
+ const headers = {};
147
+ propagator.inject(tracingContext || api.context.active(), headers, api.defaultTextMapSetter);
148
+ return headers;
149
+ }
150
+ }
151
+
152
+ // Copyright (c) Microsoft Corporation.
153
+ // Licensed under the MIT license.
154
+ const SDK_VERSION = "1.0.0-beta.1";
155
+
156
+ // Copyright (c) Microsoft Corporation.
157
+ /**
158
+ * The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
159
+ */
160
+ class AzureSdkInstrumentation extends instrumentation.InstrumentationBase {
161
+ constructor(options = {}) {
162
+ super("@azure/opentelemetry-instrumentation-azure-sdk", SDK_VERSION, Object.assign({}, options));
163
+ }
164
+ /**
165
+ * Entrypoint for the module registration.
166
+ *
167
+ * @returns The patched \@azure/core-tracing module after setting its instrumenter.
168
+ */
169
+ init() {
170
+ const result = new instrumentation.InstrumentationNodeModuleDefinition("@azure/core-tracing", ["^1.0.0-preview.14", "^1.0.0"], (moduleExports) => {
171
+ if (typeof moduleExports.useInstrumenter === "function") {
172
+ moduleExports.useInstrumenter(new OpenTelemetryInstrumenter());
173
+ }
174
+ return moduleExports;
175
+ });
176
+ // Needed to support 1.0.0-preview.14
177
+ result.includePrerelease = true;
178
+ return result;
179
+ }
180
+ }
181
+ /**
182
+ * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
183
+ *
184
+ * When registerd, any Azure data plane package will begin emitting tracing spans for internal calls
185
+ * as well as network calls
186
+ *
187
+ * Example usage:
188
+ * ```ts
189
+ * const openTelemetryInstrumentation = require("@opentelemetry/instrumentation");
190
+ * openTelemetryInstrumentation.registerInstrumentations({
191
+ * instrumentations: [createAzureSdkInstrumentation()],
192
+ * })
193
+ * ```
194
+ *
195
+ * @remarks
196
+ *
197
+ * As OpenTelemetry instrumentations rely on patching required modules, you should register
198
+ * this instrumentation as early as possible and before loading any Azure Client Libraries.
199
+ */
200
+ function createAzureSdkInstrumentation(options = {}) {
201
+ return new AzureSdkInstrumentation(options);
202
+ }
203
+
204
+ exports.createAzureSdkInstrumentation = createAzureSdkInstrumentation;
205
+ exports.logger = logger;
206
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AACA,MAKa,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;aAC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AmBA,SAAgB,6BAA6B,CAC3C,UAA0C,EAAE;IAE5C,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;;;;;"}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ export const SDK_VERSION = "1.0.0-beta.1";
4
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ export * from "./logger";
4
+ export * from "./instrumentation";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport * from \"./logger\";\nexport * from \"./instrumentation\";\n"]}
@@ -0,0 +1,45 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { InstrumentationBase, } from "@opentelemetry/instrumentation";
4
+ import { OpenTelemetryInstrumenter } from "./instrumenter";
5
+ import { SDK_VERSION } from "./constants";
6
+ import { useInstrumenter } from "@azure/core-tracing";
7
+ /**
8
+ * The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
9
+ */
10
+ class AzureSdkInstrumentation extends InstrumentationBase {
11
+ constructor(options = {}) {
12
+ super("@azure/opentelemetry-instrumentation-azure-sdk", SDK_VERSION, Object.assign({}, options));
13
+ }
14
+ /** In the browser we rely on overriding the `enable` function instead as there are no modules to patch. */
15
+ init() {
16
+ // no-op
17
+ }
18
+ /**
19
+ * Entrypoint for the module registration. Ensures the global instrumenter is set to use OpenTelemetry.
20
+ */
21
+ enable() {
22
+ useInstrumenter(new OpenTelemetryInstrumenter());
23
+ }
24
+ disable() {
25
+ // no-op
26
+ }
27
+ }
28
+ /**
29
+ * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
30
+ *
31
+ * When registerd, any Azure data plane package will begin emitting tracing spans for internal calls
32
+ * as well as network calls
33
+ *
34
+ * Example usage:
35
+ * ```ts
36
+ * const openTelemetryInstrumentation = require("@opentelemetry/instrumentation");
37
+ * openTelemetryInstrumentation.registerInstrumentations({
38
+ * instrumentations: [createAzureSdkInstrumentation()],
39
+ * })
40
+ * ```
41
+ */
42
+ export function createAzureSdkInstrumentation(options = {}) {
43
+ return new AzureSdkInstrumentation(options);
44
+ }
45
+ //# sourceMappingURL=instrumentation.browser.js.map
@@ -0,0 +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,aAAa,CAAC;AAC1C,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 \"./constants\";\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 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 */\nexport function createAzureSdkInstrumentation(\n options: AzureSdkInstrumentationOptions = {}\n): Instrumentation {\n return new AzureSdkInstrumentation(options);\n}\n"]}
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { InstrumentationBase, InstrumentationNodeModuleDefinition, } from "@opentelemetry/instrumentation";
4
+ import { OpenTelemetryInstrumenter } from "./instrumenter";
5
+ import { SDK_VERSION } from "./constants";
6
+ /**
7
+ * The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
8
+ */
9
+ class AzureSdkInstrumentation extends InstrumentationBase {
10
+ constructor(options = {}) {
11
+ super("@azure/opentelemetry-instrumentation-azure-sdk", SDK_VERSION, Object.assign({}, options));
12
+ }
13
+ /**
14
+ * Entrypoint for the module registration.
15
+ *
16
+ * @returns The patched \@azure/core-tracing module after setting its instrumenter.
17
+ */
18
+ init() {
19
+ const result = new InstrumentationNodeModuleDefinition("@azure/core-tracing", ["^1.0.0-preview.14", "^1.0.0"], (moduleExports) => {
20
+ if (typeof moduleExports.useInstrumenter === "function") {
21
+ moduleExports.useInstrumenter(new OpenTelemetryInstrumenter());
22
+ }
23
+ return moduleExports;
24
+ });
25
+ // Needed to support 1.0.0-preview.14
26
+ result.includePrerelease = true;
27
+ return result;
28
+ }
29
+ }
30
+ /**
31
+ * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
32
+ *
33
+ * When registerd, any Azure data plane package will begin emitting tracing spans for internal calls
34
+ * as well as network calls
35
+ *
36
+ * Example usage:
37
+ * ```ts
38
+ * const openTelemetryInstrumentation = require("@opentelemetry/instrumentation");
39
+ * openTelemetryInstrumentation.registerInstrumentations({
40
+ * instrumentations: [createAzureSdkInstrumentation()],
41
+ * })
42
+ * ```
43
+ *
44
+ * @remarks
45
+ *
46
+ * As OpenTelemetry instrumentations rely on patching required modules, you should register
47
+ * this instrumentation as early as possible and before loading any Azure Client Libraries.
48
+ */
49
+ export function createAzureSdkInstrumentation(options = {}) {
50
+ return new AzureSdkInstrumentation(options);
51
+ }
52
+ //# sourceMappingURL=instrumentation.js.map
@@ -0,0 +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,aAAa,CAAC;AAO1C;;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 \"./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"]}
@@ -0,0 +1,33 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { context, defaultTextMapGetter, defaultTextMapSetter, trace } from "@opentelemetry/api";
4
+ import { OpenTelemetrySpanWrapper } from "./spanWrapper";
5
+ import { W3CTraceContextPropagator } from "@opentelemetry/core";
6
+ import { toSpanOptions } from "./transformations";
7
+ // While default propagation is user-configurable, Azure services always use the W3C implementation.
8
+ export const propagator = new W3CTraceContextPropagator();
9
+ export class OpenTelemetryInstrumenter {
10
+ startSpan(name, spanOptions) {
11
+ const span = trace
12
+ .getTracer(spanOptions.packageName, spanOptions.packageVersion)
13
+ .startSpan(name, toSpanOptions(spanOptions));
14
+ const ctx = (spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.tracingContext) || context.active();
15
+ return {
16
+ span: new OpenTelemetrySpanWrapper(span),
17
+ tracingContext: trace.setSpan(ctx, span),
18
+ };
19
+ }
20
+ withContext(tracingContext, callback, ...callbackArgs) {
21
+ return context.with(tracingContext, callback,
22
+ /** Assume caller will bind `this` or use arrow functions */ undefined, ...callbackArgs);
23
+ }
24
+ parseTraceparentHeader(traceparentHeader) {
25
+ return propagator.extract(context.active(), { traceparent: traceparentHeader }, defaultTextMapGetter);
26
+ }
27
+ createRequestHeaders(tracingContext) {
28
+ const headers = {};
29
+ propagator.inject(tracingContext || context.active(), headers, defaultTextMapSetter);
30
+ return headers;
31
+ }
32
+ }
33
+ //# sourceMappingURL=instrumenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhG,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,yBA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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"]}
@@ -0,0 +1,8 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { createClientLogger } from "@azure/logger";
4
+ /**
5
+ * The \@azure/logger configuration for this package.
6
+ */
7
+ export const logger = createClientLogger("opentelemetry-instrumentation-azure-sdk");
8
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,yCAAyC,CAAC,CAAC","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"]}
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { SpanStatusCode } from "@opentelemetry/api";
4
+ export class OpenTelemetrySpanWrapper {
5
+ constructor(span) {
6
+ this._span = span;
7
+ }
8
+ setStatus(status) {
9
+ if (status.status === "error") {
10
+ if (status.error) {
11
+ this._span.setStatus({ code: SpanStatusCode.ERROR, message: status.error.toString() });
12
+ this.recordException(status.error);
13
+ }
14
+ else {
15
+ this._span.setStatus({ code: SpanStatusCode.ERROR });
16
+ }
17
+ }
18
+ else if (status.status === "success") {
19
+ this._span.setStatus({ code: SpanStatusCode.OK });
20
+ }
21
+ }
22
+ setAttribute(name, value) {
23
+ if (value !== null && value !== undefined) {
24
+ this._span.setAttribute(name, value);
25
+ }
26
+ }
27
+ end() {
28
+ this._span.end();
29
+ }
30
+ recordException(exception) {
31
+ this._span.recordException(exception);
32
+ }
33
+ isRecording() {
34
+ return this._span.isRecording();
35
+ }
36
+ /**
37
+ * Allows getting the wrapped span as needed.
38
+ * @internal
39
+ *
40
+ * @returns The underlying span
41
+ */
42
+ unwrap() {
43
+ return this._span;
44
+ }
45
+ }
46
+ //# sourceMappingURL=spanWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spanWrapper.js","sourceRo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,EAAE,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF","sourcesContent":["// 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"]}
@@ -0,0 +1,66 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { SpanKind, trace, } from "@opentelemetry/api";
4
+ /**
5
+ * Converts our TracingSpanKind to the corresponding OpenTelemetry SpanKind.
6
+ *
7
+ * By default it will return {@link SpanKind.INTERNAL}
8
+ * @param tracingSpanKind - The core tracing {@link TracingSpanKind}
9
+ * @returns - The OpenTelemetry {@link SpanKind}
10
+ */
11
+ export function toOpenTelemetrySpanKind(tracingSpanKind) {
12
+ const key = (tracingSpanKind || "internal").toUpperCase();
13
+ return SpanKind[key];
14
+ }
15
+ /**
16
+ * Converts core-tracing's TracingSpanLink to OpenTelemetry's Link
17
+ *
18
+ * @param spanLinks - The core tracing {@link TracingSpanLink} to convert
19
+ * @returns A set of {@link Link}s
20
+ */
21
+ function toOpenTelemetryLinks(spanLinks = []) {
22
+ return spanLinks.reduce((acc, tracingSpanLink) => {
23
+ const spanContext = trace.getSpanContext(tracingSpanLink.tracingContext);
24
+ if (spanContext) {
25
+ acc.push({
26
+ context: spanContext,
27
+ attributes: toOpenTelemetrySpanAttributes(tracingSpanLink.attributes),
28
+ });
29
+ }
30
+ return acc;
31
+ }, []);
32
+ }
33
+ /**
34
+ * Converts core-tracing's span attributes to OpenTelemetry attributes.
35
+ *
36
+ * @param spanAttributes - The set of attributes to convert.
37
+ * @returns An {@link SpanAttributes} to set on a span.
38
+ */
39
+ function toOpenTelemetrySpanAttributes(spanAttributes) {
40
+ const attributes = {};
41
+ for (const key in spanAttributes) {
42
+ // Any non-nullish value is allowed.
43
+ if (spanAttributes[key] !== null && spanAttributes[key] !== undefined) {
44
+ attributes[key] = spanAttributes[key];
45
+ }
46
+ }
47
+ return attributes;
48
+ }
49
+ /**
50
+ * Converts core-tracing span options to OpenTelemetry options.
51
+ *
52
+ * @param spanOptions - The {@link InstrumenterSpanOptions} to convert.
53
+ * @returns An OpenTelemetry {@link SpanOptions} that can be used when creating a span.
54
+ */
55
+ export function toSpanOptions(spanOptions) {
56
+ const { spanAttributes, spanLinks, spanKind } = spanOptions || {};
57
+ const attributes = toOpenTelemetrySpanAttributes(spanAttributes);
58
+ const kind = toOpenTelemetrySpanKind(spanKind);
59
+ const links = toOpenTelemetryLinks(spanLinks);
60
+ return {
61
+ attributes,
62
+ kind,
63
+ links,
64
+ };
65
+ }
66
+ //# sourceMappingURL=transformations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformations.js","sourceRoot":"","sources":["../../src/transformations.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAIL,QAAQ,EAER,KAAK,GACN,MAAM,oBAAoB,CAAC;AAE5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C;IAC/C,MAAM,KAAK,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAE9C,OAAO;QACL,UAAU;QACV,IAAI;QACJ,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["// 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"]}
package/package.json ADDED
@@ -0,0 +1,135 @@
1
+ {
2
+ "name": "@azure/opentelemetry-instrumentation-azure-sdk",
3
+ "version": "1.0.0-alpha.20220118.2",
4
+ "description": "Instrumentation client for the Azure SDK.",
5
+ "sdk-type": "client",
6
+ "main": "dist/index.js",
7
+ "module": "dist-esm/src/index.js",
8
+ "browser": {
9
+ "./dist-esm/src/instrumentation.js": "./dist-esm/src/instrumentation.browser.js"
10
+ },
11
+ "//metadata": {
12
+ "constantPaths": [
13
+ {
14
+ "path": "src/constants.ts",
15
+ "prefix": "SDK_VERSION"
16
+ }
17
+ ]
18
+ },
19
+ "types": "types/latest/opentelemetry-instrumentation-azure-sdk.d.ts",
20
+ "typesVersions": {
21
+ "<3.6": {
22
+ "*": [
23
+ "types/3.1/opentelemetry-instrumentation-azure-sdk.d.ts"
24
+ ]
25
+ }
26
+ },
27
+ "scripts": {
28
+ "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
29
+ "build:samples": "echo Obsolete",
30
+ "build:test": "tsc -p . && rollup -c 2>&1",
31
+ "build:types": "downlevel-dts types/latest/ types/3.1/",
32
+ "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local && npm run build:types",
33
+ "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
34
+ "clean": "rimraf dist dist-* temp types *.tgz *.log",
35
+ "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src",
36
+ "execute:samples": "dev-tool samples run samples-dev",
37
+ "extract-api": "tsc -p . && api-extractor run --local",
38
+ "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
39
+ "generate:client": "autorest --typescript ./swagger/README.md",
40
+ "integration-test:browser": "karma start --single-run",
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
+ "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",
45
+ "pack": "npm pack 2>&1",
46
+ "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
47
+ "test:node": "npm run clean && tsc -p . && npm run unit-test:node && npm run integration-test:node",
48
+ "test": "npm run clean && tsc -p . && npm run unit-test:node && rollup -c 2>&1 && npm run unit-test:browser && npm run integration-test",
49
+ "unit-test:browser": "karma start --single-run",
50
+ "unit-test:node": "mocha -r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace --exclude \"test/**/browser/*.spec.ts\" \"test/**/*.spec.ts\"",
51
+ "unit-test": "npm run unit-test:node && npm run unit-test:browser"
52
+ },
53
+ "files": [
54
+ "dist/",
55
+ "dist-esm/src/",
56
+ "types/latest/",
57
+ "types/3.1/",
58
+ "README.md",
59
+ "LICENSE"
60
+ ],
61
+ "repository": "github:Azure/azure-sdk-for-js",
62
+ "engines": {
63
+ "node": ">=12.0.0"
64
+ },
65
+ "keywords": [
66
+ "azure",
67
+ "cloud",
68
+ "tracing",
69
+ "typescript"
70
+ ],
71
+ "author": "Microsoft Corporation",
72
+ "license": "MIT",
73
+ "bugs": {
74
+ "url": "https://github.com/Azure/azure-sdk-for-js/issues"
75
+ },
76
+ "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/instrumentation/opentelemetry-instrumentation-azure-sdk/README.md",
77
+ "sideEffects": false,
78
+ "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
79
+ "dependencies": {
80
+ "@azure/core-tracing": ">=1.0.0-alpha <1.0.0-alphb",
81
+ "@azure/logger": "^1.0.0",
82
+ "@opentelemetry/api": "^1.0.3",
83
+ "@opentelemetry/core": "^1.0.1",
84
+ "@opentelemetry/instrumentation": "^0.27.0",
85
+ "tslib": "^2.2.0"
86
+ },
87
+ "devDependencies": {
88
+ "@azure-tools/test-recorder": "^1.0.0",
89
+ "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
90
+ "@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
91
+ "@microsoft/api-extractor": "^7.18.11",
92
+ "@types/chai": "^4.1.6",
93
+ "@types/mocha": "^7.0.2",
94
+ "@types/node": "^12.0.0",
95
+ "@types/sinon": "^10.0.6",
96
+ "chai": "^4.2.0",
97
+ "cross-env": "^7.0.2",
98
+ "dotenv": "^8.2.0",
99
+ "downlevel-dts": "~0.4.0",
100
+ "eslint": "^7.15.0",
101
+ "esm": "^3.2.18",
102
+ "inherits": "^2.0.3",
103
+ "karma": "^6.2.0",
104
+ "karma-chrome-launcher": "^3.0.0",
105
+ "karma-coverage": "^2.0.0",
106
+ "karma-edge-launcher": "^0.4.2",
107
+ "karma-env-preprocessor": "^0.1.1",
108
+ "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
+ "karma-junit-reporter": "^2.0.1",
113
+ "karma-mocha": "^2.0.1",
114
+ "karma-mocha-reporter": "^2.2.5",
115
+ "mocha": "^7.1.1",
116
+ "mocha-junit-reporter": "^1.18.0",
117
+ "nyc": "^14.0.0",
118
+ "prettier": "^2.5.1",
119
+ "rimraf": "^3.0.0",
120
+ "rollup": "^1.16.3",
121
+ "sinon": "^12.0.1",
122
+ "source-map-support": "^0.5.9",
123
+ "typedoc": "0.15.2",
124
+ "typescript": "~4.2.0",
125
+ "util": "^0.12.1"
126
+ },
127
+ "//sampleConfiguration": {
128
+ "skipFolder": true,
129
+ "disableDocsMs": true,
130
+ "productName": "Azure OpenTelemetry Instrumentation",
131
+ "productSlugs": [],
132
+ "apiRefLink": "https://docs.microsoft.com/javascript/api/",
133
+ "requiredResources": {}
134
+ }
135
+ }
@@ -0,0 +1,33 @@
1
+ import { AzureLogger } from '@azure/logger';
2
+ import { Instrumentation } from '@opentelemetry/instrumentation';
3
+ import { InstrumentationConfig } from '@opentelemetry/instrumentation';
4
+ /**
5
+ * Configuration options that can be passed to {@link createAzureSdkInstrumentation} function.
6
+ */
7
+ export declare interface AzureSdkInstrumentationOptions extends InstrumentationConfig {
8
+ }
9
+ /**
10
+ * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
11
+ *
12
+ * When registerd, any Azure data plane package will begin emitting tracing spans for internal calls
13
+ * as well as network calls
14
+ *
15
+ * Example usage:
16
+ * ```ts
17
+ * const openTelemetryInstrumentation = require("@opentelemetry/instrumentation");
18
+ * openTelemetryInstrumentation.registerInstrumentations({
19
+ * instrumentations: [createAzureSdkInstrumentation()],
20
+ * })
21
+ * ```
22
+ *
23
+ * @remarks
24
+ *
25
+ * As OpenTelemetry instrumentations rely on patching required modules, you should register
26
+ * this instrumentation as early as possible and before loading any Azure Client Libraries.
27
+ */
28
+ export declare function createAzureSdkInstrumentation(options?: AzureSdkInstrumentationOptions): Instrumentation;
29
+ /**
30
+ * The \@azure/logger configuration for this package.
31
+ */
32
+ export declare const logger: AzureLogger;
33
+ export {};
@@ -0,0 +1,37 @@
1
+ import { AzureLogger } from '@azure/logger';
2
+ import { Instrumentation } from '@opentelemetry/instrumentation';
3
+ import { InstrumentationConfig } from '@opentelemetry/instrumentation';
4
+
5
+ /**
6
+ * Configuration options that can be passed to {@link createAzureSdkInstrumentation} function.
7
+ */
8
+ export declare interface AzureSdkInstrumentationOptions extends InstrumentationConfig {
9
+ }
10
+
11
+ /**
12
+ * Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
13
+ *
14
+ * When registerd, any Azure data plane package will begin emitting tracing spans for internal calls
15
+ * as well as network calls
16
+ *
17
+ * Example usage:
18
+ * ```ts
19
+ * const openTelemetryInstrumentation = require("@opentelemetry/instrumentation");
20
+ * openTelemetryInstrumentation.registerInstrumentations({
21
+ * instrumentations: [createAzureSdkInstrumentation()],
22
+ * })
23
+ * ```
24
+ *
25
+ * @remarks
26
+ *
27
+ * As OpenTelemetry instrumentations rely on patching required modules, you should register
28
+ * this instrumentation as early as possible and before loading any Azure Client Libraries.
29
+ */
30
+ export declare function createAzureSdkInstrumentation(options?: AzureSdkInstrumentationOptions): Instrumentation;
31
+
32
+ /**
33
+ * The \@azure/logger configuration for this package.
34
+ */
35
+ export declare const logger: AzureLogger;
36
+
37
+ export { }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.19.4"
9
+ }
10
+ ]
11
+ }