@opentelemetry/exporter-zipkin 1.30.1 → 2.0.0-dev.1
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
|
@@ -25,7 +25,11 @@ export function prepareSend(urlStr, headers) {
|
|
|
25
25
|
let xhrHeaders;
|
|
26
26
|
const useBeacon = typeof navigator.sendBeacon === 'function' && !headers;
|
|
27
27
|
if (headers) {
|
|
28
|
-
xhrHeaders =
|
|
28
|
+
xhrHeaders = {
|
|
29
|
+
Accept: 'application/json',
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
...headers,
|
|
32
|
+
};
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
31
35
|
* Send spans to the remote Zipkin service.
|
|
@@ -1 +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,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,
|
|
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,IAAoC;QAEpC,IAAI,WAAW,CAAC,MAAM,KA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;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"]}
|
|
@@ -17,7 +17,6 @@ import { diag } from '@opentelemetry/api';
|
|
|
17
17
|
import { ExportResultCode } from '@opentelemetry/core';
|
|
18
18
|
import * as http from 'http';
|
|
19
19
|
import * as https from 'https';
|
|
20
|
-
import * as url from 'url';
|
|
21
20
|
/**
|
|
22
21
|
* Prepares send function that will send spans to the remote Zipkin service.
|
|
23
22
|
* @param urlStr - url to send spans
|
|
@@ -25,11 +24,14 @@ import * as url from 'url';
|
|
|
25
24
|
* send
|
|
26
25
|
*/
|
|
27
26
|
export function prepareSend(urlStr, headers) {
|
|
28
|
-
const
|
|
27
|
+
const url = new URL(urlStr);
|
|
29
28
|
const reqOpts = Object.assign({
|
|
30
29
|
method: 'POST',
|
|
31
|
-
headers:
|
|
32
|
-
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
...headers,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
33
35
|
/**
|
|
34
36
|
* Send spans to the remote Zipkin service.
|
|
35
37
|
*/
|
|
@@ -38,8 +40,8 @@ export function prepareSend(urlStr, headers) {
|
|
|
38
40
|
diag.debug('Zipkin send with empty spans');
|
|
39
41
|
return done({ code: ExportResultCode.SUCCESS });
|
|
40
42
|
}
|
|
41
|
-
const { request } =
|
|
42
|
-
const req = request(reqOpts, (res) => {
|
|
43
|
+
const { request } = url.protocol === 'http:' ? http : https;
|
|
44
|
+
const req = request(url, reqOpts, (res) => {
|
|
43
45
|
let rawData = '';
|
|
44
46
|
res.on('data', chunk => {
|
|
45
47
|
rawData += chunk;
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,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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 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"]}
|
|
@@ -33,7 +33,7 @@ export const defaultStatusErrorTagName = 'error';
|
|
|
33
33
|
export function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTagName) {
|
|
34
34
|
const zipkinSpan = {
|
|
35
35
|
traceId: span.spanContext().traceId,
|
|
36
|
-
parentId: span.
|
|
36
|
+
parentId: span.parentSpanContext?.spanId,
|
|
37
37
|
name: span.name,
|
|
38
38
|
id: span.spanContext().spanId,
|
|
39
39
|
kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
|
|
@@ -1 +1 @@
|
|
|
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,CAAC;AAC3D,OAAO,KAAK,WAAW,MAAM,SAAS,CAAC;AAEvC,MAAM,wBAAwB,GAAG;IAC/B,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;IAClD,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;IAClD,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ;IACtD,CAAC,GAAG,CAAC,QAAQ,CAAC,Q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* 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/esnext/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
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "
|
|
1
|
+
export declare const VERSION = "2.0.0-dev.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/esnext/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
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.1';\n"]}
|
package/build/esnext/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';
|
|
@@ -23,10 +23,20 @@ import { prepareGetHeaders } from './utils';
|
|
|
23
23
|
* Zipkin Exporter
|
|
24
24
|
*/
|
|
25
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 = [];
|
|
26
35
|
constructor(config = {}) {
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
this._urlStr =
|
|
37
|
+
config.url ||
|
|
38
|
+
(getStringFromEnv('OTEL_EXPORTER_ZIPKIN_ENDPOINT') ??
|
|
39
|
+
'http://localhost:9411/api/v2/spans');
|
|
30
40
|
this._send = prepareSend(this._urlStr, config.headers);
|
|
31
41
|
this._serviceName = config.serviceName;
|
|
32
42
|
this._statusCodeTagName =
|
|
@@ -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;AA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AKG;IACK,WAAW;QACjB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;SAC5D;IACH,CAAC;IAED;;OAEG;IACK,UAAU,CAChB,KAAqB,EACrB,WAAmB,EACnB,IAAqC;QAErC,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CACnC,YAAY,CACV,IAAI,EACJ,MAAM,CACJ,IAAI,CAAC,UAAU,CAAC,wBAAwB,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,wBAAwB,CAAC;YAClD,WAAW,CACd,EACD,IAAI,CAAC,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"]}
|
|
@@ -28,7 +28,11 @@ function prepareSend(urlStr, headers) {
|
|
|
28
28
|
let xhrHeaders;
|
|
29
29
|
const useBeacon = typeof navigator.sendBeacon === 'function' && !headers;
|
|
30
30
|
if (headers) {
|
|
31
|
-
xhrHeaders =
|
|
31
|
+
xhrHeaders = {
|
|
32
|
+
Accept: 'application/json',
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
...headers,
|
|
35
|
+
};
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* Send spans to the remote Zipkin service.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;G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D;iBAAM;gBACL,OAAO,IAAI,CAAC;oBACV,IAAI,EAAE,uBAAgB,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,IAAA,yBAAkB,EAAC,IAAI,KAAK,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,uBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,kCAAkC;IAClC,UAAI,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"]}
|
|
@@ -20,7 +20,6 @@ const api_1 = require("@opentelemetry/api");
|
|
|
20
20
|
const core_1 = require("@opentelemetry/core");
|
|
21
21
|
const http = require("http");
|
|
22
22
|
const https = require("https");
|
|
23
|
-
const url = require("url");
|
|
24
23
|
/**
|
|
25
24
|
* Prepares send function that will send spans to the remote Zipkin service.
|
|
26
25
|
* @param urlStr - url to send spans
|
|
@@ -28,11 +27,14 @@ const url = require("url");
|
|
|
28
27
|
* send
|
|
29
28
|
*/
|
|
30
29
|
function prepareSend(urlStr, headers) {
|
|
31
|
-
const
|
|
30
|
+
const url = new URL(urlStr);
|
|
32
31
|
const reqOpts = Object.assign({
|
|
33
32
|
method: 'POST',
|
|
34
|
-
headers:
|
|
35
|
-
|
|
33
|
+
headers: {
|
|
34
|
+
'Content-Type': 'application/json',
|
|
35
|
+
...headers,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
36
38
|
/**
|
|
37
39
|
* Send spans to the remote Zipkin service.
|
|
38
40
|
*/
|
|
@@ -41,8 +43,8 @@ function prepareSend(urlStr, headers) {
|
|
|
41
43
|
api_1.diag.debug('Zipkin send with empty spans');
|
|
42
44
|
return done({ code: core_1.ExportResultCode.SUCCESS });
|
|
43
45
|
}
|
|
44
|
-
const { request } =
|
|
45
|
-
const req = request(reqOpts, (res) => {
|
|
46
|
+
const { request } = url.protocol === 'http:' ? http : https;
|
|
47
|
+
const req = request(url, reqOpts, (res) => {
|
|
46
48
|
let rawData = '';
|
|
47
49
|
res.on('data', chunk => {
|
|
48
50
|
rawData += chunk;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,8CAAqE;AACrE,6BAA6B;AAC7B,+BAA+B;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;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E,IAAI,EAAE,uBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;oBAChD,wCAAwC;iBACzC;qBAAM;oBACL,OAAO,IAAI,CAAC;wBACV,IAAI,EAAE,uBAAgB,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,uBAAgB,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,UAAI,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;AAlED,kCAkEC","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/src/transform.js
CHANGED
|
@@ -36,7 +36,7 @@ exports.defaultStatusErrorTagName = 'error';
|
|
|
36
36
|
function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTagName) {
|
|
37
37
|
const zipkinSpan = {
|
|
38
38
|
traceId: span.spanContext().traceId,
|
|
39
|
-
parentId: span.
|
|
39
|
+
parentId: span.parentSpanContext?.spanId,
|
|
40
40
|
name: span.name,
|
|
41
41
|
id: span.spanContext().spanId,
|
|
42
42
|
kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAE1C,8CAA2D;AAC3D,uCAAuC;AAEvC,MAAM,wBAAwB,GAAG;IAC/B,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;IAClD,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;IAClD,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ;IACtD,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ;IACtD,kCAAkC;IAClC,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS;CACnC,CAAC;AAEW,QAAA,wBAAwB,GAAG,kBAAkB,CAAC;AAC9C,QAAA,yBAAyB,GAAG,OAAO,CAAC;AAEjD;;;GAGG;AACH,SAAgB,YAAY,CAC1B,IAAkB,EAClB,WAAmB,EACnB,iBAAyB,EACzB,kBAA0B;IAE1B,MAAM,UAAU,GAAqB;QACnC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO;QACnC,QAAQ,EAAE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAE1C,8CAA2D;AAC3D,uCAAuC;AAEvC,MAAM,wBAAwB,GAAG;IAC/B,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;IAClD,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ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AO,IAAI,CAAC;AACd,CAAC;AA1CD,sCA0CC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAClC,MAAoB;IAEpB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1B,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAA,2BAAoB,EAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,KAAK,EAAE,KAAK,CAAC,IAAI;KAClB,CAAC,CAAC,CAAC;AACN,CAAC;AAPD,oDAOC","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/src/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/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "
|
|
1
|
+
export declare const VERSION = "2.0.0-dev.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,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.1';\n"]}
|
package/build/src/zipkin.js
CHANGED
|
@@ -26,10 +26,20 @@ const utils_1 = require("./utils");
|
|
|
26
26
|
* Zipkin Exporter
|
|
27
27
|
*/
|
|
28
28
|
class ZipkinExporter {
|
|
29
|
+
DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
|
|
30
|
+
_statusCodeTagName;
|
|
31
|
+
_statusDescriptionTagName;
|
|
32
|
+
_urlStr;
|
|
33
|
+
_send;
|
|
34
|
+
_getHeaders;
|
|
35
|
+
_serviceName;
|
|
36
|
+
_isShutdown;
|
|
37
|
+
_sendingPromises = [];
|
|
29
38
|
constructor(config = {}) {
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
this._urlStr =
|
|
40
|
+
config.url ||
|
|
41
|
+
((0, core_1.getStringFromEnv)('OTEL_EXPORTER_ZIPKIN_ENDPOINT') ??
|
|
42
|
+
'http://localhost:9411/api/v2/spans');
|
|
33
43
|
this._send = (0, index_1.prepareSend)(this._urlStr, config.headers);
|
|
34
44
|
this._serviceName = config.serviceName;
|
|
35
45
|
this._statusCodeTagName =
|
package/build/src/zipkin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zipkin.js","sourceRoot":"","sources":["../../src/zipkin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"zipkin.js","sourceRoot":"","sources":["../../src/zipkin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,8CAI6B;AAE7B,4CAA+C;AAE/C,2CAIqB;AACrB,8EAA+E;AAC/E,mCAA4C;AAE5C;;GAEG;AACH,MAAa,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;IACr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;IACK,UAAU,CAChB,KAAqB,EACrB,WAAmB,EACnB,IAAqC;QAErC,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CACnC,IAAA,wBAAY,EACV,IAAI,EACJ,MAAM,CACJ,IAAI,CAAC,UAAU,CAAC,+CAAwB,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,+CAAwB,CAAC;YAClD,WAAW,CACd,EACD,IAAI,CAAC,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;AAhID,wCAgIC","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/exporter-zipkin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-dev.1",
|
|
4
4
|
"description": "OpenTelemetry Zipkin Exporter allows the user to send collected traces to Zipkin.",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"author": "OpenTelemetry Authors",
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
41
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
42
|
+
"node": "^18.19.0 || >=20.6.0"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"build/esm/**/*.js",
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@babel/core": "7.26.
|
|
63
|
-
"@babel/preset-env": "7.26.
|
|
62
|
+
"@babel/core": "7.26.9",
|
|
63
|
+
"@babel/preset-env": "7.26.9",
|
|
64
64
|
"@opentelemetry/api": "^1.0.0",
|
|
65
65
|
"@types/mocha": "10.0.10",
|
|
66
66
|
"@types/node": "18.6.5",
|
|
67
|
-
"@types/sinon": "17.0.
|
|
67
|
+
"@types/sinon": "17.0.4",
|
|
68
68
|
"@types/webpack-env": "1.16.3",
|
|
69
|
-
"babel-loader": "
|
|
69
|
+
"babel-loader": "9.2.1",
|
|
70
70
|
"babel-plugin-istanbul": "7.0.0",
|
|
71
71
|
"cross-var": "1.1.0",
|
|
72
72
|
"karma": "6.4.4",
|
|
@@ -76,26 +76,25 @@
|
|
|
76
76
|
"karma-spec-reporter": "0.0.36",
|
|
77
77
|
"karma-webpack": "5.0.1",
|
|
78
78
|
"lerna": "6.6.2",
|
|
79
|
-
"mocha": "
|
|
80
|
-
"nock": "13.
|
|
81
|
-
"nyc": "
|
|
79
|
+
"mocha": "11.1.0",
|
|
80
|
+
"nock": "13.5.6",
|
|
81
|
+
"nyc": "17.1.0",
|
|
82
82
|
"sinon": "15.1.2",
|
|
83
|
-
"ts-loader": "9.5.
|
|
84
|
-
"typescript": "
|
|
83
|
+
"ts-loader": "9.5.2",
|
|
84
|
+
"typescript": "5.0.4",
|
|
85
85
|
"webpack": "5.96.1",
|
|
86
|
-
"webpack-cli": "
|
|
87
|
-
"webpack-merge": "5.10.0"
|
|
86
|
+
"webpack-cli": "6.0.1"
|
|
88
87
|
},
|
|
89
88
|
"peerDependencies": {
|
|
90
89
|
"@opentelemetry/api": "^1.0.0"
|
|
91
90
|
},
|
|
92
91
|
"dependencies": {
|
|
93
|
-
"@opentelemetry/core": "
|
|
94
|
-
"@opentelemetry/resources": "
|
|
95
|
-
"@opentelemetry/sdk-trace-base": "
|
|
96
|
-
"@opentelemetry/semantic-conventions": "1.
|
|
92
|
+
"@opentelemetry/core": "2.0.0-dev.1",
|
|
93
|
+
"@opentelemetry/resources": "2.0.0-dev.1",
|
|
94
|
+
"@opentelemetry/sdk-trace-base": "2.0.0-dev.1",
|
|
95
|
+
"@opentelemetry/semantic-conventions": "^1.29.0"
|
|
97
96
|
},
|
|
98
97
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-exporter-zipkin",
|
|
99
98
|
"sideEffects": false,
|
|
100
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "92fde6aa77e464ee85c4a18f279fe12294f625d1"
|
|
101
100
|
}
|