@opentelemetry/exporter-zipkin 1.30.0 → 2.0.0-dev.0
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/build/esm/platform/browser/util.js +19 -44
- package/build/esm/platform/browser/util.js.map +1 -1
- package/build/esm/platform/node/util.js +19 -28
- package/build/esm/platform/node/util.js.map +1 -1
- package/build/esm/transform.js +19 -43
- package/build/esm/transform.js.map +1 -1
- package/build/esm/types.d.ts +3 -3
- package/build/esm/version.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esm/zipkin.js +43 -43
- package/build/esm/zipkin.js.map +1 -1
- package/build/esnext/platform/browser/util.js +5 -1
- package/build/esnext/platform/browser/util.js.map +1 -1
- package/build/esnext/platform/node/util.js +8 -6
- package/build/esnext/platform/node/util.js.map +1 -1
- package/build/esnext/transform.js +1 -1
- package/build/esnext/transform.js.map +1 -1
- package/build/esnext/types.d.ts +3 -3
- package/build/esnext/version.d.ts +1 -1
- package/build/esnext/version.js +1 -1
- package/build/esnext/version.js.map +1 -1
- package/build/esnext/zipkin.js +14 -4
- package/build/esnext/zipkin.js.map +1 -1
- package/build/src/platform/browser/util.js +5 -1
- package/build/src/platform/browser/util.js.map +1 -1
- package/build/src/platform/node/util.js +8 -6
- package/build/src/platform/node/util.js.map +1 -1
- package/build/src/transform.js +1 -1
- package/build/src/transform.js.map +1 -1
- package/build/src/types.d.ts +3 -3
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/build/src/zipkin.js +13 -3
- package/build/src/zipkin.js.map +1 -1
- package/package.json +17 -18
|
@@ -13,33 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
28
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29
|
-
if (!m) return o;
|
|
30
|
-
var i = m.call(o), r, ar = [], e;
|
|
31
|
-
try {
|
|
32
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
33
|
-
}
|
|
34
|
-
catch (error) { e = { error: error }; }
|
|
35
|
-
finally {
|
|
36
|
-
try {
|
|
37
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
38
|
-
}
|
|
39
|
-
finally { if (e) throw e.error; }
|
|
40
|
-
}
|
|
41
|
-
return ar;
|
|
42
|
-
};
|
|
43
16
|
import { diag } from '@opentelemetry/api';
|
|
44
17
|
import { ExportResultCode, globalErrorHandler, } from '@opentelemetry/core';
|
|
45
18
|
/**
|
|
@@ -49,10 +22,14 @@ import { ExportResultCode, globalErrorHandler, } from '@opentelemetry/core';
|
|
|
49
22
|
* send
|
|
50
23
|
*/
|
|
51
24
|
export function prepareSend(urlStr, headers) {
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
let xhrHeaders;
|
|
26
|
+
const useBeacon = typeof navigator.sendBeacon === 'function' && !headers;
|
|
54
27
|
if (headers) {
|
|
55
|
-
xhrHeaders =
|
|
28
|
+
xhrHeaders = {
|
|
29
|
+
Accept: 'application/json',
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
...headers,
|
|
32
|
+
};
|
|
56
33
|
}
|
|
57
34
|
/**
|
|
58
35
|
* Send spans to the remote Zipkin service.
|
|
@@ -62,7 +39,7 @@ export function prepareSend(urlStr, headers) {
|
|
|
62
39
|
diag.debug('Zipkin send with empty spans');
|
|
63
40
|
return done({ code: ExportResultCode.SUCCESS });
|
|
64
41
|
}
|
|
65
|
-
|
|
42
|
+
const payload = JSON.stringify(zipkinSpans);
|
|
66
43
|
if (useBeacon) {
|
|
67
44
|
sendWithBeacon(payload, done, urlStr);
|
|
68
45
|
}
|
|
@@ -85,7 +62,7 @@ function sendWithBeacon(data, done, urlStr) {
|
|
|
85
62
|
else {
|
|
86
63
|
done({
|
|
87
64
|
code: ExportResultCode.FAILED,
|
|
88
|
-
error: new Error(
|
|
65
|
+
error: new Error(`sendBeacon - cannot send ${data}`),
|
|
89
66
|
});
|
|
90
67
|
}
|
|
91
68
|
}
|
|
@@ -96,35 +73,33 @@ function sendWithBeacon(data, done, urlStr) {
|
|
|
96
73
|
* @param urlStr
|
|
97
74
|
* @param xhrHeaders
|
|
98
75
|
*/
|
|
99
|
-
function sendWithXhr(data, done, urlStr, xhrHeaders) {
|
|
100
|
-
|
|
101
|
-
var xhr = new XMLHttpRequest();
|
|
76
|
+
function sendWithXhr(data, done, urlStr, xhrHeaders = {}) {
|
|
77
|
+
const xhr = new XMLHttpRequest();
|
|
102
78
|
xhr.open('POST', urlStr);
|
|
103
|
-
Object.entries(xhrHeaders).forEach(
|
|
104
|
-
var _b = __read(_a, 2), k = _b[0], v = _b[1];
|
|
79
|
+
Object.entries(xhrHeaders).forEach(([k, v]) => {
|
|
105
80
|
xhr.setRequestHeader(k, v);
|
|
106
81
|
});
|
|
107
|
-
xhr.onreadystatechange =
|
|
82
|
+
xhr.onreadystatechange = () => {
|
|
108
83
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
109
|
-
|
|
110
|
-
diag.debug(
|
|
84
|
+
const statusCode = xhr.status || 0;
|
|
85
|
+
diag.debug(`Zipkin response status code: ${statusCode}, body: ${data}`);
|
|
111
86
|
if (xhr.status >= 200 && xhr.status < 400) {
|
|
112
87
|
return done({ code: ExportResultCode.SUCCESS });
|
|
113
88
|
}
|
|
114
89
|
else {
|
|
115
90
|
return done({
|
|
116
91
|
code: ExportResultCode.FAILED,
|
|
117
|
-
error: new Error(
|
|
92
|
+
error: new Error(`Got unexpected status code from zipkin: ${xhr.status}`),
|
|
118
93
|
});
|
|
119
94
|
}
|
|
120
95
|
}
|
|
121
96
|
};
|
|
122
|
-
xhr.onerror =
|
|
123
|
-
globalErrorHandler(new Error(
|
|
97
|
+
xhr.onerror = msg => {
|
|
98
|
+
globalErrorHandler(new Error(`Zipkin request error: ${msg}`));
|
|
124
99
|
return done({ code: ExportResultCode.FAILED });
|
|
125
100
|
};
|
|
126
101
|
// Issue request to remote service
|
|
127
|
-
diag.debug(
|
|
102
|
+
diag.debug(`Zipkin request payload: ${data}`);
|
|
128
103
|
xhr.send(data);
|
|
129
104
|
}
|
|
130
105
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAEL,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,OAAgC;IAEhC,IAAI,UAAkC,CAAC;IACvC,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,IAAI,CAAC,OAAO,CAAC;IACzE,IAAI,OAAO,EAAE;QACX,UAAU,GAAG;YACX,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;YAClC,GAAG,OAAO;SACX,CAAC;KACH;IAED;;OAEG;IACH,OAAO,SAAS,IAAI,CAClB,WAA+B,EAC/B,IA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gB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,kBAAkB,GAAG,GAAG,EAAE;QAC5B,IAAI,GAAG,CAAC,UAAU,KAAK,cAAc,CAAC,IAAI,EAAE;YAC1C,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,KAAK,CAAC,gCAAgC,UAAU,WAAW,IAAI,EAAE,CAAC,CAAC;YAExE,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE;gBACzC,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;aACjD;iBAAM;gBACL,OAAO,IAAI,CAAC;oBACV,IAAI,EAAE,gBAAgB,CAAC,MAAM;oBAC7B,KAAK,EAAE,IAAI,KAAK,CACd,2CAA2C,GAAG,CAAC,MAAM,EAAE,CACxD;iBACF,CAAC,CAAC;aACJ;SACF;IACH,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,EAAE;QAClB,kBAAkB,CAAC,IAAI,KAAK,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,kCAAkC;IAClC,IAAI,CAAC,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;IAC9C,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { diag } from '@opentelemetry/api';\nimport {\n ExportResult,\n ExportResultCode,\n globalErrorHandler,\n} from '@opentelemetry/core';\nimport * as zipkinTypes from '../../types';\n\n/**\n * Prepares send function that will send spans to the remote Zipkin service.\n * @param urlStr - url to send spans\n * @param headers - headers\n * send\n */\nexport function prepareSend(\n urlStr: string,\n headers?: Record<string, string>\n): zipkinTypes.SendFn {\n let xhrHeaders: Record<string, string>;\n const useBeacon = typeof navigator.sendBeacon === 'function' && !headers;\n if (headers) {\n xhrHeaders = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n ...headers,\n };\n }\n\n /**\n * Send spans to the remote Zipkin service.\n */\n return function send(\n zipkinSpans: zipkinTypes.Span[],\n done: (result: ExportResult) => void\n ) {\n if (zipkinSpans.length === 0) {\n diag.debug('Zipkin send with empty spans');\n return done({ code: ExportResultCode.SUCCESS });\n }\n const payload = JSON.stringify(zipkinSpans);\n if (useBeacon) {\n sendWithBeacon(payload, done, urlStr);\n } else {\n sendWithXhr(payload, done, urlStr, xhrHeaders);\n }\n };\n}\n\n/**\n * Sends data using beacon\n * @param data\n * @param done\n * @param urlStr\n */\nfunction sendWithBeacon(\n data: string,\n done: (result: ExportResult) => void,\n urlStr: string\n) {\n if (navigator.sendBeacon(urlStr, data)) {\n diag.debug('sendBeacon - can send', data);\n done({ code: ExportResultCode.SUCCESS });\n } else {\n done({\n code: ExportResultCode.FAILED,\n error: new Error(`sendBeacon - cannot send ${data}`),\n });\n }\n}\n\n/**\n * Sends data using XMLHttpRequest\n * @param data\n * @param done\n * @param urlStr\n * @param xhrHeaders\n */\nfunction sendWithXhr(\n data: string,\n done: (result: ExportResult) => void,\n urlStr: string,\n xhrHeaders: Record<string, string> = {}\n) {\n const xhr = new XMLHttpRequest();\n xhr.open('POST', urlStr);\n Object.entries(xhrHeaders).forEach(([k, v]) => {\n xhr.setRequestHeader(k, v);\n });\n\n xhr.onreadystatechange = () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n const statusCode = xhr.status || 0;\n diag.debug(`Zipkin response status code: ${statusCode}, body: ${data}`);\n\n if (xhr.status >= 200 && xhr.status < 400) {\n return done({ code: ExportResultCode.SUCCESS });\n } else {\n return done({\n code: ExportResultCode.FAILED,\n error: new Error(\n `Got unexpected status code from zipkin: ${xhr.status}`\n ),\n });\n }\n }\n };\n\n xhr.onerror = msg => {\n globalErrorHandler(new Error(`Zipkin request error: ${msg}`));\n return done({ code: ExportResultCode.FAILED });\n };\n\n // Issue request to remote service\n diag.debug(`Zipkin request payload: ${data}`);\n xhr.send(data);\n}\n"]}
|
|
@@ -13,22 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
16
|
import { diag } from '@opentelemetry/api';
|
|
28
17
|
import { ExportResultCode } from '@opentelemetry/core';
|
|
29
18
|
import * as http from 'http';
|
|
30
19
|
import * as https from 'https';
|
|
31
|
-
import * as url from 'url';
|
|
32
20
|
/**
|
|
33
21
|
* Prepares send function that will send spans to the remote Zipkin service.
|
|
34
22
|
* @param urlStr - url to send spans
|
|
@@ -36,11 +24,14 @@ import * as url from 'url';
|
|
|
36
24
|
* send
|
|
37
25
|
*/
|
|
38
26
|
export function prepareSend(urlStr, headers) {
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
const url = new URL(urlStr);
|
|
28
|
+
const reqOpts = Object.assign({
|
|
41
29
|
method: 'POST',
|
|
42
|
-
headers:
|
|
43
|
-
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
...headers,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
44
35
|
/**
|
|
45
36
|
* Send spans to the remote Zipkin service.
|
|
46
37
|
*/
|
|
@@ -49,15 +40,15 @@ export function prepareSend(urlStr, headers) {
|
|
|
49
40
|
diag.debug('Zipkin send with empty spans');
|
|
50
41
|
return done({ code: ExportResultCode.SUCCESS });
|
|
51
42
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
res.on('data',
|
|
43
|
+
const { request } = url.protocol === 'http:' ? http : https;
|
|
44
|
+
const req = request(url, reqOpts, (res) => {
|
|
45
|
+
let rawData = '';
|
|
46
|
+
res.on('data', chunk => {
|
|
56
47
|
rawData += chunk;
|
|
57
48
|
});
|
|
58
|
-
res.on('end',
|
|
59
|
-
|
|
60
|
-
diag.debug(
|
|
49
|
+
res.on('end', () => {
|
|
50
|
+
const statusCode = res.statusCode || 0;
|
|
51
|
+
diag.debug(`Zipkin response status code: ${statusCode}, body: ${rawData}`);
|
|
61
52
|
// Consider 2xx and 3xx as success.
|
|
62
53
|
if (statusCode < 400) {
|
|
63
54
|
return done({ code: ExportResultCode.SUCCESS });
|
|
@@ -66,20 +57,20 @@ export function prepareSend(urlStr, headers) {
|
|
|
66
57
|
else {
|
|
67
58
|
return done({
|
|
68
59
|
code: ExportResultCode.FAILED,
|
|
69
|
-
error: new Error(
|
|
60
|
+
error: new Error(`Got unexpected status code from zipkin: ${statusCode}`),
|
|
70
61
|
});
|
|
71
62
|
}
|
|
72
63
|
});
|
|
73
64
|
});
|
|
74
|
-
req.on('error',
|
|
65
|
+
req.on('error', error => {
|
|
75
66
|
return done({
|
|
76
67
|
code: ExportResultCode.FAILED,
|
|
77
|
-
error
|
|
68
|
+
error,
|
|
78
69
|
});
|
|
79
70
|
});
|
|
80
71
|
// Issue request to remote service
|
|
81
|
-
|
|
82
|
-
diag.debug(
|
|
72
|
+
const payload = JSON.stringify(zipkinSpans);
|
|
73
|
+
diag.debug(`Zipkin request payload: ${payload}`);
|
|
83
74
|
req.write(payload, 'utf8');
|
|
84
75
|
req.end();
|
|
85
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,OAAgC;IAEhC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAE5B,MAAM,OAAO,GAAwB,MAAM,CAAC,MAAM,CAAC;QACjD,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,GAAG,OAAO;SACX;KACF,CAAC,CAAC;IAEH;;OAEG;IACH,OAAO,SAAS,IAAI,CAClB,WAA+B,EAC/B,IAAoC;QAEpC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAC3C,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,QAAQ,KAAK,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;QAC3B,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { diag } from '@opentelemetry/api';\nimport { ExportResult, ExportResultCode } from '@opentelemetry/core';\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zipkinTypes from '../../types';\n\n/**\n * Prepares send function that will send spans to the remote Zipkin service.\n * @param urlStr - url to send spans\n * @param headers - headers\n * send\n */\nexport function prepareSend(\n urlStr: string,\n headers?: Record<string, string>\n): zipkinTypes.SendFn {\n const url = new URL(urlStr);\n\n const reqOpts: http.RequestOptions = Object.assign({\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n /**\n * Send spans to the remote Zipkin service.\n */\n return function send(\n zipkinSpans: zipkinTypes.Span[],\n done: (result: ExportResult) => void\n ) {\n if (zipkinSpans.length === 0) {\n diag.debug('Zipkin send with empty spans');\n return done({ code: ExportResultCode.SUCCESS });\n }\n\n const { request } = url.protocol === 'http:' ? http : https;\n const req = request(url, reqOpts, (res: http.IncomingMessage) => {\n let rawData = '';\n res.on('data', chunk => {\n rawData += chunk;\n });\n res.on('end', () => {\n const statusCode = res.statusCode || 0;\n diag.debug(\n `Zipkin response status code: ${statusCode}, body: ${rawData}`\n );\n\n // Consider 2xx and 3xx as success.\n if (statusCode < 400) {\n return done({ code: ExportResultCode.SUCCESS });\n // Consider 4xx as failed non-retryable.\n } else {\n return done({\n code: ExportResultCode.FAILED,\n error: new Error(\n `Got unexpected status code from zipkin: ${statusCode}`\n ),\n });\n }\n });\n });\n\n req.on('error', error => {\n return done({\n code: ExportResultCode.FAILED,\n error,\n });\n });\n\n // Issue request to remote service\n const payload = JSON.stringify(zipkinSpans);\n diag.debug(`Zipkin request payload: ${payload}`);\n req.write(payload, 'utf8');\n req.end();\n };\n}\n"]}
|
package/build/esm/transform.js
CHANGED
|
@@ -13,45 +13,33 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
var __values = (this && this.__values) || function(o) {
|
|
17
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
18
|
-
if (m) return m.call(o);
|
|
19
|
-
if (o && typeof o.length === "number") return {
|
|
20
|
-
next: function () {
|
|
21
|
-
if (o && i >= o.length) o = void 0;
|
|
22
|
-
return { value: o && o[i++], done: !o };
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
26
|
-
};
|
|
27
|
-
var _a;
|
|
28
16
|
import * as api from '@opentelemetry/api';
|
|
29
17
|
import { hrTimeToMicroseconds } from '@opentelemetry/core';
|
|
30
18
|
import * as zipkinTypes from './types';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
const ZIPKIN_SPAN_KIND_MAPPING = {
|
|
20
|
+
[api.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,
|
|
21
|
+
[api.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,
|
|
22
|
+
[api.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,
|
|
23
|
+
[api.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,
|
|
36
24
|
// When absent, the span is local.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
export
|
|
25
|
+
[api.SpanKind.INTERNAL]: undefined,
|
|
26
|
+
};
|
|
27
|
+
export const defaultStatusCodeTagName = 'otel.status_code';
|
|
28
|
+
export const defaultStatusErrorTagName = 'error';
|
|
41
29
|
/**
|
|
42
30
|
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
|
|
43
31
|
* @param span Span to be translated
|
|
44
32
|
*/
|
|
45
33
|
export function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTagName) {
|
|
46
|
-
|
|
34
|
+
const zipkinSpan = {
|
|
47
35
|
traceId: span.spanContext().traceId,
|
|
48
|
-
parentId: span.
|
|
36
|
+
parentId: span.parentSpanContext?.spanId,
|
|
49
37
|
name: span.name,
|
|
50
38
|
id: span.spanContext().spanId,
|
|
51
39
|
kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
|
|
52
40
|
timestamp: hrTimeToMicroseconds(span.startTime),
|
|
53
41
|
duration: Math.round(hrTimeToMicroseconds(span.duration)),
|
|
54
|
-
localEndpoint: { serviceName
|
|
42
|
+
localEndpoint: { serviceName },
|
|
55
43
|
tags: _toZipkinTags(span, statusCodeTagName, statusErrorTagName),
|
|
56
44
|
annotations: span.events.length
|
|
57
45
|
? _toZipkinAnnotations(span.events)
|
|
@@ -60,22 +48,10 @@ export function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTa
|
|
|
60
48
|
return zipkinSpan;
|
|
61
49
|
}
|
|
62
50
|
/** Converts OpenTelemetry Span properties to Zipkin Tags format. */
|
|
63
|
-
export function _toZipkinTags(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
for (var _c = __values(Object.keys(attributes)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
69
|
-
var key = _d.value;
|
|
70
|
-
tags[key] = String(attributes[key]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
74
|
-
finally {
|
|
75
|
-
try {
|
|
76
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
77
|
-
}
|
|
78
|
-
finally { if (e_1) throw e_1.error; }
|
|
51
|
+
export function _toZipkinTags({ attributes, resource, status, droppedAttributesCount, droppedEventsCount, droppedLinksCount, }, statusCodeTagName, statusErrorTagName) {
|
|
52
|
+
const tags = {};
|
|
53
|
+
for (const key of Object.keys(attributes)) {
|
|
54
|
+
tags[key] = String(attributes[key]);
|
|
79
55
|
}
|
|
80
56
|
if (status.code !== api.SpanStatusCode.UNSET) {
|
|
81
57
|
tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
|
|
@@ -95,16 +71,16 @@ export function _toZipkinTags(_a, statusCodeTagName, statusErrorTagName) {
|
|
|
95
71
|
if (droppedLinksCount) {
|
|
96
72
|
tags['otel.dropped_links_count'] = String(droppedLinksCount);
|
|
97
73
|
}
|
|
98
|
-
Object.keys(resource.attributes).forEach(
|
|
74
|
+
Object.keys(resource.attributes).forEach(name => (tags[name] = String(resource.attributes[name])));
|
|
99
75
|
return tags;
|
|
100
76
|
}
|
|
101
77
|
/**
|
|
102
78
|
* Converts OpenTelemetry Events to Zipkin Annotations format.
|
|
103
79
|
*/
|
|
104
80
|
export function _toZipkinAnnotations(events) {
|
|
105
|
-
return events.map(
|
|
81
|
+
return events.map(event => ({
|
|
106
82
|
timestamp: Math.round(hrTimeToMicroseconds(event.time)),
|
|
107
83
|
value: event.name,
|
|
108
|
-
})
|
|
84
|
+
}));
|
|
109
85
|
}
|
|
110
86
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,C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iBAAiB,CAAC,CAAC;KAC9D;IAED,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CACtC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CACzD,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAoB;IAEpB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1B,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,KAAK,EAAE,KAAK,CAAC,IAAI;KAClB,CAAC,CAAC,CAAC;AACN,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';\nimport { hrTimeToMicroseconds } from '@opentelemetry/core';\nimport * as zipkinTypes from './types';\n\nconst ZIPKIN_SPAN_KIND_MAPPING = {\n [api.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,\n [api.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,\n [api.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,\n [api.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,\n // When absent, the span is local.\n [api.SpanKind.INTERNAL]: undefined,\n};\n\nexport const defaultStatusCodeTagName = 'otel.status_code';\nexport const defaultStatusErrorTagName = 'error';\n\n/**\n * Translate OpenTelemetry ReadableSpan to ZipkinSpan format\n * @param span Span to be translated\n */\nexport function toZipkinSpan(\n span: ReadableSpan,\n serviceName: string,\n statusCodeTagName: string,\n statusErrorTagName: string\n): zipkinTypes.Span {\n const zipkinSpan: zipkinTypes.Span = {\n traceId: span.spanContext().traceId,\n parentId: span.parentSpanContext?.spanId,\n name: span.name,\n id: span.spanContext().spanId,\n kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],\n timestamp: hrTimeToMicroseconds(span.startTime),\n duration: Math.round(hrTimeToMicroseconds(span.duration)),\n localEndpoint: { serviceName },\n tags: _toZipkinTags(span, statusCodeTagName, statusErrorTagName),\n annotations: span.events.length\n ? _toZipkinAnnotations(span.events)\n : undefined,\n };\n\n return zipkinSpan;\n}\n\n/** Converts OpenTelemetry Span properties to Zipkin Tags format. */\nexport function _toZipkinTags(\n {\n attributes,\n resource,\n status,\n droppedAttributesCount,\n droppedEventsCount,\n droppedLinksCount,\n }: ReadableSpan,\n statusCodeTagName: string,\n statusErrorTagName: string\n): zipkinTypes.Tags {\n const tags: { [key: string]: string } = {};\n for (const key of Object.keys(attributes)) {\n tags[key] = String(attributes[key]);\n }\n if (status.code !== api.SpanStatusCode.UNSET) {\n tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);\n }\n if (status.code === api.SpanStatusCode.ERROR && status.message) {\n tags[statusErrorTagName] = status.message;\n }\n /* Add droppedAttributesCount as a tag */\n if (droppedAttributesCount) {\n tags['otel.dropped_attributes_count'] = String(droppedAttributesCount);\n }\n\n /* Add droppedEventsCount as a tag */\n if (droppedEventsCount) {\n tags['otel.dropped_events_count'] = String(droppedEventsCount);\n }\n\n /* Add droppedLinksCount as a tag */\n if (droppedLinksCount) {\n tags['otel.dropped_links_count'] = String(droppedLinksCount);\n }\n\n Object.keys(resource.attributes).forEach(\n name => (tags[name] = String(resource.attributes[name]))\n );\n\n return tags;\n}\n\n/**\n * Converts OpenTelemetry Events to Zipkin Annotations format.\n */\nexport function _toZipkinAnnotations(\n events: TimedEvent[]\n): zipkinTypes.Annotation[] {\n return events.map(event => ({\n timestamp: Math.round(hrTimeToMicroseconds(event.time)),\n value: event.name,\n }));\n}\n"]}
|
package/build/esm/types.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export declare enum SpanKind {
|
|
|
152
152
|
/**
|
|
153
153
|
* interface for function that will send zipkin spans
|
|
154
154
|
*/
|
|
155
|
-
export
|
|
156
|
-
export
|
|
157
|
-
export
|
|
155
|
+
export type SendFunction = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
|
|
156
|
+
export type GetHeaders = () => Record<string, string> | undefined;
|
|
157
|
+
export type SendFn = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
|
|
158
158
|
//# sourceMappingURL=types.d.ts.map
|
package/build/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "
|
|
1
|
+
export declare const VERSION = "2.0.0-dev.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/esm/version.js
CHANGED
package/build/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '2.0.0-dev.0';\n"]}
|
package/build/esm/zipkin.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { diag } from '@opentelemetry/api';
|
|
17
|
-
import { ExportResultCode,
|
|
17
|
+
import { ExportResultCode, getStringFromEnv, } from '@opentelemetry/core';
|
|
18
18
|
import { prepareSend } from './platform/index';
|
|
19
19
|
import { toZipkinSpan, defaultStatusCodeTagName, defaultStatusErrorTagName, } from './transform';
|
|
20
20
|
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
@@ -22,12 +22,21 @@ import { prepareGetHeaders } from './utils';
|
|
|
22
22
|
/**
|
|
23
23
|
* Zipkin Exporter
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
export class ZipkinExporter {
|
|
26
|
+
DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
|
|
27
|
+
_statusCodeTagName;
|
|
28
|
+
_statusDescriptionTagName;
|
|
29
|
+
_urlStr;
|
|
30
|
+
_send;
|
|
31
|
+
_getHeaders;
|
|
32
|
+
_serviceName;
|
|
33
|
+
_isShutdown;
|
|
34
|
+
_sendingPromises = [];
|
|
35
|
+
constructor(config = {}) {
|
|
36
|
+
this._urlStr =
|
|
37
|
+
config.url ||
|
|
38
|
+
(getStringFromEnv('OTEL_EXPORTER_ZIPKIN_ENDPOINT') ??
|
|
39
|
+
'http://localhost:9411/api/v2/spans');
|
|
31
40
|
this._send = prepareSend(this._urlStr, config.headers);
|
|
32
41
|
this._serviceName = config.serviceName;
|
|
33
42
|
this._statusCodeTagName =
|
|
@@ -46,82 +55,73 @@ var ZipkinExporter = /** @class */ (function () {
|
|
|
46
55
|
/**
|
|
47
56
|
* Export spans.
|
|
48
57
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var serviceName = String(this._serviceName ||
|
|
58
|
+
export(spans, resultCallback) {
|
|
59
|
+
const serviceName = String(this._serviceName ||
|
|
52
60
|
spans[0].resource.attributes[SEMRESATTRS_SERVICE_NAME] ||
|
|
53
61
|
this.DEFAULT_SERVICE_NAME);
|
|
54
62
|
diag.debug('Zipkin exporter export');
|
|
55
63
|
if (this._isShutdown) {
|
|
56
|
-
setTimeout(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
});
|
|
64
|
+
setTimeout(() => resultCallback({
|
|
65
|
+
code: ExportResultCode.FAILED,
|
|
66
|
+
error: new Error('Exporter has been shutdown'),
|
|
67
|
+
}));
|
|
62
68
|
return;
|
|
63
69
|
}
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
const promise = new Promise(resolve => {
|
|
71
|
+
this._sendSpans(spans, serviceName, result => {
|
|
66
72
|
resolve();
|
|
67
73
|
resultCallback(result);
|
|
68
74
|
});
|
|
69
75
|
});
|
|
70
76
|
this._sendingPromises.push(promise);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
const popPromise = () => {
|
|
78
|
+
const index = this._sendingPromises.indexOf(promise);
|
|
79
|
+
this._sendingPromises.splice(index, 1);
|
|
74
80
|
};
|
|
75
81
|
promise.then(popPromise, popPromise);
|
|
76
|
-
}
|
|
82
|
+
}
|
|
77
83
|
/**
|
|
78
84
|
* Shutdown exporter. Noop operation in this exporter.
|
|
79
85
|
*/
|
|
80
|
-
|
|
86
|
+
shutdown() {
|
|
81
87
|
diag.debug('Zipkin exporter shutdown');
|
|
82
88
|
this._isShutdown = true;
|
|
83
89
|
return this.forceFlush();
|
|
84
|
-
}
|
|
90
|
+
}
|
|
85
91
|
/**
|
|
86
92
|
* Exports any pending spans in exporter
|
|
87
93
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
Promise.all(_this._sendingPromises).then(function () {
|
|
94
|
+
forceFlush() {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
Promise.all(this._sendingPromises).then(() => {
|
|
92
97
|
resolve();
|
|
93
98
|
}, reject);
|
|
94
99
|
});
|
|
95
|
-
}
|
|
100
|
+
}
|
|
96
101
|
/**
|
|
97
102
|
* if user defines getExportRequestHeaders in config then this will be called
|
|
98
103
|
* every time before send, otherwise it will be replaced with noop in
|
|
99
104
|
* constructor
|
|
100
105
|
* @default noop
|
|
101
106
|
*/
|
|
102
|
-
|
|
107
|
+
_beforeSend() {
|
|
103
108
|
if (this._getHeaders) {
|
|
104
109
|
this._send = prepareSend(this._urlStr, this._getHeaders());
|
|
105
110
|
}
|
|
106
|
-
}
|
|
111
|
+
}
|
|
107
112
|
/**
|
|
108
113
|
* Transform spans and sends to Zipkin service.
|
|
109
114
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
span.resource.attributes[SEMRESATTRS_SERVICE_NAME] ||
|
|
115
|
-
serviceName), _this._statusCodeTagName, _this._statusDescriptionTagName);
|
|
116
|
-
});
|
|
115
|
+
_sendSpans(spans, serviceName, done) {
|
|
116
|
+
const zipkinSpans = spans.map(span => toZipkinSpan(span, String(span.attributes[SEMRESATTRS_SERVICE_NAME] ||
|
|
117
|
+
span.resource.attributes[SEMRESATTRS_SERVICE_NAME] ||
|
|
118
|
+
serviceName), this._statusCodeTagName, this._statusDescriptionTagName));
|
|
117
119
|
this._beforeSend();
|
|
118
|
-
return this._send(zipkinSpans,
|
|
120
|
+
return this._send(zipkinSpans, (result) => {
|
|
119
121
|
if (done) {
|
|
120
122
|
return done(result);
|
|
121
123
|
}
|
|
122
124
|
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}());
|
|
126
|
-
export { ZipkinExporter };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
127
|
//# sourceMappingURL=zipkin.js.map
|
package/build/esm/zipkin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zipkin.js","sourceRoot":"","sources":["../../src/zipkin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"zipkin.js","sourceRoot":"","sources":["../../src/zipkin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAEL,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,cAAc;IACR,oBAAoB,GAAG,uBAAuB,CAAC;IAC/C,kBAAkB,CAAS;IAC3B,yBAAyB,CAAS;IAC3C,OAAO,CAAS;IAChB,KAAK,CAA2B;IAChC,WAAW,CAAqC;IAChD,YAAY,CAAU;IACtB,WAAW,CAAU;IACrB,gBAAgB,GAAuB,EAAE,CAAC;IAElD,YAAY,SAAqC,EAAE;QACjD,IAAI,CAAC,OAAO;YACV,MAAM,CAAC,GAAG;gBACV,CAAC,gBAAgB,CAAC,+BAA+B,CAAC;oBAChD,oCAAoC,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC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,kBAAkB,EACvB,IAAI,CAAC,yBAAyB,CAC/B,CACF,CAAC;QACF,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,MAAoB,EAAE,EAAE;YACtD,IAAI,IAAI,EAAE;gBACR,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;aACrB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { diag } from '@opentelemetry/api';\nimport {\n ExportResult,\n ExportResultCode,\n getStringFromEnv,\n} from '@opentelemetry/core';\nimport { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { prepareSend } from './platform/index';\nimport * as zipkinTypes from './types';\nimport {\n toZipkinSpan,\n defaultStatusCodeTagName,\n defaultStatusErrorTagName,\n} from './transform';\nimport { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';\nimport { prepareGetHeaders } from './utils';\n\n/**\n * Zipkin Exporter\n */\nexport class ZipkinExporter implements SpanExporter {\n private readonly DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';\n private readonly _statusCodeTagName: string;\n private readonly _statusDescriptionTagName: string;\n private _urlStr: string;\n private _send: zipkinTypes.SendFunction;\n private _getHeaders: zipkinTypes.GetHeaders | undefined;\n private _serviceName?: string;\n private _isShutdown: boolean;\n private _sendingPromises: Promise<unknown>[] = [];\n\n constructor(config: zipkinTypes.ExporterConfig = {}) {\n this._urlStr =\n config.url ||\n (getStringFromEnv('OTEL_EXPORTER_ZIPKIN_ENDPOINT') ??\n 'http://localhost:9411/api/v2/spans');\n this._send = prepareSend(this._urlStr, config.headers);\n this._serviceName = config.serviceName;\n this._statusCodeTagName =\n config.statusCodeTagName || defaultStatusCodeTagName;\n this._statusDescriptionTagName =\n config.statusDescriptionTagName || defaultStatusErrorTagName;\n this._isShutdown = false;\n if (typeof config.getExportRequestHeaders === 'function') {\n this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders);\n } else {\n // noop\n this._beforeSend = function () {};\n }\n }\n\n /**\n * Export spans.\n */\n export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): void {\n const serviceName = String(\n this._serviceName ||\n spans[0].resource.attributes[SEMRESATTRS_SERVICE_NAME] ||\n this.DEFAULT_SERVICE_NAME\n );\n\n diag.debug('Zipkin exporter export');\n if (this._isShutdown) {\n setTimeout(() =>\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been shutdown'),\n })\n );\n return;\n }\n const promise = new Promise<void>(resolve => {\n this._sendSpans(spans, serviceName, result => {\n resolve();\n resultCallback(result);\n });\n });\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n\n /**\n * Shutdown exporter. Noop operation in this exporter.\n */\n shutdown(): Promise<void> {\n diag.debug('Zipkin exporter shutdown');\n this._isShutdown = true;\n return this.forceFlush();\n }\n\n /**\n * Exports any pending spans in exporter\n */\n forceFlush(): Promise<void> {\n return new Promise((resolve, reject) => {\n Promise.all(this._sendingPromises).then(() => {\n resolve();\n }, reject);\n });\n }\n\n /**\n * if user defines getExportRequestHeaders in config then this will be called\n * every time before send, otherwise it will be replaced with noop in\n * constructor\n * @default noop\n */\n private _beforeSend() {\n if (this._getHeaders) {\n this._send = prepareSend(this._urlStr, this._getHeaders());\n }\n }\n\n /**\n * Transform spans and sends to Zipkin service.\n */\n private _sendSpans(\n spans: ReadableSpan[],\n serviceName: string,\n done?: (result: ExportResult) => void\n ) {\n const zipkinSpans = spans.map(span =>\n toZipkinSpan(\n span,\n String(\n span.attributes[SEMRESATTRS_SERVICE_NAME] ||\n span.resource.attributes[SEMRESATTRS_SERVICE_NAME] ||\n serviceName\n ),\n this._statusCodeTagName,\n this._statusDescriptionTagName\n )\n );\n this._beforeSend();\n return this._send(zipkinSpans, (result: ExportResult) => {\n if (done) {\n return done(result);\n }\n });\n }\n}\n"]}
|