@opentelemetry/exporter-zipkin 1.0.1 → 1.2.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/README.md +0 -6
- package/build/esm/platform/browser/util.js +18 -2
- package/build/esm/platform/browser/util.js.map +1 -1
- package/build/esm/transform.js +24 -3
- package/build/esm/transform.js.map +1 -1
- 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.map +1 -1
- package/build/esnext/index.d.ts +4 -0
- package/build/esnext/index.js +18 -0
- package/build/esnext/index.js.map +1 -0
- package/build/esnext/platform/browser/index.d.ts +2 -0
- package/build/esnext/platform/browser/index.js +17 -0
- package/build/esnext/platform/browser/index.js.map +1 -0
- package/build/esnext/platform/browser/util.d.ts +9 -0
- package/build/esnext/platform/browser/util.js +101 -0
- package/build/esnext/platform/browser/util.js.map +1 -0
- package/build/esnext/platform/index.d.ts +2 -0
- package/build/esnext/platform/index.js +17 -0
- package/build/esnext/platform/index.js.map +1 -0
- package/build/esnext/platform/node/index.d.ts +2 -0
- package/build/esnext/platform/node/index.js +17 -0
- package/build/esnext/platform/node/index.js.map +1 -0
- package/build/esnext/platform/node/util.d.ts +9 -0
- package/build/esnext/platform/node/util.js +76 -0
- package/build/esnext/platform/node/util.js.map +1 -0
- package/build/esnext/transform.d.ts +18 -0
- package/build/esnext/transform.js +74 -0
- package/build/esnext/transform.js.map +1 -0
- package/build/esnext/types.d.ts +158 -0
- package/build/esnext/types.js +45 -0
- package/build/esnext/types.js.map +1 -0
- package/build/esnext/utils.d.ts +3 -0
- package/build/esnext/utils.js +6 -0
- package/build/esnext/utils.js.map +1 -0
- package/build/esnext/version.d.ts +2 -0
- package/build/esnext/version.js +18 -0
- package/build/esnext/version.js.map +1 -0
- package/build/esnext/zipkin.d.ts +38 -0
- package/build/esnext/zipkin.js +110 -0
- package/build/esnext/zipkin.js.map +1 -0
- package/build/src/platform/browser/util.js +2 -2
- package/build/src/platform/browser/util.js.map +1 -1
- package/build/src/transform.js +3 -3
- package/build/src/transform.js.map +1 -1
- 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 +5 -5
- package/build/src/zipkin.js.map +1 -1
- package/package.json +29 -22
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# OpenTelemetry Zipkin Trace Exporter
|
|
2
2
|
|
|
3
3
|
[![NPM Published Version][npm-img]][npm-url]
|
|
4
|
-
[![dependencies][dependencies-image]][dependencies-url]
|
|
5
|
-
[![devDependencies][devDependencies-image]][devDependencies-url]
|
|
6
4
|
[![Apache License][license-image]][license-image]
|
|
7
5
|
|
|
8
6
|
OpenTelemetry Zipkin Trace Exporter allows the user to send collected traces to Zipkin.
|
|
@@ -74,9 +72,5 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
|
|
|
74
72
|
[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
|
|
75
73
|
[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE
|
|
76
74
|
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
|
|
77
|
-
[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-exporter-zipkin
|
|
78
|
-
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-exporter-zipkin
|
|
79
|
-
[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-exporter-zipkin&type=dev
|
|
80
|
-
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-exporter-zipkin&type=dev
|
|
81
75
|
[npm-url]: https://www.npmjs.com/package/@opentelemetry/exporter-zipkin
|
|
82
76
|
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fexporter-zipkin.svg
|
|
@@ -24,6 +24,22 @@ var __assign = (this && this.__assign) || function () {
|
|
|
24
24
|
};
|
|
25
25
|
return __assign.apply(this, arguments);
|
|
26
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
|
+
};
|
|
27
43
|
import { diag } from '@opentelemetry/api';
|
|
28
44
|
import { ExportResultCode, globalErrorHandler, } from '@opentelemetry/core';
|
|
29
45
|
/**
|
|
@@ -82,10 +98,10 @@ function sendWithBeacon(data, done, urlStr) {
|
|
|
82
98
|
*/
|
|
83
99
|
function sendWithXhr(data, done, urlStr, xhrHeaders) {
|
|
84
100
|
if (xhrHeaders === void 0) { xhrHeaders = {}; }
|
|
85
|
-
var xhr = new
|
|
101
|
+
var xhr = new XMLHttpRequest();
|
|
86
102
|
xhr.open('POST', urlStr);
|
|
87
103
|
Object.entries(xhrHeaders).forEach(function (_a) {
|
|
88
|
-
var k =
|
|
104
|
+
var _b = __read(_a, 2), k = _b[0], v = _b[1];
|
|
89
105
|
xhr.setRequestHeader(k, v);
|
|
90
106
|
});
|
|
91
107
|
xhr.onreadystatechange = function () {
|
|
@@ -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":"","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;IACH,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,GAAG,UAAA,GAAG;QACf,kBAAkB,CAAC,IAAI,KAAK,CAAC,2BAAyB,GAAK,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,6BAA2B,IAAM,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(urlStr: string, headers?: Record<string, string>): 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"]}
|
package/build/esm/transform.js
CHANGED
|
@@ -13,6 +13,17 @@
|
|
|
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
|
+
};
|
|
16
27
|
var _a;
|
|
17
28
|
import * as api from '@opentelemetry/api';
|
|
18
29
|
import { hrTimeToMicroseconds } from '@opentelemetry/core';
|
|
@@ -50,10 +61,20 @@ export function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTa
|
|
|
50
61
|
}
|
|
51
62
|
/** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */
|
|
52
63
|
export function _toZipkinTags(attributes, status, statusCodeTagName, statusErrorTagName, resource) {
|
|
64
|
+
var e_1, _a;
|
|
53
65
|
var tags = {};
|
|
54
|
-
|
|
55
|
-
var
|
|
56
|
-
|
|
66
|
+
try {
|
|
67
|
+
for (var _b = __values(Object.keys(attributes)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
68
|
+
var key = _c.value;
|
|
69
|
+
tags[key] = String(attributes[key]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
73
|
+
finally {
|
|
74
|
+
try {
|
|
75
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
76
|
+
}
|
|
77
|
+
finally { if (e_1) throw e_1.error; }
|
|
57
78
|
}
|
|
58
79
|
if (status.code !== api.SpanStatusCode.UNSET) {
|
|
59
80
|
tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
|
|
@@ -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":["../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AI,CAAC,CAAC,CAAC,EAAhD,CAAgD,CACzD,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAoB;IAEpB,OAAO,MAAM,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,CAAC;QAC1B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC;QAC3C,KAAK,EAAE,KAAK,CAAC,IAAI;KAClB,CAAC,EAHyB,CAGzB,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';\nimport { Resource } from '@opentelemetry/resources';\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.parentSpanId,\n name: span.name,\n id: span.spanContext().spanId,\n kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],\n timestamp: hrTimeToMicroseconds(span.startTime),\n duration: hrTimeToMicroseconds(span.duration),\n localEndpoint: { serviceName },\n tags: _toZipkinTags(\n span.attributes,\n span.status,\n statusCodeTagName,\n statusErrorTagName,\n span.resource\n ),\n annotations: span.events.length\n ? _toZipkinAnnotations(span.events)\n : undefined,\n };\n\n return zipkinSpan;\n}\n\n/** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */\nexport function _toZipkinTags(\n attributes: api.SpanAttributes,\n status: api.SpanStatus,\n statusCodeTagName: string,\n statusErrorTagName: string,\n resource: Resource\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\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: hrTimeToMicroseconds(event.time),\n value: event.name,\n }));\n}\n"]}
|
package/build/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.0
|
|
1
|
+
export declare const VERSION = "1.2.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,IAAM,OAAO,GAAG,OAAO,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 = '1.0
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,OAAO,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 = '1.2.0';\n"]}
|
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,EAAgB,gBAAgB,EAAE,M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5D;IACH,CAAC;IAED;;OAEG;IACK,mCAAU,GAAlB,UACE,KAAqB,EACrB,WAAmB,EACnB,IAAqC;QAHvC,iBAuBC;QAlBC,IAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI;YAChC,OAAA,YAAY,CACV,IAAI,EACJ,MAAM,CACJ,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAAC,YAAY,CAAC;gBACtD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,YAAY,CAAC;gBACjE,WAAW,CACd,EACD,KAAI,CAAC,kBAAkB,EACvB,KAAI,CAAC,yBAAyB,CAC/B;QATD,CASC,CACF,CAAC;QACF,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,UAAC,MAAoB;YAClD,IAAI,IAAI,EAAE;gBACR,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;aACrB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACH,qBAAC;AAAD,CAAC,AAtHD,IAsHC","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, getEnv } 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 { SemanticResourceAttributes } 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 = config.url || getEnv().OTEL_EXPORTER_ZIPKIN_ENDPOINT;\n this._send = prepareSend(this._urlStr, config.headers);\n this._serviceName = config.serviceName;\n this._statusCodeTagName = 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[SemanticResourceAttributes.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\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 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 * everytime 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[SemanticResourceAttributes.SERVICE_NAME] ||\n span.resource.attributes[SemanticResourceAttributes.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"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export * from './platform';
|
|
17
|
+
export * from './zipkin';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,YAAY,CAAC;AAE3B,cAAc,UAAU,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\nexport * from './platform';\nexport { ExporterConfig } from './types';\nexport * from './zipkin';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export * from './util';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,QAAQ,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\nexport * from './util';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as zipkinTypes from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Prepares send function that will send spans to the remote Zipkin service.
|
|
4
|
+
* @param urlStr - url to send spans
|
|
5
|
+
* @param headers - headers
|
|
6
|
+
* send
|
|
7
|
+
*/
|
|
8
|
+
export declare function prepareSend(urlStr: string, headers?: Record<string, string>): zipkinTypes.SendFn;
|
|
9
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { diag } from '@opentelemetry/api';
|
|
17
|
+
import { ExportResultCode, globalErrorHandler, } from '@opentelemetry/core';
|
|
18
|
+
/**
|
|
19
|
+
* Prepares send function that will send spans to the remote Zipkin service.
|
|
20
|
+
* @param urlStr - url to send spans
|
|
21
|
+
* @param headers - headers
|
|
22
|
+
* send
|
|
23
|
+
*/
|
|
24
|
+
export function prepareSend(urlStr, headers) {
|
|
25
|
+
let xhrHeaders;
|
|
26
|
+
const useBeacon = typeof navigator.sendBeacon === 'function' && !headers;
|
|
27
|
+
if (headers) {
|
|
28
|
+
xhrHeaders = Object.assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, headers);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Send spans to the remote Zipkin service.
|
|
32
|
+
*/
|
|
33
|
+
return function send(zipkinSpans, done) {
|
|
34
|
+
if (zipkinSpans.length === 0) {
|
|
35
|
+
diag.debug('Zipkin send with empty spans');
|
|
36
|
+
return done({ code: ExportResultCode.SUCCESS });
|
|
37
|
+
}
|
|
38
|
+
const payload = JSON.stringify(zipkinSpans);
|
|
39
|
+
if (useBeacon) {
|
|
40
|
+
sendWithBeacon(payload, done, urlStr);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
sendWithXhr(payload, done, urlStr, xhrHeaders);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sends data using beacon
|
|
49
|
+
* @param data
|
|
50
|
+
* @param done
|
|
51
|
+
* @param urlStr
|
|
52
|
+
*/
|
|
53
|
+
function sendWithBeacon(data, done, urlStr) {
|
|
54
|
+
if (navigator.sendBeacon(urlStr, data)) {
|
|
55
|
+
diag.debug('sendBeacon - can send', data);
|
|
56
|
+
done({ code: ExportResultCode.SUCCESS });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
done({
|
|
60
|
+
code: ExportResultCode.FAILED,
|
|
61
|
+
error: new Error(`sendBeacon - cannot send ${data}`),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sends data using XMLHttpRequest
|
|
67
|
+
* @param data
|
|
68
|
+
* @param done
|
|
69
|
+
* @param urlStr
|
|
70
|
+
* @param xhrHeaders
|
|
71
|
+
*/
|
|
72
|
+
function sendWithXhr(data, done, urlStr, xhrHeaders = {}) {
|
|
73
|
+
const xhr = new XMLHttpRequest();
|
|
74
|
+
xhr.open('POST', urlStr);
|
|
75
|
+
Object.entries(xhrHeaders).forEach(([k, v]) => {
|
|
76
|
+
xhr.setRequestHeader(k, v);
|
|
77
|
+
});
|
|
78
|
+
xhr.onreadystatechange = () => {
|
|
79
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
80
|
+
const statusCode = xhr.status || 0;
|
|
81
|
+
diag.debug(`Zipkin response status code: ${statusCode}, body: ${data}`);
|
|
82
|
+
if (xhr.status >= 200 && xhr.status < 400) {
|
|
83
|
+
return done({ code: ExportResultCode.SUCCESS });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return done({
|
|
87
|
+
code: ExportResultCode.FAILED,
|
|
88
|
+
error: new Error(`Got unexpected status code from zipkin: ${xhr.status}`),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
xhr.onerror = msg => {
|
|
94
|
+
globalErrorHandler(new Error(`Zipkin request error: ${msg}`));
|
|
95
|
+
return done({ code: ExportResultCode.FAILED });
|
|
96
|
+
};
|
|
97
|
+
// Issue request to remote service
|
|
98
|
+
diag.debug(`Zipkin request payload: ${data}`);
|
|
99
|
+
xhr.send(data);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,MAAc,EAAE,OAAgC;IAC1E,IAAI,UAAkC,CAAC;IACvC,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,IAAI,CAAC,OAAO,CAAC;IAC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Telemetry 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(urlStr: string, headers?: Record<string, string>): 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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export * from './node';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,QAAQ,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\nexport * from './node';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export * from './util';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,QAAQ,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\nexport * from './util';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as zipkinTypes from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Prepares send function that will send spans to the remote Zipkin service.
|
|
4
|
+
* @param urlStr - url to send spans
|
|
5
|
+
* @param headers - headers
|
|
6
|
+
* send
|
|
7
|
+
*/
|
|
8
|
+
export declare function prepareSend(urlStr: string, headers?: Record<string, string>): zipkinTypes.SendFn;
|
|
9
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { diag } from '@opentelemetry/api';
|
|
17
|
+
import { ExportResultCode } from '@opentelemetry/core';
|
|
18
|
+
import * as http from 'http';
|
|
19
|
+
import * as https from 'https';
|
|
20
|
+
import * as url from 'url';
|
|
21
|
+
/**
|
|
22
|
+
* Prepares send function that will send spans to the remote Zipkin service.
|
|
23
|
+
* @param urlStr - url to send spans
|
|
24
|
+
* @param headers - headers
|
|
25
|
+
* send
|
|
26
|
+
*/
|
|
27
|
+
export function prepareSend(urlStr, headers) {
|
|
28
|
+
const urlOpts = url.parse(urlStr);
|
|
29
|
+
const reqOpts = Object.assign({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, headers),
|
|
32
|
+
}, urlOpts);
|
|
33
|
+
/**
|
|
34
|
+
* Send spans to the remote Zipkin service.
|
|
35
|
+
*/
|
|
36
|
+
return function send(zipkinSpans, done) {
|
|
37
|
+
if (zipkinSpans.length === 0) {
|
|
38
|
+
diag.debug('Zipkin send with empty spans');
|
|
39
|
+
return done({ code: ExportResultCode.SUCCESS });
|
|
40
|
+
}
|
|
41
|
+
const { request } = reqOpts.protocol === 'http:' ? http : https;
|
|
42
|
+
const req = request(reqOpts, (res) => {
|
|
43
|
+
let rawData = '';
|
|
44
|
+
res.on('data', chunk => {
|
|
45
|
+
rawData += chunk;
|
|
46
|
+
});
|
|
47
|
+
res.on('end', () => {
|
|
48
|
+
const statusCode = res.statusCode || 0;
|
|
49
|
+
diag.debug(`Zipkin response status code: ${statusCode}, body: ${rawData}`);
|
|
50
|
+
// Consider 2xx and 3xx as success.
|
|
51
|
+
if (statusCode < 400) {
|
|
52
|
+
return done({ code: ExportResultCode.SUCCESS });
|
|
53
|
+
// Consider 4xx as failed non-retriable.
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return done({
|
|
57
|
+
code: ExportResultCode.FAILED,
|
|
58
|
+
error: new Error(`Got unexpected status code from zipkin: ${statusCode}`),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
req.on('error', error => {
|
|
64
|
+
return done({
|
|
65
|
+
code: ExportResultCode.FAILED,
|
|
66
|
+
error,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
// Issue request to remote service
|
|
70
|
+
const payload = JSON.stringify(zipkinSpans);
|
|
71
|
+
diag.debug(`Zipkin request payload: ${payload}`);
|
|
72
|
+
req.write(payload, 'utf8');
|
|
73
|
+
req.end();
|
|
74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KAAK,CAAC,EAAE;gBACrB,OAAO,IAAI,KAAK,CAAC;YACnB,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACjB,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,CAAC,CAAC;gBACvC,IAAI,CAAC,KAAK,CAAC,gCAAgC,UAAU,WAAW,OAAO,EAAE,CAAC,CAAC;gBAE3E,mCAAmC;gBACnC,IAAI,UAAU,GAAG,GAAG,EAAE;oBACpB,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;oBAChD,wCAAwC;iBACzC;qBAAM;oBACL,OAAO,IAAI,CAAC;wBACV,IAAI,EAAE,gBAAgB,CAAC,MAAM;wBAC7B,KAAK,EAAE,IAAI,KAAK,CACd,2CAA2C,UAAU,EAAE,CACxD;qBACF,CAAC,CAAC;iBACJ;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE;YACtB,OAAO,IAAI,CAAC;gBACV,IAAI,EAAE,gBAAgB,CAAC,MAAM;gBAC7B,KAAK;aACN,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,kCAAkC;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;QACjD,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;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 url from 'url';\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(urlStr: string, headers?: Record<string, string>): zipkinTypes.SendFn {\n const urlOpts = url.parse(urlStr);\n\n const reqOpts: http.RequestOptions = Object.assign(\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n },\n urlOpts\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 } = reqOpts.protocol === 'http:' ? http : https;\n const req = request(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(`Zipkin response status code: ${statusCode}, body: ${rawData}`);\n\n // Consider 2xx and 3xx as success.\n if (statusCode < 400) {\n return done({ code: ExportResultCode.SUCCESS });\n // Consider 4xx as failed non-retriable.\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"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as api from '@opentelemetry/api';
|
|
2
|
+
import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
|
|
3
|
+
import * as zipkinTypes from './types';
|
|
4
|
+
import { Resource } from '@opentelemetry/resources';
|
|
5
|
+
export declare const defaultStatusCodeTagName = "otel.status_code";
|
|
6
|
+
export declare const defaultStatusErrorTagName = "error";
|
|
7
|
+
/**
|
|
8
|
+
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
|
|
9
|
+
* @param span Span to be translated
|
|
10
|
+
*/
|
|
11
|
+
export declare function toZipkinSpan(span: ReadableSpan, serviceName: string, statusCodeTagName: string, statusErrorTagName: string): zipkinTypes.Span;
|
|
12
|
+
/** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */
|
|
13
|
+
export declare function _toZipkinTags(attributes: api.SpanAttributes, status: api.SpanStatus, statusCodeTagName: string, statusErrorTagName: string, resource: Resource): zipkinTypes.Tags;
|
|
14
|
+
/**
|
|
15
|
+
* Converts OpenTelemetry Events to Zipkin Annotations format.
|
|
16
|
+
*/
|
|
17
|
+
export declare function _toZipkinAnnotations(events: TimedEvent[]): zipkinTypes.Annotation[];
|
|
18
|
+
//# sourceMappingURL=transform.d.ts.map
|