@opentelemetry/exporter-zipkin 1.1.0 → 1.1.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.
Files changed (70) hide show
  1. package/build/esm/index.d.ts +4 -0
  2. package/build/esm/index.js +18 -0
  3. package/build/esm/index.js.map +1 -0
  4. package/build/esm/platform/browser/index.d.ts +2 -0
  5. package/build/esm/platform/browser/index.js +17 -0
  6. package/build/esm/platform/browser/index.js.map +1 -0
  7. package/build/esm/platform/browser/util.d.ts +9 -0
  8. package/build/esm/platform/browser/util.js +130 -0
  9. package/build/esm/platform/browser/util.js.map +1 -0
  10. package/build/esm/platform/index.d.ts +2 -0
  11. package/build/esm/platform/index.js +17 -0
  12. package/build/esm/platform/index.js.map +1 -0
  13. package/build/esm/platform/node/index.d.ts +2 -0
  14. package/build/esm/platform/node/index.js +17 -0
  15. package/build/esm/platform/node/index.js.map +1 -0
  16. package/build/esm/platform/node/util.d.ts +9 -0
  17. package/build/esm/platform/node/util.js +87 -0
  18. package/build/esm/platform/node/util.js.map +1 -0
  19. package/build/esm/transform.d.ts +18 -0
  20. package/build/esm/transform.js +97 -0
  21. package/build/esm/transform.js.map +1 -0
  22. package/build/esm/types.d.ts +158 -0
  23. package/build/esm/types.js +45 -0
  24. package/build/esm/types.js.map +1 -0
  25. package/build/esm/utils.d.ts +3 -0
  26. package/build/esm/utils.js +6 -0
  27. package/build/esm/utils.js.map +1 -0
  28. package/build/esm/version.d.ts +2 -0
  29. package/build/esm/version.js +18 -0
  30. package/build/esm/version.js.map +1 -0
  31. package/build/esm/zipkin.d.ts +38 -0
  32. package/build/esm/zipkin.js +120 -0
  33. package/build/esm/zipkin.js.map +1 -0
  34. package/build/esnext/index.d.ts +4 -0
  35. package/build/esnext/index.js +18 -0
  36. package/build/esnext/index.js.map +1 -0
  37. package/build/esnext/platform/browser/index.d.ts +2 -0
  38. package/build/esnext/platform/browser/index.js +17 -0
  39. package/build/esnext/platform/browser/index.js.map +1 -0
  40. package/build/esnext/platform/browser/util.d.ts +9 -0
  41. package/build/esnext/platform/browser/util.js +101 -0
  42. package/build/esnext/platform/browser/util.js.map +1 -0
  43. package/build/esnext/platform/index.d.ts +2 -0
  44. package/build/esnext/platform/index.js +17 -0
  45. package/build/esnext/platform/index.js.map +1 -0
  46. package/build/esnext/platform/node/index.d.ts +2 -0
  47. package/build/esnext/platform/node/index.js +17 -0
  48. package/build/esnext/platform/node/index.js.map +1 -0
  49. package/build/esnext/platform/node/util.d.ts +9 -0
  50. package/build/esnext/platform/node/util.js +76 -0
  51. package/build/esnext/platform/node/util.js.map +1 -0
  52. package/build/esnext/transform.d.ts +18 -0
  53. package/build/esnext/transform.js +74 -0
  54. package/build/esnext/transform.js.map +1 -0
  55. package/build/esnext/types.d.ts +158 -0
  56. package/build/esnext/types.js +45 -0
  57. package/build/esnext/types.js.map +1 -0
  58. package/build/esnext/utils.d.ts +3 -0
  59. package/build/esnext/utils.js +6 -0
  60. package/build/esnext/utils.js.map +1 -0
  61. package/build/esnext/version.d.ts +2 -0
  62. package/build/esnext/version.js +18 -0
  63. package/build/esnext/version.js.map +1 -0
  64. package/build/esnext/zipkin.d.ts +38 -0
  65. package/build/esnext/zipkin.js +110 -0
  66. package/build/esnext/zipkin.js.map +1 -0
  67. package/build/src/version.d.ts +1 -1
  68. package/build/src/version.js +1 -1
  69. package/build/src/version.js.map +1 -1
  70. package/package.json +7 -6
