@azure/opentelemetry-instrumentation-azure-sdk 1.0.0-beta.5 → 1.0.0-beta.7
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 +7 -2
- package/dist/browser/configuration.d.ts +21 -0
- package/dist/browser/configuration.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/configuration.js +2 -2
- package/dist/browser/configuration.js.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +5 -0
- package/{dist-esm/src → dist/browser}/index.js.map +1 -1
- package/dist/browser/instrumentation-browser.d.mts.map +1 -0
- package/dist/browser/instrumentation-browser.mjs.map +1 -0
- package/dist/browser/instrumentation.d.ts +35 -0
- package/{dist-esm/src/instrumentation.browser.js → dist/browser/instrumentation.js} +5 -5
- package/dist/browser/instrumenter.d.ts +13 -0
- package/dist/browser/instrumenter.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/instrumenter.js +4 -4
- package/dist/browser/instrumenter.js.map +1 -0
- package/dist/browser/logger.d.ts +5 -0
- package/dist/browser/logger.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/logger.js +1 -1
- package/{dist-esm/src → dist/browser}/logger.js.map +1 -1
- package/dist/browser/package.json +3 -0
- package/dist/browser/spanWrapper.d.ts +20 -0
- package/dist/browser/spanWrapper.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/spanWrapper.js +6 -2
- package/dist/browser/spanWrapper.js.map +1 -0
- package/dist/browser/transformations.d.ts +29 -0
- package/dist/browser/transformations.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/transformations.js +4 -19
- package/dist/browser/transformations.js.map +1 -0
- package/dist/commonjs/configuration.d.ts +21 -0
- package/dist/commonjs/configuration.d.ts.map +1 -0
- package/dist/commonjs/configuration.js +35 -0
- package/dist/commonjs/configuration.js.map +1 -0
- package/dist/commonjs/index.d.ts +3 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +8 -0
- package/dist/commonjs/index.js.map +1 -0
- package/{types/3.1/opentelemetry-instrumentation-azure-sdk.d.ts → dist/commonjs/instrumentation.d.ts} +39 -33
- package/dist/commonjs/instrumentation.d.ts.map +1 -0
- package/dist/commonjs/instrumentation.js +57 -0
- package/dist/commonjs/instrumentation.js.map +1 -0
- package/dist/commonjs/instrumenter.d.ts +13 -0
- package/dist/commonjs/instrumenter.d.ts.map +1 -0
- package/dist/commonjs/instrumenter.js +51 -0
- package/dist/commonjs/instrumenter.js.map +1 -0
- package/dist/commonjs/logger.d.ts +5 -0
- package/dist/commonjs/logger.d.ts.map +1 -0
- package/dist/commonjs/logger.js +11 -0
- package/dist/commonjs/logger.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/spanWrapper.d.ts +20 -0
- package/dist/commonjs/spanWrapper.d.ts.map +1 -0
- package/dist/commonjs/spanWrapper.js +54 -0
- package/dist/commonjs/spanWrapper.js.map +1 -0
- package/dist/commonjs/transformations.d.ts +29 -0
- package/dist/commonjs/transformations.d.ts.map +1 -0
- package/dist/commonjs/transformations.js +55 -0
- package/dist/commonjs/transformations.js.map +1 -0
- package/{types/latest → dist/commonjs}/tsdoc-metadata.json +1 -1
- package/dist/esm/configuration.d.ts +21 -0
- package/dist/esm/configuration.d.ts.map +1 -0
- package/dist/esm/configuration.js +31 -0
- package/dist/esm/configuration.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/instrumentation.d.ts +39 -0
- package/dist/esm/instrumentation.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/instrumentation.js +4 -4
- package/dist/esm/instrumentation.js.map +1 -0
- package/dist/esm/instrumenter.d.ts +13 -0
- package/dist/esm/instrumenter.d.ts.map +1 -0
- package/dist/esm/instrumenter.js +47 -0
- package/dist/esm/instrumenter.js.map +1 -0
- package/dist/esm/logger.d.ts +5 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +8 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/spanWrapper.d.ts +20 -0
- package/dist/esm/spanWrapper.d.ts.map +1 -0
- package/dist/esm/spanWrapper.js +50 -0
- package/dist/esm/spanWrapper.js.map +1 -0
- package/dist/esm/transformations.d.ts +29 -0
- package/dist/esm/transformations.d.ts.map +1 -0
- package/dist/esm/transformations.js +51 -0
- package/dist/esm/transformations.js.map +1 -0
- package/dist/react-native/configuration.d.ts +21 -0
- package/dist/react-native/configuration.d.ts.map +1 -0
- package/dist/react-native/configuration.js +31 -0
- package/dist/react-native/configuration.js.map +1 -0
- package/dist/react-native/index.d.ts +3 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +5 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/instrumentation.d.ts +39 -0
- package/dist/react-native/instrumentation.d.ts.map +1 -0
- package/dist/react-native/instrumentation.js +52 -0
- package/dist/react-native/instrumentation.js.map +1 -0
- package/dist/react-native/instrumenter.d.ts +13 -0
- package/dist/react-native/instrumenter.d.ts.map +1 -0
- package/dist/react-native/instrumenter.js +47 -0
- package/dist/react-native/instrumenter.js.map +1 -0
- package/dist/react-native/logger.d.ts +5 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +8 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/spanWrapper.d.ts +20 -0
- package/dist/react-native/spanWrapper.d.ts.map +1 -0
- package/dist/react-native/spanWrapper.js +50 -0
- package/dist/react-native/spanWrapper.js.map +1 -0
- package/dist/react-native/transformations.d.ts +29 -0
- package/dist/react-native/transformations.d.ts.map +1 -0
- package/dist/react-native/transformations.js +51 -0
- package/dist/react-native/transformations.js.map +1 -0
- package/package.json +75 -67
- package/types/latest/opentelemetry-instrumentation-azure-sdk.d.ts +15 -0
- package/dist/index.js +0 -246
- package/dist/index.js.map +0 -1
- package/dist-esm/src/configuration.js.map +0 -1
- package/dist-esm/src/index.js +0 -5
- package/dist-esm/src/instrumentation.browser.js.map +0 -1
- package/dist-esm/src/instrumentation.js.map +0 -1
- package/dist-esm/src/instrumenter.js.map +0 -1
- package/dist-esm/src/spanWrapper.js.map +0 -1
- package/dist-esm/src/transformations.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { SpanKind, trace } from "@opentelemetry/api";
|
|
4
|
+
import { sanitizeAttributes } from "@opentelemetry/core";
|
|
5
|
+
/**
|
|
6
|
+
* Converts our TracingSpanKind to the corresponding OpenTelemetry SpanKind.
|
|
7
|
+
*
|
|
8
|
+
* By default it will return {@link SpanKind.INTERNAL}
|
|
9
|
+
* @param tracingSpanKind - The core tracing {@link TracingSpanKind}
|
|
10
|
+
* @returns - The OpenTelemetry {@link SpanKind}
|
|
11
|
+
*/
|
|
12
|
+
export function toOpenTelemetrySpanKind(tracingSpanKind) {
|
|
13
|
+
const key = (tracingSpanKind || "internal").toUpperCase();
|
|
14
|
+
return SpanKind[key];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts core-tracing's TracingSpanLink to OpenTelemetry's Link
|
|
18
|
+
*
|
|
19
|
+
* @param spanLinks - The core tracing {@link TracingSpanLink} to convert
|
|
20
|
+
* @returns A set of {@link Link}s
|
|
21
|
+
*/
|
|
22
|
+
function toOpenTelemetryLinks(spanLinks = []) {
|
|
23
|
+
return spanLinks.reduce((acc, tracingSpanLink) => {
|
|
24
|
+
const spanContext = trace.getSpanContext(tracingSpanLink.tracingContext);
|
|
25
|
+
if (spanContext) {
|
|
26
|
+
acc.push({
|
|
27
|
+
context: spanContext,
|
|
28
|
+
attributes: sanitizeAttributes(tracingSpanLink.attributes),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return acc;
|
|
32
|
+
}, []);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts core-tracing span options to OpenTelemetry options.
|
|
36
|
+
*
|
|
37
|
+
* @param spanOptions - The {@link InstrumenterSpanOptions} to convert.
|
|
38
|
+
* @returns An OpenTelemetry {@link SpanOptions} that can be used when creating a span.
|
|
39
|
+
*/
|
|
40
|
+
export function toSpanOptions(spanOptions) {
|
|
41
|
+
const { spanAttributes, spanLinks, spanKind } = spanOptions || {};
|
|
42
|
+
const attributes = sanitizeAttributes(spanAttributes);
|
|
43
|
+
const kind = toOpenTelemetrySpanKind(spanKind);
|
|
44
|
+
const links = toOpenTelemetryLinks(spanLinks);
|
|
45
|
+
return {
|
|
46
|
+
attributes,
|
|
47
|
+
kind,
|
|
48
|
+
links,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# 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,EAAQ,QAAQ,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,eAAmB;IAEnB,MAAM,GAAG,GAAG,CAAC,eAAe,IAAI,UAAU,CAAC,CAAC,WAAW,EAA2B,CAAC;IACnF,OAAO,QAAQ,CAAC,GAAG,CAAuB,CAAC;AAC7C,CAAC;AAaD;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,YAA+B,EAAE;IAC7D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,EAAE;QAC/C,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QACzE,IAAI,WAAW,EAAE,CAAC;YAChB,GAAG,CAAC,IAAI,CAAC;gBACP,OAAO,EAAE,WAAW;gBACpB,UAAU,EAAE,kBAAkB,CAAC,eAAe,CAAC,UAAU,CAAC;aAC3D,CAAC,CAAC;QACL,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAY,CAAC,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,WAAqC;IACjE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,WAAW,IAAI,EAAE,CAAC;IAElE,MAAM,UAAU,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;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 { Link, SpanKind, SpanOptions, trace } from \"@opentelemetry/api\";\nimport { sanitizeAttributes } from \"@opentelemetry/core\";\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: sanitizeAttributes(tracingSpanLink.attributes),\n });\n }\n return acc;\n }, [] as Link[]);\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 = sanitizeAttributes(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
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/opentelemetry-instrumentation-azure-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.7",
|
|
4
4
|
"description": "Instrumentation client for the Azure SDK.",
|
|
5
5
|
"sdk-type": "client",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/commonjs/index.js",
|
|
8
|
+
"module": "./dist/esm/index.js",
|
|
9
|
+
"browser": "dist/browser/index.js",
|
|
10
|
+
"react-native": "dist/react-native/index.js",
|
|
12
11
|
"//metadata": {
|
|
13
12
|
"constantPaths": [
|
|
14
13
|
{
|
|
@@ -17,50 +16,42 @@
|
|
|
17
16
|
}
|
|
18
17
|
]
|
|
19
18
|
},
|
|
20
|
-
"types": "
|
|
21
|
-
"typesVersions": {
|
|
22
|
-
"<3.6": {
|
|
23
|
-
"*": [
|
|
24
|
-
"types/3.1/opentelemetry-instrumentation-azure-sdk.d.ts"
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
},
|
|
19
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
28
20
|
"scripts": {
|
|
29
21
|
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
|
|
22
|
+
"build": "npm run clean && dev-tool run build-package && dev-tool run extract-api",
|
|
30
23
|
"build:samples": "echo Obsolete",
|
|
31
|
-
"build:test": "
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
35
|
-
"clean": "rimraf dist dist-* temp types *.tgz *.log",
|
|
24
|
+
"build:test": "echo skipped. actual commands inlined in browser test scripts",
|
|
25
|
+
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
26
|
+
"clean": "rimraf --glob dist dist-* temp types *.tgz *.log",
|
|
36
27
|
"execute:samples": "dev-tool samples run samples-dev",
|
|
37
|
-
"extract-api": "
|
|
38
|
-
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
28
|
+
"extract-api": "dev-tool run build-package && dev-tool run extract-api",
|
|
29
|
+
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
|
39
30
|
"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
31
|
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
32
|
+
"integration-test:browser": "echo skipped",
|
|
33
|
+
"integration-test:node": "echo skipped",
|
|
34
|
+
"lint": "eslint package.json api-extractor.json README.md src test",
|
|
35
|
+
"lint:fix": "eslint package.json api-extractor.json README.md src test --fix --fix-type [problem,suggestion]",
|
|
45
36
|
"pack": "npm pack 2>&1",
|
|
37
|
+
"test": "npm run clean && dev-tool run build-package && npm run unit-test:node && dev-tool run bundle && npm run unit-test:browser && npm run integration-test",
|
|
46
38
|
"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 &&
|
|
48
|
-
"test": "npm run
|
|
49
|
-
"unit-test:browser": "
|
|
50
|
-
"unit-test:node": "
|
|
51
|
-
"
|
|
39
|
+
"test:node": "npm run clean && dev-tool run build-package && npm run unit-test:node && npm run integration-test:node",
|
|
40
|
+
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
|
41
|
+
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --no-test-proxy --browser",
|
|
42
|
+
"unit-test:node": "dev-tool run test:vitest --no-test-proxy",
|
|
43
|
+
"update-snippets": "echo skipped"
|
|
52
44
|
},
|
|
53
45
|
"files": [
|
|
54
46
|
"dist/",
|
|
55
47
|
"dist-esm/src/",
|
|
56
48
|
"types/latest/",
|
|
57
|
-
"types/3.1/",
|
|
58
49
|
"README.md",
|
|
59
50
|
"LICENSE"
|
|
60
51
|
],
|
|
61
52
|
"repository": "github:Azure/azure-sdk-for-js",
|
|
62
53
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
54
|
+
"node": ">=18.0.0"
|
|
64
55
|
},
|
|
65
56
|
"keywords": [
|
|
66
57
|
"azure",
|
|
@@ -77,48 +68,29 @@
|
|
|
77
68
|
"sideEffects": false,
|
|
78
69
|
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
|
|
79
70
|
"dependencies": {
|
|
80
|
-
"@azure/core-tracing": "^1.
|
|
71
|
+
"@azure/core-tracing": "^1.2.0",
|
|
81
72
|
"@azure/logger": "^1.0.0",
|
|
82
|
-
"@opentelemetry/api": "^1.
|
|
83
|
-
"@opentelemetry/core": "^1.
|
|
84
|
-
"@opentelemetry/instrumentation": "^0.
|
|
85
|
-
"tslib": "^2.
|
|
73
|
+
"@opentelemetry/api": "^1.9.0",
|
|
74
|
+
"@opentelemetry/core": "^1.26.0",
|
|
75
|
+
"@opentelemetry/instrumentation": "^0.53.0",
|
|
76
|
+
"tslib": "^2.7.0"
|
|
86
77
|
},
|
|
87
78
|
"devDependencies": {
|
|
88
79
|
"@azure/core-rest-pipeline": "^1.5.1",
|
|
89
80
|
"@azure/dev-tool": "^1.0.0",
|
|
90
81
|
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
91
82
|
"@microsoft/api-extractor": "^7.31.1",
|
|
92
|
-
"@opentelemetry/sdk-trace-base": "^1.
|
|
93
|
-
"@opentelemetry/sdk-trace-node": "^1.
|
|
94
|
-
"@types/
|
|
95
|
-
"@
|
|
96
|
-
"@
|
|
97
|
-
"@types/sinon": "^10.0.0",
|
|
98
|
-
"chai": "^4.2.0",
|
|
99
|
-
"cross-env": "^7.0.2",
|
|
83
|
+
"@opentelemetry/sdk-trace-base": "^1.26.0",
|
|
84
|
+
"@opentelemetry/sdk-trace-node": "^1.26.0",
|
|
85
|
+
"@types/node": "^18.0.0",
|
|
86
|
+
"@vitest/browser": "^2.1.1",
|
|
87
|
+
"@vitest/coverage-istanbul": "^2.1.1",
|
|
100
88
|
"dotenv": "^16.0.0",
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"karma-chrome-launcher": "^3.0.0",
|
|
107
|
-
"karma-coverage": "^2.0.0",
|
|
108
|
-
"karma-env-preprocessor": "^0.1.1",
|
|
109
|
-
"karma-firefox-launcher": "^1.1.0",
|
|
110
|
-
"karma-junit-reporter": "^2.0.1",
|
|
111
|
-
"karma-mocha": "^2.0.1",
|
|
112
|
-
"karma-mocha-reporter": "^2.2.5",
|
|
113
|
-
"mocha": "^7.1.1",
|
|
114
|
-
"mocha-junit-reporter": "^1.18.0",
|
|
115
|
-
"nyc": "^15.0.0",
|
|
116
|
-
"prettier": "^2.5.1",
|
|
117
|
-
"rimraf": "^3.0.0",
|
|
118
|
-
"sinon": "^15.0.0",
|
|
119
|
-
"source-map-support": "^0.5.9",
|
|
120
|
-
"typescript": "~5.0.0",
|
|
121
|
-
"util": "^0.12.1"
|
|
89
|
+
"eslint": "^9.9.0",
|
|
90
|
+
"playwright": "^1.47.2",
|
|
91
|
+
"rimraf": "^5.0.5",
|
|
92
|
+
"typescript": "~5.6.2",
|
|
93
|
+
"vitest": "^2.1.1"
|
|
122
94
|
},
|
|
123
95
|
"//sampleConfiguration": {
|
|
124
96
|
"skipFolder": true,
|
|
@@ -127,5 +99,41 @@
|
|
|
127
99
|
"productSlugs": [],
|
|
128
100
|
"apiRefLink": "https://docs.microsoft.com/javascript/api/",
|
|
129
101
|
"requiredResources": {}
|
|
102
|
+
},
|
|
103
|
+
"tshy": {
|
|
104
|
+
"exports": {
|
|
105
|
+
"./package.json": "./package.json",
|
|
106
|
+
".": "./src/index.ts"
|
|
107
|
+
},
|
|
108
|
+
"dialects": [
|
|
109
|
+
"esm",
|
|
110
|
+
"commonjs"
|
|
111
|
+
],
|
|
112
|
+
"esmDialects": [
|
|
113
|
+
"browser",
|
|
114
|
+
"react-native"
|
|
115
|
+
],
|
|
116
|
+
"selfLink": false
|
|
117
|
+
},
|
|
118
|
+
"exports": {
|
|
119
|
+
"./package.json": "./package.json",
|
|
120
|
+
".": {
|
|
121
|
+
"browser": {
|
|
122
|
+
"types": "./dist/browser/index.d.ts",
|
|
123
|
+
"default": "./dist/browser/index.js"
|
|
124
|
+
},
|
|
125
|
+
"react-native": {
|
|
126
|
+
"types": "./dist/react-native/index.d.ts",
|
|
127
|
+
"default": "./dist/react-native/index.js"
|
|
128
|
+
},
|
|
129
|
+
"import": {
|
|
130
|
+
"types": "./dist/esm/index.d.ts",
|
|
131
|
+
"default": "./dist/esm/index.js"
|
|
132
|
+
},
|
|
133
|
+
"require": {
|
|
134
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
135
|
+
"default": "./dist/commonjs/index.js"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
130
138
|
}
|
|
131
139
|
}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { AzureLogger } from '@azure/logger';
|
|
2
2
|
import { Instrumentation } from '@opentelemetry/instrumentation';
|
|
3
|
+
import { InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
3
4
|
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
|
|
5
|
+
import { InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AzureSdkInstrumentation extends InstrumentationBase {
|
|
11
|
+
constructor(options?: AzureSdkInstrumentationOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Entrypoint for the module registration.
|
|
14
|
+
*
|
|
15
|
+
* @returns The patched \@azure/core-tracing module after setting its instrumenter.
|
|
16
|
+
*/
|
|
17
|
+
protected init(): void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[];
|
|
18
|
+
}
|
|
4
19
|
|
|
5
20
|
/**
|
|
6
21
|
* Configuration options that can be passed to {@link createAzureSdkInstrumentation} function.
|
package/dist/index.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
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
|
-
// Licensed under the MIT license.
|
|
62
|
-
const SDK_VERSION = "1.0.0-beta.5";
|
|
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
|
-
|
|
91
|
-
// Copyright (c) Microsoft Corporation.
|
|
92
|
-
/**
|
|
93
|
-
* Converts our TracingSpanKind to the corresponding OpenTelemetry SpanKind.
|
|
94
|
-
*
|
|
95
|
-
* By default it will return {@link SpanKind.INTERNAL}
|
|
96
|
-
* @param tracingSpanKind - The core tracing {@link TracingSpanKind}
|
|
97
|
-
* @returns - The OpenTelemetry {@link SpanKind}
|
|
98
|
-
*/
|
|
99
|
-
function toOpenTelemetrySpanKind(tracingSpanKind) {
|
|
100
|
-
const key = (tracingSpanKind || "internal").toUpperCase();
|
|
101
|
-
return api.SpanKind[key];
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Converts core-tracing's TracingSpanLink to OpenTelemetry's Link
|
|
105
|
-
*
|
|
106
|
-
* @param spanLinks - The core tracing {@link TracingSpanLink} to convert
|
|
107
|
-
* @returns A set of {@link Link}s
|
|
108
|
-
*/
|
|
109
|
-
function toOpenTelemetryLinks(spanLinks = []) {
|
|
110
|
-
return spanLinks.reduce((acc, tracingSpanLink) => {
|
|
111
|
-
const spanContext = api.trace.getSpanContext(tracingSpanLink.tracingContext);
|
|
112
|
-
if (spanContext) {
|
|
113
|
-
acc.push({
|
|
114
|
-
context: spanContext,
|
|
115
|
-
attributes: toOpenTelemetrySpanAttributes(tracingSpanLink.attributes),
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return acc;
|
|
119
|
-
}, []);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Converts core-tracing's span attributes to OpenTelemetry attributes.
|
|
123
|
-
*
|
|
124
|
-
* @param spanAttributes - The set of attributes to convert.
|
|
125
|
-
* @returns An {@link SpanAttributes} to set on a span.
|
|
126
|
-
*/
|
|
127
|
-
function toOpenTelemetrySpanAttributes(spanAttributes) {
|
|
128
|
-
const attributes = {};
|
|
129
|
-
for (const key in spanAttributes) {
|
|
130
|
-
// Any non-nullish value is allowed.
|
|
131
|
-
if (spanAttributes[key] !== null && spanAttributes[key] !== undefined) {
|
|
132
|
-
attributes[key] = spanAttributes[key];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return attributes;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Converts core-tracing span options to OpenTelemetry options.
|
|
139
|
-
*
|
|
140
|
-
* @param spanOptions - The {@link InstrumenterSpanOptions} to convert.
|
|
141
|
-
* @returns An OpenTelemetry {@link SpanOptions} that can be used when creating a span.
|
|
142
|
-
*/
|
|
143
|
-
function toSpanOptions(spanOptions) {
|
|
144
|
-
const { spanAttributes, spanLinks, spanKind } = spanOptions || {};
|
|
145
|
-
const attributes = toOpenTelemetrySpanAttributes(spanAttributes);
|
|
146
|
-
const kind = toOpenTelemetrySpanKind(spanKind);
|
|
147
|
-
const links = toOpenTelemetryLinks(spanLinks);
|
|
148
|
-
return {
|
|
149
|
-
attributes,
|
|
150
|
-
kind,
|
|
151
|
-
links,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Copyright (c) Microsoft Corporation.
|
|
156
|
-
// While default propagation is user-configurable, Azure services always use the W3C implementation.
|
|
157
|
-
const propagator = new core.W3CTraceContextPropagator();
|
|
158
|
-
class OpenTelemetryInstrumenter {
|
|
159
|
-
startSpan(name, spanOptions) {
|
|
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
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
span: new OpenTelemetrySpanWrapper(span),
|
|
179
|
-
tracingContext: api.trace.setSpan(ctx, span),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
withContext(tracingContext, callback, ...callbackArgs) {
|
|
183
|
-
return api.context.with(tracingContext, callback,
|
|
184
|
-
/** Assume caller will bind `this` or use arrow functions */ undefined, ...callbackArgs);
|
|
185
|
-
}
|
|
186
|
-
parseTraceparentHeader(traceparentHeader) {
|
|
187
|
-
return propagator.extract(api.context.active(), { traceparent: traceparentHeader }, api.defaultTextMapGetter);
|
|
188
|
-
}
|
|
189
|
-
createRequestHeaders(tracingContext) {
|
|
190
|
-
const headers = {};
|
|
191
|
-
propagator.inject(tracingContext || api.context.active(), headers, api.defaultTextMapSetter);
|
|
192
|
-
return headers;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Copyright (c) Microsoft Corporation.
|
|
197
|
-
/**
|
|
198
|
-
* The instrumentation module for the Azure SDK. Implements OpenTelemetry's {@link Instrumentation}.
|
|
199
|
-
*/
|
|
200
|
-
class AzureSdkInstrumentation extends instrumentation.InstrumentationBase {
|
|
201
|
-
constructor(options = {}) {
|
|
202
|
-
super("@azure/opentelemetry-instrumentation-azure-sdk", SDK_VERSION, Object.assign({}, options));
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Entrypoint for the module registration.
|
|
206
|
-
*
|
|
207
|
-
* @returns The patched \@azure/core-tracing module after setting its instrumenter.
|
|
208
|
-
*/
|
|
209
|
-
init() {
|
|
210
|
-
const result = new instrumentation.InstrumentationNodeModuleDefinition("@azure/core-tracing", ["^1.0.0-preview.14", "^1.0.0"], (moduleExports) => {
|
|
211
|
-
if (typeof moduleExports.useInstrumenter === "function") {
|
|
212
|
-
moduleExports.useInstrumenter(new OpenTelemetryInstrumenter());
|
|
213
|
-
}
|
|
214
|
-
return moduleExports;
|
|
215
|
-
});
|
|
216
|
-
// Needed to support 1.0.0-preview.14
|
|
217
|
-
result.includePrerelease = true;
|
|
218
|
-
return result;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Enables Azure SDK Instrumentation using OpenTelemetry for Azure SDK client libraries.
|
|
223
|
-
*
|
|
224
|
-
* When registered, any Azure data plane package will begin emitting tracing spans for internal calls
|
|
225
|
-
* as well as network calls
|
|
226
|
-
*
|
|
227
|
-
* Example usage:
|
|
228
|
-
* ```ts
|
|
229
|
-
* const openTelemetryInstrumentation = require("@opentelemetry/instrumentation");
|
|
230
|
-
* openTelemetryInstrumentation.registerInstrumentations({
|
|
231
|
-
* instrumentations: [createAzureSdkInstrumentation()],
|
|
232
|
-
* })
|
|
233
|
-
* ```
|
|
234
|
-
*
|
|
235
|
-
* @remarks
|
|
236
|
-
*
|
|
237
|
-
* As OpenTelemetry instrumentations rely on patching required modules, you should register
|
|
238
|
-
* this instrumentation as early as possible and before loading any Azure Client Libraries.
|
|
239
|
-
*/
|
|
240
|
-
function createAzureSdkInstrumentation(options = {}) {
|
|
241
|
-
return new AzureSdkInstrumentation(options);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
exports.createAzureSdkInstrumentation = createAzureSdkInstrumentation;
|
|
245
|
-
exports.logger = logger;
|
|
246
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/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, AttributeValue, 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 AttributeValue);\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.5\";\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 { Attributes, AttributeValue, Link, SpanKind, SpanOptions, trace } 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): Attributes {\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 AttributeValue;\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: Attributes = 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_CONTEXT","suppressTracing","defaultTextMapGetter","defaultTextMapSetter","InstrumentationBase","InstrumentationNodeModuleDefinition"],"mappings":";;;;;;;;;AAAA;AAKA;;AAEG;MACU,MAAM,GAAGA,2BAAkB,CAAC,yCAAyC;;ACRlF;MAMa,wBAAwB,CAAA;AAGnC,IAAA,WAAA,CAAY,IAAU,EAAA;AACpB,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;KACnB;AAED,IAAA,SAAS,CAAC,MAAkB,EAAA;AAC1B,QAAA,IAAI,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE;YAC7B,IAAI,MAAM,CAAC,KAAK,EAAE;gBAChB,IAAI,CA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C,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.5\";\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"]}
|
package/dist-esm/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,EA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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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spanWrapper.js","sourceRoot":"","sources":["../../src/spanWrapper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAwB,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG1E,MAAM,OAAO,wBAAwB;IAGnC,YAAY,IAAU;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;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,EAAE,cAAc,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,EAAE,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;aACtD;SACF;aAAM,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;YACtC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC;SACnD;IACH,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,KAAc;QACvC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;YACzC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,KAAuB,CAAC,CAAC;SACxD;IACH,CAAC;IAED,GAAG;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,eAAe,CAAC,SAAyB;QACvC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,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, AttributeValue, 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 AttributeValue);\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"]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;IACjE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,WAAW,IAAI,EAAE,CAAC;IAElE,MAAM,UAAU,GAAe,6BAA6B,CAAC,cAAc,CAAC,CAAC;IAC7E,MAAM,IAAI,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;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 { Attributes, AttributeValue, Link, SpanKind, SpanOptions, trace } 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): Attributes {\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 AttributeValue;\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: Attributes = toOpenTelemetrySpanAttributes(spanAttributes);\n const kind = toOpenTelemetrySpanKind(spanKind);\n const links = toOpenTelemetryLinks(spanLinks);\n\n return {\n attributes,\n kind,\n links,\n };\n}\n"]}
|