@uoa/lambda-tracing 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,160 +0,0 @@
1
- /**
2
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/types.ts
3
- */
4
- import { ExportResult } from '@opentelemetry/core';
5
- /**
6
- * Exporter config
7
- */
8
- export interface ExporterConfig {
9
- headers?: Record<string, string>;
10
- serviceName?: string;
11
- url?: string;
12
- statusCodeTagName?: string;
13
- statusDescriptionTagName?: string;
14
- getExportRequestHeaders?: () => Record<string, string> | undefined;
15
- }
16
- /**
17
- * Zipkin Span
18
- * @see https://github.com/openzipkin/zipkin-api/blob/master/zipkin2-api.yaml
19
- */
20
- export interface Span {
21
- /**
22
- * Trace identifier, set on all spans within it.
23
- */
24
- traceId: string;
25
- /**
26
- * The logical operation this span represents in lowercase (e.g. rpc method).
27
- * Leave absent if unknown.
28
- */
29
- name: string;
30
- /**
31
- * The parent span ID or absent if this the root span in a trace.
32
- */
33
- parentId?: string;
34
- /**
35
- * Unique 64bit identifier for this operation within the trace.
36
- */
37
- id: string;
38
- /**
39
- * When present, kind clarifies timestamp, duration and remoteEndpoint.
40
- * When absent, the span is local or incomplete.
41
- */
42
- kind?: SpanKind;
43
- /**
44
- * Epoch microseconds of the start of this span, possibly absent if
45
- * incomplete.
46
- */
47
- timestamp: number;
48
- /**
49
- * Duration in microseconds of the critical path, if known.
50
- */
51
- duration: number;
52
- /**
53
- * True is a request to store this span even if it overrides sampling policy.
54
- * This is true when the `X-B3-Flags` header has a value of 1.
55
- */
56
- debug?: boolean;
57
- /**
58
- * True if we are contributing to a span started by another tracer (ex on a
59
- * different host).
60
- */
61
- shared?: boolean;
62
- /**
63
- * The host that recorded this span, primarily for query by service name.
64
- */
65
- localEndpoint: Endpoint;
66
- /**
67
- * Associates events that explain latency with the time they happened.
68
- */
69
- annotations?: Annotation[];
70
- /**
71
- * Tags give your span context for search, viewing and analysis.
72
- */
73
- tags: Tags;
74
- }
75
- /**
76
- * Associates an event that explains latency with a timestamp.
77
- * Unlike log statements, annotations are often codes. Ex. "ws" for WireSend
78
- * Zipkin v1 core annotations such as "cs" and "sr" have been replaced with
79
- * Span.Kind, which interprets timestamp and duration.
80
- */
81
- export interface Annotation {
82
- /**
83
- * Epoch microseconds of this event.
84
- * For example, 1502787600000000 corresponds to 2017-08-15 09:00 UTC
85
- */
86
- timestamp: number;
87
- /**
88
- * Usually a short tag indicating an event, like "error"
89
- * While possible to add larger data, such as garbage collection details, low
90
- * cardinality event names both keep the size of spans down and also are easy
91
- * to search against.
92
- */
93
- value: string;
94
- }
95
- /**
96
- * The network context of a node in the service graph.
97
- */
98
- export interface Endpoint {
99
- /**
100
- * Lower-case label of this node in the service graph, such as "favstar".
101
- * Leave absent if unknown.
102
- * This is a primary label for trace lookup and aggregation, so it should be
103
- * intuitive and consistent. Many use a name from service discovery.
104
- */
105
- serviceName?: string;
106
- /**
107
- * The text representation of the primary IPv4 address associated with this
108
- * connection. Ex. 192.168.99.100 Absent if unknown.
109
- */
110
- ipv4?: string;
111
- /**
112
- * The text representation of the primary IPv6 address associated with a
113
- * connection. Ex. 2001:db8::c001 Absent if unknown.
114
- * Prefer using the ipv4 field for mapped addresses.
115
- */
116
- port?: number;
117
- }
118
- /**
119
- * Adds context to a span, for search, viewing and analysis.
120
- * For example, a key "your_app.version" would let you lookup traces by version.
121
- * A tag "sql.query" isn't searchable, but it can help in debugging when viewing
122
- * a trace.
123
- */
124
- export interface Tags {
125
- [tagKey: string]: unknown;
126
- }
127
- /**
128
- * When present, kind clarifies timestamp, duration and remoteEndpoint. When
129
- * absent, the span is local or incomplete. Unlike client and server, there
130
- * is no direct critical path latency relationship between producer and
131
- * consumer spans.
132
- * `CLIENT`
133
- * timestamp is the moment a request was sent to the server.
134
- * duration is the delay until a response or an error was received.
135
- * remoteEndpoint is the server.
136
- * `SERVER`
137
- * timestamp is the moment a client request was received.
138
- * duration is the delay until a response was sent or an error.
139
- * remoteEndpoint is the client.
140
- * `PRODUCER`
141
- * timestamp is the moment a message was sent to a destination.
142
- * duration is the delay sending the message, such as batching.
143
- * remoteEndpoint is the broker.
144
- * `CONSUMER`
145
- * timestamp is the moment a message was received from an origin.
146
- * duration is the delay consuming the message, such as from backlog.
147
- * remoteEndpoint - Represents the broker. Leave serviceName absent if unknown.
148
- */
149
- export declare enum SpanKind {
150
- CLIENT = "CLIENT",
151
- SERVER = "SERVER",
152
- CONSUMER = "CONSUMER",
153
- PRODUCER = "PRODUCER"
154
- }
155
- /**
156
- * interface for function that will send zipkin spans
157
- */
158
- export declare type SendFunction = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
159
- export declare type GetHeaders = () => Record<string, string> | undefined;
160
- export declare type SendFn = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * https://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.SpanKind = void 0;
19
- /**
20
- * When present, kind clarifies timestamp, duration and remoteEndpoint. When
21
- * absent, the span is local or incomplete. Unlike client and server, there
22
- * is no direct critical path latency relationship between producer and
23
- * consumer spans.
24
- * `CLIENT`
25
- * timestamp is the moment a request was sent to the server.
26
- * duration is the delay until a response or an error was received.
27
- * remoteEndpoint is the server.
28
- * `SERVER`
29
- * timestamp is the moment a client request was received.
30
- * duration is the delay until a response was sent or an error.
31
- * remoteEndpoint is the client.
32
- * `PRODUCER`
33
- * timestamp is the moment a message was sent to a destination.
34
- * duration is the delay sending the message, such as batching.
35
- * remoteEndpoint is the broker.
36
- * `CONSUMER`
37
- * timestamp is the moment a message was received from an origin.
38
- * duration is the delay consuming the message, such as from backlog.
39
- * remoteEndpoint - Represents the broker. Leave serviceName absent if unknown.
40
- */
41
- var SpanKind;
42
- (function (SpanKind) {
43
- SpanKind["CLIENT"] = "CLIENT";
44
- SpanKind["SERVER"] = "SERVER";
45
- SpanKind["CONSUMER"] = "CONSUMER";
46
- SpanKind["PRODUCER"] = "PRODUCER";
47
- })(SpanKind = exports.SpanKind || (exports.SpanKind = {}));
@@ -1,5 +0,0 @@
1
- /**
2
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/utils.ts
3
- */
4
- import { GetHeaders } from './types';
5
- export declare function prepareGetHeaders(getExportRequestHeaders: GetHeaders): () => Record<string, string> | undefined;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * https://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.prepareGetHeaders = void 0;
19
- function prepareGetHeaders(getExportRequestHeaders) {
20
- return function () {
21
- return getExportRequestHeaders();
22
- };
23
- }
24
- exports.prepareGetHeaders = prepareGetHeaders;
@@ -1,37 +0,0 @@
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
- }
@@ -1,118 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * https://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ZipkinExporter = void 0;
19
- /**
20
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/zipkin.ts
21
- *
22
- * Modified to prioritise input serviceName over SemanticResourceAttributes.SERVICE_NAME
23
- */
24
- const api_1 = require("@opentelemetry/api");
25
- const core_1 = require("@opentelemetry/core");
26
- const index_1 = require("./platform/index");
27
- const transform_1 = require("./transform");
28
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
29
- const utils_1 = require("./utils");
30
- /**
31
- * Zipkin Exporter
32
- */
33
- class ZipkinExporter {
34
- constructor(config = {}) {
35
- this.DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
36
- this._sendingPromises = [];
37
- this._urlStr = config.url || (0, core_1.getEnv)().OTEL_EXPORTER_ZIPKIN_ENDPOINT;
38
- this._send = (0, index_1.prepareSend)(this._urlStr, config.headers);
39
- this._serviceName = config.serviceName;
40
- this._statusCodeTagName = config.statusCodeTagName || transform_1.defaultStatusCodeTagName;
41
- this._statusDescriptionTagName =
42
- config.statusDescriptionTagName || transform_1.defaultStatusErrorTagName;
43
- this._isShutdown = false;
44
- if (typeof config.getExportRequestHeaders === 'function') {
45
- this._getHeaders = (0, utils_1.prepareGetHeaders)(config.getExportRequestHeaders);
46
- }
47
- else {
48
- // noop
49
- this._beforeSend = function () { };
50
- }
51
- }
52
- /**
53
- * Export spans.
54
- */
55
- export(spans, resultCallback) {
56
- const serviceName = String(this._serviceName ||
57
- spans[0].resource.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
58
- this.DEFAULT_SERVICE_NAME);
59
- api_1.diag.debug('Zipkin exporter export');
60
- if (this._isShutdown) {
61
- setTimeout(() => resultCallback({
62
- code: core_1.ExportResultCode.FAILED,
63
- error: new Error('Exporter has been shutdown'),
64
- }));
65
- return;
66
- }
67
- const promise = new Promise(resolve => {
68
- this._sendSpans(spans, serviceName, result => {
69
- resolve();
70
- resultCallback(result);
71
- });
72
- });
73
- this._sendingPromises.push(promise);
74
- const popPromise = () => {
75
- const index = this._sendingPromises.indexOf(promise);
76
- this._sendingPromises.splice(index, 1);
77
- };
78
- promise.then(popPromise, popPromise);
79
- }
80
- /**
81
- * Shutdown exporter. Noop operation in this exporter.
82
- */
83
- shutdown() {
84
- api_1.diag.debug('Zipkin exporter shutdown');
85
- this._isShutdown = true;
86
- return new Promise((resolve, reject) => {
87
- Promise.all(this._sendingPromises).then(() => {
88
- resolve();
89
- }, reject);
90
- });
91
- }
92
- /**
93
- * if user defines getExportRequestHeaders in config then this will be called
94
- * everytime before send, otherwise it will be replaced with noop in
95
- * constructor
96
- * @default noop
97
- */
98
- _beforeSend() {
99
- if (this._getHeaders) {
100
- this._send = (0, index_1.prepareSend)(this._urlStr, this._getHeaders());
101
- }
102
- }
103
- /**
104
- * Transform spans and sends to Zipkin service.
105
- */
106
- _sendSpans(spans, serviceName, done) {
107
- const zipkinSpans = spans.map(span => (0, transform_1.toZipkinSpan)(span, String(serviceName ||
108
- span.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
109
- span.resource.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]), this._statusCodeTagName, this._statusDescriptionTagName));
110
- this._beforeSend();
111
- return this._send(zipkinSpans, (result) => {
112
- if (done) {
113
- return done(result);
114
- }
115
- });
116
- }
117
- }
118
- exports.ZipkinExporter = ZipkinExporter;
@@ -1,21 +0,0 @@
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
- /**
18
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/platform/index.ts
19
- */
20
-
21
- export * from './node';
@@ -1,21 +0,0 @@
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
- /**
18
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/platform/node/index.ts
19
- */
20
-
21
- export * from './util';
@@ -1,98 +0,0 @@
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
- /**
18
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts
19
- */
20
-
21
- import { diag } from '@opentelemetry/api';
22
- import { ExportResult, ExportResultCode } from '@opentelemetry/core';
23
- import * as http from 'http';
24
- import * as https from 'https';
25
- import * as url from 'url';
26
- import * as zipkinTypes from '../../types';
27
-
28
- /**
29
- * Prepares send function that will send spans to the remote Zipkin service.
30
- * @param urlStr - url to send spans
31
- * @param headers - headers
32
- * send
33
- */
34
- export function prepareSend(urlStr: string, headers?: Record<string, string>): zipkinTypes.SendFn {
35
- const urlOpts = url.parse(urlStr);
36
-
37
- const reqOpts: http.RequestOptions = Object.assign(
38
- {
39
- method: 'POST',
40
- headers: {
41
- 'Content-Type': 'application/json',
42
- ...headers,
43
- },
44
- },
45
- urlOpts
46
- );
47
-
48
- /**
49
- * Send spans to the remote Zipkin service.
50
- */
51
- return function send(
52
- zipkinSpans: zipkinTypes.Span[],
53
- done: (result: ExportResult) => void
54
- ) {
55
- if (zipkinSpans.length === 0) {
56
- diag.debug('Zipkin send with empty spans');
57
- return done({ code: ExportResultCode.SUCCESS });
58
- }
59
-
60
- const { request } = reqOpts.protocol === 'http:' ? http : https;
61
- const req = request(reqOpts, (res: http.IncomingMessage) => {
62
- let rawData = '';
63
- res.on('data', chunk => {
64
- rawData += chunk;
65
- });
66
- res.on('end', () => {
67
- const statusCode = res.statusCode || 0;
68
- diag.debug(`Zipkin response status code: ${statusCode}, body: ${rawData}`);
69
-
70
- // Consider 2xx and 3xx as success.
71
- if (statusCode < 400) {
72
- return done({ code: ExportResultCode.SUCCESS });
73
- // Consider 4xx as failed non-retriable.
74
- } else {
75
- return done({
76
- code: ExportResultCode.FAILED,
77
- error: new Error(
78
- `Got unexpected status code from zipkin: ${statusCode}`
79
- ),
80
- });
81
- }
82
- });
83
- });
84
-
85
- req.on('error', error => {
86
- return done({
87
- code: ExportResultCode.FAILED,
88
- error,
89
- });
90
- });
91
-
92
- // Issue request to remote service
93
- const payload = JSON.stringify(zipkinSpans);
94
- diag.debug(`Zipkin request payload: ${payload}`);
95
- req.write(payload, 'utf8');
96
- req.end();
97
- };
98
- }
@@ -1,117 +0,0 @@
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
- /**
18
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/transform.ts
19
- *
20
- * Modified to handle our traceId length being either 16 or 32 characters, and to send the correct Parent Span ID
21
- */
22
-
23
- import * as api from '@opentelemetry/api';
24
- import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
25
- import { hrTimeToMicroseconds } from '@opentelemetry/core';
26
- import * as zipkinTypes from './types';
27
- import { Resource } from '@opentelemetry/resources';
28
- import {context} from "@opentelemetry/api";
29
- import {B3_PARENT_SPAN_ID_KEY, B3_TRACE_ID_LENGTH_KEY} from "../UoaB3Propagator";
30
-
31
- const ZIPKIN_SPAN_KIND_MAPPING = {
32
- [api.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,
33
- [api.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,
34
- [api.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,
35
- [api.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,
36
- // When absent, the span is local.
37
- //@ts-ignore
38
- [api.SpanKind.INTERNAL]: undefined,
39
- };
40
-
41
- export const defaultStatusCodeTagName = 'otel.status_code';
42
- export const defaultStatusErrorTagName = 'error';
43
-
44
- /**
45
- * Translate OpenTelemetry ReadableSpan to ZipkinSpan format
46
- * @param span Span to be translated
47
- */
48
- export function toZipkinSpan(
49
- span: ReadableSpan,
50
- serviceName: string,
51
- statusCodeTagName: string,
52
- statusErrorTagName: string
53
- ): zipkinTypes.Span {
54
- const traceIdLength: number = <number>context.active().getValue(B3_TRACE_ID_LENGTH_KEY);
55
- let traceId = span.spanContext().traceId.slice(span.spanContext().traceId.length - traceIdLength);
56
- const parentSpanId = <string>context.active().getValue(B3_PARENT_SPAN_ID_KEY);
57
- const zipkinSpan: zipkinTypes.Span = {
58
- traceId: traceId,
59
- parentId: parentSpanId || span.parentSpanId,
60
- name: span.name,
61
- id: span.spanContext().spanId,
62
- kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
63
- timestamp: hrTimeToMicroseconds(span.startTime),
64
- duration: hrTimeToMicroseconds(span.duration),
65
- localEndpoint: { serviceName },
66
- tags: _toZipkinTags(
67
- span.attributes,
68
- span.status,
69
- statusCodeTagName,
70
- statusErrorTagName,
71
- span.resource
72
- ),
73
- annotations: span.events.length
74
- ? _toZipkinAnnotations(span.events)
75
- : undefined,
76
- };
77
-
78
- return zipkinSpan;
79
- }
80
-
81
- /** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */
82
- export function _toZipkinTags(
83
- attributes: api.SpanAttributes,
84
- status: api.SpanStatus,
85
- statusCodeTagName: string,
86
- statusErrorTagName: string,
87
- resource: Resource
88
- ): zipkinTypes.Tags {
89
- const tags: { [key: string]: string } = {};
90
- for (const key of Object.keys(attributes)) {
91
- tags[key] = String(attributes[key]);
92
- }
93
- if (status.code !== api.SpanStatusCode.UNSET) {
94
- tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
95
- }
96
- if (status.code === api.SpanStatusCode.ERROR && status.message) {
97
- tags[statusErrorTagName] = status.message;
98
- }
99
-
100
- Object.keys(resource.attributes).forEach(
101
- name => (tags[name] = String(resource.attributes[name]))
102
- );
103
-
104
- return tags;
105
- }
106
-
107
- /**
108
- * Converts OpenTelemetry Events to Zipkin Annotations format.
109
- */
110
- export function _toZipkinAnnotations(
111
- events: TimedEvent[]
112
- ): zipkinTypes.Annotation[] {
113
- return events.map(event => ({
114
- timestamp: hrTimeToMicroseconds(event.time),
115
- value: event.name,
116
- }));
117
- }