@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,158 @@
1
+ import { ExportResult } from '@opentelemetry/core';
2
+ /**
3
+ * Exporter config
4
+ */
5
+ export interface ExporterConfig {
6
+ headers?: Record<string, string>;
7
+ serviceName?: string;
8
+ url?: string;
9
+ statusCodeTagName?: string;
10
+ statusDescriptionTagName?: string;
11
+ getExportRequestHeaders?: () => Record<string, string> | undefined;
12
+ }
13
+ /**
14
+ * Zipkin Span
15
+ * @see https://github.com/openzipkin/zipkin-api/blob/master/zipkin2-api.yaml
16
+ */
17
+ export interface Span {
18
+ /**
19
+ * Trace identifier, set on all spans within it.
20
+ */
21
+ traceId: string;
22
+ /**
23
+ * The logical operation this span represents in lowercase (e.g. rpc method).
24
+ * Leave absent if unknown.
25
+ */
26
+ name: string;
27
+ /**
28
+ * The parent span ID or absent if this the root span in a trace.
29
+ */
30
+ parentId?: string;
31
+ /**
32
+ * Unique 64bit identifier for this operation within the trace.
33
+ */
34
+ id: string;
35
+ /**
36
+ * When present, kind clarifies timestamp, duration and remoteEndpoint.
37
+ * When absent, the span is local or incomplete.
38
+ */
39
+ kind?: SpanKind;
40
+ /**
41
+ * Epoch microseconds of the start of this span, possibly absent if
42
+ * incomplete.
43
+ */
44
+ timestamp: number;
45
+ /**
46
+ * Duration in microseconds of the critical path, if known.
47
+ */
48
+ duration: number;
49
+ /**
50
+ * True is a request to store this span even if it overrides sampling policy.
51
+ * This is true when the `X-B3-Flags` header has a value of 1.
52
+ */
53
+ debug?: boolean;
54
+ /**
55
+ * True if we are contributing to a span started by another tracer (ex on a
56
+ * different host).
57
+ */
58
+ shared?: boolean;
59
+ /**
60
+ * The host that recorded this span, primarily for query by service name.
61
+ */
62
+ localEndpoint: Endpoint;
63
+ /**
64
+ * Associates events that explain latency with the time they happened.
65
+ */
66
+ annotations?: Annotation[];
67
+ /**
68
+ * Tags give your span context for search, viewing and analysis.
69
+ */
70
+ tags: Tags;
71
+ }
72
+ /**
73
+ * Associates an event that explains latency with a timestamp.
74
+ * Unlike log statements, annotations are often codes. Ex. "ws" for WireSend
75
+ * Zipkin v1 core annotations such as "cs" and "sr" have been replaced with
76
+ * Span.Kind, which interprets timestamp and duration.
77
+ */
78
+ export interface Annotation {
79
+ /**
80
+ * Epoch microseconds of this event.
81
+ * For example, 1502787600000000 corresponds to 2017-08-15 09:00 UTC
82
+ */
83
+ timestamp: number;
84
+ /**
85
+ * Usually a short tag indicating an event, like "error"
86
+ * While possible to add larger data, such as garbage collection details, low
87
+ * cardinality event names both keep the size of spans down and also are easy
88
+ * to search against.
89
+ */
90
+ value: string;
91
+ }
92
+ /**
93
+ * The network context of a node in the service graph.
94
+ */
95
+ export interface Endpoint {
96
+ /**
97
+ * Lower-case label of this node in the service graph, such as "favstar".
98
+ * Leave absent if unknown.
99
+ * This is a primary label for trace lookup and aggregation, so it should be
100
+ * intuitive and consistent. Many use a name from service discovery.
101
+ */
102
+ serviceName?: string;
103
+ /**
104
+ * The text representation of the primary IPv4 address associated with this
105
+ * connection. Ex. 192.168.99.100 Absent if unknown.
106
+ */
107
+ ipv4?: string;
108
+ /**
109
+ * The text representation of the primary IPv6 address associated with a
110
+ * connection. Ex. 2001:db8::c001 Absent if unknown.
111
+ * Prefer using the ipv4 field for mapped addresses.
112
+ */
113
+ port?: number;
114
+ }
115
+ /**
116
+ * Adds context to a span, for search, viewing and analysis.
117
+ * For example, a key "your_app.version" would let you lookup traces by version.
118
+ * A tag "sql.query" isn't searchable, but it can help in debugging when viewing
119
+ * a trace.
120
+ */
121
+ export interface Tags {
122
+ [tagKey: string]: unknown;
123
+ }
124
+ /**
125
+ * When present, kind clarifies timestamp, duration and remoteEndpoint. When
126
+ * absent, the span is local or incomplete. Unlike client and server, there
127
+ * is no direct critical path latency relationship between producer and
128
+ * consumer spans.
129
+ * `CLIENT`
130
+ * timestamp is the moment a request was sent to the server.
131
+ * duration is the delay until a response or an error was received.
132
+ * remoteEndpoint is the server.
133
+ * `SERVER`
134
+ * timestamp is the moment a client request was received.
135
+ * duration is the delay until a response was sent or an error.
136
+ * remoteEndpoint is the client.
137
+ * `PRODUCER`
138
+ * timestamp is the moment a message was sent to a destination.
139
+ * duration is the delay sending the message, such as batching.
140
+ * remoteEndpoint is the broker.
141
+ * `CONSUMER`
142
+ * timestamp is the moment a message was received from an origin.
143
+ * duration is the delay consuming the message, such as from backlog.
144
+ * remoteEndpoint - Represents the broker. Leave serviceName absent if unknown.
145
+ */
146
+ export declare enum SpanKind {
147
+ CLIENT = "CLIENT",
148
+ SERVER = "SERVER",
149
+ CONSUMER = "CONSUMER",
150
+ PRODUCER = "PRODUCER"
151
+ }
152
+ /**
153
+ * interface for function that will send zipkin spans
154
+ */
155
+ export declare type SendFunction = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
156
+ export declare type GetHeaders = () => Record<string, string> | undefined;
157
+ export declare type SendFn = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
158
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,45 @@
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
+ /**
17
+ * When present, kind clarifies timestamp, duration and remoteEndpoint. When
18
+ * absent, the span is local or incomplete. Unlike client and server, there
19
+ * is no direct critical path latency relationship between producer and
20
+ * consumer spans.
21
+ * `CLIENT`
22
+ * timestamp is the moment a request was sent to the server.
23
+ * duration is the delay until a response or an error was received.
24
+ * remoteEndpoint is the server.
25
+ * `SERVER`
26
+ * timestamp is the moment a client request was received.
27
+ * duration is the delay until a response was sent or an error.
28
+ * remoteEndpoint is the client.
29
+ * `PRODUCER`
30
+ * timestamp is the moment a message was sent to a destination.
31
+ * duration is the delay sending the message, such as batching.
32
+ * remoteEndpoint is the broker.
33
+ * `CONSUMER`
34
+ * timestamp is the moment a message was received from an origin.
35
+ * duration is the delay consuming the message, such as from backlog.
36
+ * remoteEndpoint - Represents the broker. Leave serviceName absent if unknown.
37
+ */
38
+ export var SpanKind;
39
+ (function (SpanKind) {
40
+ SpanKind["CLIENT"] = "CLIENT";
41
+ SpanKind["SERVER"] = "SERVER";
42
+ SpanKind["CONSUMER"] = "CONSUMER";
43
+ SpanKind["PRODUCER"] = "PRODUCER";
44
+ })(SpanKind || (SpanKind = {}));
45
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAyIH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;AACvB,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB","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 { ExportResult } from '@opentelemetry/core';\n\n/**\n * Exporter config\n */\nexport interface ExporterConfig {\n headers?: Record<string, string>;\n serviceName?: string;\n url?: string;\n // Optional mapping overrides for OpenTelemetry status code and description.\n statusCodeTagName?: string;\n statusDescriptionTagName?: string;\n getExportRequestHeaders?: () => Record<string, string> | undefined;\n}\n\n/**\n * Zipkin Span\n * @see https://github.com/openzipkin/zipkin-api/blob/master/zipkin2-api.yaml\n */\nexport interface Span {\n /**\n * Trace identifier, set on all spans within it.\n */\n traceId: string;\n /**\n * The logical operation this span represents in lowercase (e.g. rpc method).\n * Leave absent if unknown.\n */\n name: string;\n /**\n * The parent span ID or absent if this the root span in a trace.\n */\n parentId?: string;\n /**\n * Unique 64bit identifier for this operation within the trace.\n */\n id: string;\n /**\n * When present, kind clarifies timestamp, duration and remoteEndpoint.\n * When absent, the span is local or incomplete.\n */\n kind?: SpanKind;\n /**\n * Epoch microseconds of the start of this span, possibly absent if\n * incomplete.\n */\n timestamp: number;\n /**\n * Duration in microseconds of the critical path, if known.\n */\n duration: number;\n /**\n * True is a request to store this span even if it overrides sampling policy.\n * This is true when the `X-B3-Flags` header has a value of 1.\n */\n debug?: boolean;\n /**\n * True if we are contributing to a span started by another tracer (ex on a\n * different host).\n */\n shared?: boolean;\n /**\n * The host that recorded this span, primarily for query by service name.\n */\n localEndpoint: Endpoint;\n /**\n * Associates events that explain latency with the time they happened.\n */\n annotations?: Annotation[];\n /**\n * Tags give your span context for search, viewing and analysis.\n */\n tags: Tags;\n /**\n * TODO: `remoteEndpoint`, do we need to support it?\n * When an RPC (or messaging) span, indicates the other side of the\n * connection.\n */\n}\n\n/**\n * Associates an event that explains latency with a timestamp.\n * Unlike log statements, annotations are often codes. Ex. \"ws\" for WireSend\n * Zipkin v1 core annotations such as \"cs\" and \"sr\" have been replaced with\n * Span.Kind, which interprets timestamp and duration.\n */\nexport interface Annotation {\n /**\n * Epoch microseconds of this event.\n * For example, 1502787600000000 corresponds to 2017-08-15 09:00 UTC\n */\n timestamp: number;\n /**\n * Usually a short tag indicating an event, like \"error\"\n * While possible to add larger data, such as garbage collection details, low\n * cardinality event names both keep the size of spans down and also are easy\n * to search against.\n */\n value: string;\n}\n\n/**\n * The network context of a node in the service graph.\n */\nexport interface Endpoint {\n /**\n * Lower-case label of this node in the service graph, such as \"favstar\".\n * Leave absent if unknown.\n * This is a primary label for trace lookup and aggregation, so it should be\n * intuitive and consistent. Many use a name from service discovery.\n */\n serviceName?: string;\n /**\n * The text representation of the primary IPv4 address associated with this\n * connection. Ex. 192.168.99.100 Absent if unknown.\n */\n ipv4?: string;\n /**\n * The text representation of the primary IPv6 address associated with a\n * connection. Ex. 2001:db8::c001 Absent if unknown.\n * Prefer using the ipv4 field for mapped addresses.\n */\n port?: number;\n}\n\n/**\n * Adds context to a span, for search, viewing and analysis.\n * For example, a key \"your_app.version\" would let you lookup traces by version.\n * A tag \"sql.query\" isn't searchable, but it can help in debugging when viewing\n * a trace.\n */\nexport interface Tags {\n [tagKey: string]: unknown;\n}\n\n/**\n * When present, kind clarifies timestamp, duration and remoteEndpoint. When\n * absent, the span is local or incomplete. Unlike client and server, there\n * is no direct critical path latency relationship between producer and\n * consumer spans.\n * `CLIENT`\n * timestamp is the moment a request was sent to the server.\n * duration is the delay until a response or an error was received.\n * remoteEndpoint is the server.\n * `SERVER`\n * timestamp is the moment a client request was received.\n * duration is the delay until a response was sent or an error.\n * remoteEndpoint is the client.\n * `PRODUCER`\n * timestamp is the moment a message was sent to a destination.\n * duration is the delay sending the message, such as batching.\n * remoteEndpoint is the broker.\n * `CONSUMER`\n * timestamp is the moment a message was received from an origin.\n * duration is the delay consuming the message, such as from backlog.\n * remoteEndpoint - Represents the broker. Leave serviceName absent if unknown.\n */\nexport enum SpanKind {\n CLIENT = 'CLIENT',\n SERVER = 'SERVER',\n CONSUMER = 'CONSUMER',\n PRODUCER = 'PRODUCER',\n}\n\n/**\n * interface for function that will send zipkin spans\n */\nexport type SendFunction = (\n zipkinSpans: Span[],\n done: (result: ExportResult) => void\n) => void;\n\nexport type GetHeaders = () => Record<string, string> | undefined;\n\nexport type SendFn = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;\n"]}
@@ -0,0 +1,3 @@
1
+ import { GetHeaders } from './types';
2
+ export declare function prepareGetHeaders(getExportRequestHeaders: GetHeaders): () => Record<string, string> | undefined;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,6 @@
1
+ export function prepareGetHeaders(getExportRequestHeaders) {
2
+ return function () {
3
+ return getExportRequestHeaders();
4
+ };
5
+ }
6
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,iBAAiB,CAC/B,uBAAmC;IAEnC,OAAO;QACL,OAAO,uBAAuB,EAAE,CAAC;IACnC,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 */\nimport { GetHeaders } from './types';\n\nexport function prepareGetHeaders(\n getExportRequestHeaders: GetHeaders\n): () => Record<string, string> | undefined {\n return function () {\n return getExportRequestHeaders();\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const VERSION = "1.1.1";
2
+ //# sourceMappingURL=version.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
+ // this is autogenerated file, see scripts/version-update.js
17
+ export var VERSION = '1.1.1';
18
+ //# sourceMappingURL=version.js.map
@@ -0,0 +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.1.1';\n"]}
@@ -0,0 +1,38 @@
1
+ import { ExportResult } from '@opentelemetry/core';
2
+ import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
3
+ import * as zipkinTypes from './types';
4
+ /**
5
+ * Zipkin Exporter
6
+ */
7
+ export declare class ZipkinExporter implements SpanExporter {
8
+ private readonly DEFAULT_SERVICE_NAME;
9
+ private readonly _statusCodeTagName;
10
+ private readonly _statusDescriptionTagName;
11
+ private _urlStr;
12
+ private _send;
13
+ private _getHeaders;
14
+ private _serviceName?;
15
+ private _isShutdown;
16
+ private _sendingPromises;
17
+ constructor(config?: zipkinTypes.ExporterConfig);
18
+ /**
19
+ * Export spans.
20
+ */
21
+ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
22
+ /**
23
+ * Shutdown exporter. Noop operation in this exporter.
24
+ */
25
+ shutdown(): Promise<void>;
26
+ /**
27
+ * if user defines getExportRequestHeaders in config then this will be called
28
+ * everytime before send, otherwise it will be replaced with noop in
29
+ * constructor
30
+ * @default noop
31
+ */
32
+ private _beforeSend;
33
+ /**
34
+ * Transform spans and sends to Zipkin service.
35
+ */
36
+ private _sendSpans;
37
+ }
38
+ //# sourceMappingURL=zipkin.d.ts.map
@@ -0,0 +1,120 @@
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, getEnv } from '@opentelemetry/core';
18
+ import { prepareSend } from './platform/index';
19
+ import { toZipkinSpan, defaultStatusCodeTagName, defaultStatusErrorTagName, } from './transform';
20
+ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
21
+ import { prepareGetHeaders } from './utils';
22
+ /**
23
+ * Zipkin Exporter
24
+ */
25
+ var ZipkinExporter = /** @class */ (function () {
26
+ function ZipkinExporter(config) {
27
+ if (config === void 0) { config = {}; }
28
+ this.DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
29
+ this._sendingPromises = [];
30
+ this._urlStr = config.url || getEnv().OTEL_EXPORTER_ZIPKIN_ENDPOINT;
31
+ this._send = prepareSend(this._urlStr, config.headers);
32
+ this._serviceName = config.serviceName;
33
+ this._statusCodeTagName = config.statusCodeTagName || defaultStatusCodeTagName;
34
+ this._statusDescriptionTagName =
35
+ config.statusDescriptionTagName || defaultStatusErrorTagName;
36
+ this._isShutdown = false;
37
+ if (typeof config.getExportRequestHeaders === 'function') {
38
+ this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders);
39
+ }
40
+ else {
41
+ // noop
42
+ this._beforeSend = function () { };
43
+ }
44
+ }
45
+ /**
46
+ * Export spans.
47
+ */
48
+ ZipkinExporter.prototype.export = function (spans, resultCallback) {
49
+ var _this = this;
50
+ var serviceName = String(this._serviceName ||
51
+ spans[0].resource.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
52
+ this.DEFAULT_SERVICE_NAME);
53
+ diag.debug('Zipkin exporter export');
54
+ if (this._isShutdown) {
55
+ setTimeout(function () {
56
+ return resultCallback({
57
+ code: ExportResultCode.FAILED,
58
+ error: new Error('Exporter has been shutdown'),
59
+ });
60
+ });
61
+ return;
62
+ }
63
+ var promise = new Promise(function (resolve) {
64
+ _this._sendSpans(spans, serviceName, function (result) {
65
+ resolve();
66
+ resultCallback(result);
67
+ });
68
+ });
69
+ this._sendingPromises.push(promise);
70
+ var popPromise = function () {
71
+ var index = _this._sendingPromises.indexOf(promise);
72
+ _this._sendingPromises.splice(index, 1);
73
+ };
74
+ promise.then(popPromise, popPromise);
75
+ };
76
+ /**
77
+ * Shutdown exporter. Noop operation in this exporter.
78
+ */
79
+ ZipkinExporter.prototype.shutdown = function () {
80
+ var _this = this;
81
+ diag.debug('Zipkin exporter shutdown');
82
+ this._isShutdown = true;
83
+ return new Promise(function (resolve, reject) {
84
+ Promise.all(_this._sendingPromises).then(function () {
85
+ resolve();
86
+ }, reject);
87
+ });
88
+ };
89
+ /**
90
+ * if user defines getExportRequestHeaders in config then this will be called
91
+ * everytime before send, otherwise it will be replaced with noop in
92
+ * constructor
93
+ * @default noop
94
+ */
95
+ ZipkinExporter.prototype._beforeSend = function () {
96
+ if (this._getHeaders) {
97
+ this._send = prepareSend(this._urlStr, this._getHeaders());
98
+ }
99
+ };
100
+ /**
101
+ * Transform spans and sends to Zipkin service.
102
+ */
103
+ ZipkinExporter.prototype._sendSpans = function (spans, serviceName, done) {
104
+ var _this = this;
105
+ var zipkinSpans = spans.map(function (span) {
106
+ return toZipkinSpan(span, String(span.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
107
+ span.resource.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
108
+ serviceName), _this._statusCodeTagName, _this._statusDescriptionTagName);
109
+ });
110
+ this._beforeSend();
111
+ return this._send(zipkinSpans, function (result) {
112
+ if (done) {
113
+ return done(result);
114
+ }
115
+ });
116
+ };
117
+ return ZipkinExporter;
118
+ }());
119
+ export { ZipkinExporter };
120
+ //# sourceMappingURL=zipkin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zipkin.js","sourceRoot":"","sources":["../../src/zipkin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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gBAAgB,CAAC,CAAC,IAAI,CAAC;gBACtC,OAAO,EAAE,CAAC;YACZ,CAAC,EAAE,MAAM,CAAC,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACK,oCAAW,GAAnB;QACE,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,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,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,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;IACzE,IAAI,OAAO,EAAE;QACX,UAAU,mBACR,MAAM,EAAE,kBAAkB,EAC1B,cAAc,EAAE,kBAAkB,IAC/B,OAAO,CACX,CAAC;KACH;IAED;;OAEG;IACH,OAAO,SAAS,IAAI,CAClB,WAA+B,EAC/B,IAAoC;QAEpC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAC3C,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAI,SAAS,EAAE;YACb,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;SACvC;aAAM;YACL,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;SAChD;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,c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ACL,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(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