@@ -0,0 +1,4 @@
1
+ export * from './platform';
2
+ export { ExporterConfig } from './types';
3
+ export * from './zipkin';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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,2 @@
1
+ export * from './util';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,130 @@
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
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __read = (this && this.__read) || function (o, n) {
28
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
29
+ if (!m) return o;
30
+ var i = m.call(o), r, ar = [], e;
31
+ try {
32
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
33
+ }
34
+ catch (error) { e = { error: error }; }
35
+ finally {
36
+ try {
37
+ if (r && !r.done && (m = i["return"])) m.call(i);
38
+ }
39
+ finally { if (e) throw e.error; }
40
+ }
41
+ return ar;
42
+ };
43
+ import { diag } from '@opentelemetry/api';
44
+ import { ExportResultCode, globalErrorHandler, } from '@opentelemetry/core';
45
+ /**
46
+ * Prepares send function that will send spans to the remote Zipkin service.
47
+ * @param urlStr - url to send spans
48
+ * @param headers - headers
49
+ * send
50
+ */
51
+ export function prepareSend(urlStr, headers) {
52
+ var xhrHeaders;
53
+ var useBeacon = typeof navigator.sendBeacon === 'function' && !headers;
54
+ if (headers) {
55
+ xhrHeaders = __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, headers);
56
+ }
57
+ /**
58
+ * Send spans to the remote Zipkin service.
59
+ */
60
+ return function send(zipkinSpans, done) {
61
+ if (zipkinSpans.length === 0) {
62
+ diag.debug('Zipkin send with empty spans');
63
+ return done({ code: ExportResultCode.SUCCESS });
64
+ }
65
+ var payload = JSON.stringify(zipkinSpans);
66
+ if (useBeacon) {
67
+ sendWithBeacon(payload, done, urlStr);
68
+ }
69
+ else {
70
+ sendWithXhr(payload, done, urlStr, xhrHeaders);
71
+ }
72
+ };
73
+ }
74
+ /**
75
+ * Sends data using beacon
76
+ * @param data
77
+ * @param done
78
+ * @param urlStr
79
+ */
80
+ function sendWithBeacon(data, done, urlStr) {
81
+ if (navigator.sendBeacon(urlStr, data)) {
82
+ diag.debug('sendBeacon - can send', data);
83
+ done({ code: ExportResultCode.SUCCESS });
84
+ }
85
+ else {
86
+ done({
87
+ code: ExportResultCode.FAILED,
88
+ error: new Error("sendBeacon - cannot send " + data),
89
+ });
90
+ }
91
+ }
92
+ /**
93
+ * Sends data using XMLHttpRequest
94
+ * @param data
95
+ * @param done
96
+ * @param urlStr
97
+ * @param xhrHeaders
98
+ */
99
+ function sendWithXhr(data, done, urlStr, xhrHeaders) {
100
+ if (xhrHeaders === void 0) { xhrHeaders = {}; }
101
+ var xhr = new XMLHttpRequest();
102
+ xhr.open('POST', urlStr);
103
+ Object.entries(xhrHeaders).forEach(function (_a) {
104
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
105
+ xhr.setRequestHeader(k, v);
106
+ });
107
+ xhr.onreadystatechange = function () {
108
+ if (xhr.readyState === XMLHttpRequest.DONE) {
109
+ var statusCode = xhr.status || 0;
110
+ diag.debug("Zipkin response status code: " + statusCode + ", body: " + data);
111
+ if (xhr.status >= 200 && xhr.status < 400) {
112
+ return done({ code: ExportResultCode.SUCCESS });
113
+ }
114
+ else {
115
+ return done({
116
+ code: ExportResultCode.FAILED,
117
+ error: new Error("Got unexpected status code from zipkin: " + xhr.status),
118
+ });
119
+ }
120
+ }
121
+ };
122
+ xhr.onerror = function (msg) {
123
+ globalErrorHandler(new Error("Zipkin request error: " + msg));
124
+ return done({ code: ExportResultCode.FAILED });
125
+ };
126
+ // Issue request to remote service
127
+ diag.debug("Zipkin request payload: " + data);
128
+ xhr.send(data);
129
+ }
130
+ //# 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,IAAM,SAAS,GAAG,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,IAAI,CAAC,OAAO,CAAC;IACzE,IAAI,OAAO,EAAE;QACX,UAAU,cACR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\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,2 @@
1
+ export * from './node';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,2 @@
1
+ export * from './util';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,87 @@
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
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import { diag } from '@opentelemetry/api';
28
+ import { ExportResultCode } from '@opentelemetry/core';
29
+ import * as http from 'http';
30
+ import * as https from 'https';
31
+ import * as url from 'url';
32
+ /**
33
+ * Prepares send function that will send spans to the remote Zipkin service.
34
+ * @param urlStr - url to send spans
35
+ * @param headers - headers
36
+ * send
37
+ */
38
+ export function prepareSend(urlStr, headers) {
39
+ var urlOpts = url.parse(urlStr);
40
+ var reqOpts = Object.assign({
41
+ method: 'POST',
42
+ headers: __assign({ 'Content-Type': 'application/json' }, headers),
43
+ }, urlOpts);
44
+ /**
45
+ * Send spans to the remote Zipkin service.
46
+ */
47
+ return function send(zipkinSpans, done) {
48
+ if (zipkinSpans.length === 0) {
49
+ diag.debug('Zipkin send with empty spans');
50
+ return done({ code: ExportResultCode.SUCCESS });
51
+ }
52
+ var request = (reqOpts.protocol === 'http:' ? http : https).request;
53
+ var req = request(reqOpts, function (res) {
54
+ var rawData = '';
55
+ res.on('data', function (chunk) {
56
+ rawData += chunk;
57
+ });
58
+ res.on('end', function () {
59
+ var statusCode = res.statusCode || 0;
60
+ diag.debug("Zipkin response status code: " + statusCode + ", body: " + rawData);
61
+ // Consider 2xx and 3xx as success.
62
+ if (statusCode < 400) {
63
+ return done({ code: ExportResultCode.SUCCESS });
64
+ // Consider 4xx as failed non-retriable.
65
+ }
66
+ else {
67
+ return done({
68
+ code: ExportResultCode.FAILED,
69
+ error: new Error("Got unexpected status code from zipkin: " + statusCode),
70
+ });
71
+ }
72
+ });
73
+ });
74
+ req.on('error', function (error) {
75
+ return done({
76
+ code: ExportResultCode.FAILED,
77
+ error: error,
78
+ });
79
+ });
80
+ // Issue request to remote service
81
+ var payload = JSON.stringify(zipkinSpans);
82
+ diag.debug("Zipkin request payload: " + payload);
83
+ req.write(payload, 'utf8');
84
+ req.end();
85
+ };
86
+ }
87
+ //# sourceMappingURL=util.js.map
@@ -0,0 +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;AAC/B,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAG3B;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,OAAgC;IAC1E,IAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAElC,IAAM,OAAO,GAAwB,MAAM,CAAC,MAAM,CAChD;QACE,MAAM,EAAE,MAAM;QACd,OAA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E,UAAA,KAAK;YACnB,OAAO,IAAI,CAAC;gBACV,IAAI,EAAE,gBAAgB,CAAC,MAAM;gBAC7B,KAAK,OAAA;aACN,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,kCAAkC;QAClC,IAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,CAAC,6BAA2B,OAAS,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
@@ -0,0 +1,97 @@
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
+ var __values = (this && this.__values) || function(o) {
17
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
18
+ if (m) return m.call(o);
19
+ if (o && typeof o.length === "number") return {
20
+ next: function () {
21
+ if (o && i >= o.length) o = void 0;
22
+ return { value: o && o[i++], done: !o };
23
+ }
24
+ };
25
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
26
+ };
27
+ var _a;
28
+ import * as api from '@opentelemetry/api';
29
+ import { hrTimeToMicroseconds } from '@opentelemetry/core';
30
+ import * as zipkinTypes from './types';
31
+ var ZIPKIN_SPAN_KIND_MAPPING = (_a = {},
32
+ _a[api.SpanKind.CLIENT] = zipkinTypes.SpanKind.CLIENT,
33
+ _a[api.SpanKind.SERVER] = zipkinTypes.SpanKind.SERVER,
34
+ _a[api.SpanKind.CONSUMER] = zipkinTypes.SpanKind.CONSUMER,
35
+ _a[api.SpanKind.PRODUCER] = zipkinTypes.SpanKind.PRODUCER,
36
+ // When absent, the span is local.
37
+ _a[api.SpanKind.INTERNAL] = undefined,
38
+ _a);
39
+ export var defaultStatusCodeTagName = 'otel.status_code';
40
+ export var defaultStatusErrorTagName = 'error';
41
+ /**
42
+ * Translate OpenTelemetry ReadableSpan to ZipkinSpan format
43
+ * @param span Span to be translated
44
+ */
45
+ export function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTagName) {
46
+ var zipkinSpan = {
47
+ traceId: span.spanContext().traceId,
48
+ parentId: span.parentSpanId,
49
+ name: span.name,
50
+ id: span.spanContext().spanId,
51
+ kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
52
+ timestamp: hrTimeToMicroseconds(span.startTime),
53
+ duration: hrTimeToMicroseconds(span.duration),
54
+ localEndpoint: { serviceName: serviceName },
55
+ tags: _toZipkinTags(span.attributes, span.status, statusCodeTagName, statusErrorTagName, span.resource),
56
+ annotations: span.events.length
57
+ ? _toZipkinAnnotations(span.events)
58
+ : undefined,
59
+ };
60
+ return zipkinSpan;
61
+ }
62
+ /** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */
63
+ export function _toZipkinTags(attributes, status, statusCodeTagName, statusErrorTagName, resource) {
64
+ var e_1, _a;
65
+ var tags = {};
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; }
78
+ }
79
+ if (status.code !== api.SpanStatusCode.UNSET) {
80
+ tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
81
+ }
82
+ if (status.code === api.SpanStatusCode.ERROR && status.message) {
83
+ tags[statusErrorTagName] = status.message;
84
+ }
85
+ Object.keys(resource.attributes).forEach(function (name) { return (tags[name] = String(resource.attributes[name])); });
86
+ return tags;
87
+ }
88
+ /**
89
+ * Converts OpenTelemetry Events to Zipkin Annotations format.
90
+ */
91
+ export function _toZipkinAnnotations(events) {
92
+ return events.map(function (event) { return ({
93
+ timestamp: hrTimeToMicroseconds(event.time),
94
+ value: event.name,
95
+ }); });
96
+ }
97
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/transform.ts"],"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C,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"]}