@uoa/lambda-tracing 2.0.2 → 2.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +41 -0
- package/dist/tracing.d.ts +1 -3
- package/dist/tracing.js +2 -21
- package/dist/uoaHttps.js +101 -206
- package/package.json +4 -2
- package/tracing.ts +4 -24
- package/tsconfig.json +2 -2
- package/uoaHttps.ts +65 -155
- package/dist/zipkin/platform/index.d.ts +0 -4
- package/dist/zipkin/platform/index.js +0 -35
- package/dist/zipkin/platform/node/index.d.ts +0 -4
- package/dist/zipkin/platform/node/index.js +0 -35
- package/dist/zipkin/platform/node/util.d.ts +0 -8
- package/dist/zipkin/platform/node/util.js +0 -105
- package/dist/zipkin/transform.d.ts +0 -22
- package/dist/zipkin/transform.js +0 -113
- package/dist/zipkin/types.d.ts +0 -160
- package/dist/zipkin/types.js +0 -47
- package/dist/zipkin/utils.d.ts +0 -5
- package/dist/zipkin/utils.js +0 -24
- package/dist/zipkin/zipkin.d.ts +0 -37
- package/dist/zipkin/zipkin.js +0 -118
- package/zipkin/platform/index.ts +0 -21
- package/zipkin/platform/node/index.ts +0 -21
- package/zipkin/platform/node/util.ts +0 -98
- package/zipkin/transform.ts +0 -117
- package/zipkin/types.ts +0 -195
- package/zipkin/utils.ts +0 -29
- package/zipkin/zipkin.ts +0 -157
package/zipkin/types.ts
DELETED
|
@@ -1,195 +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/types.ts
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { ExportResult } from '@opentelemetry/core';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Exporter config
|
|
25
|
-
*/
|
|
26
|
-
export interface ExporterConfig {
|
|
27
|
-
headers?: Record<string, string>;
|
|
28
|
-
serviceName?: string;
|
|
29
|
-
url?: string;
|
|
30
|
-
// Optional mapping overrides for OpenTelemetry status code and description.
|
|
31
|
-
statusCodeTagName?: string;
|
|
32
|
-
statusDescriptionTagName?: string;
|
|
33
|
-
getExportRequestHeaders?: () => Record<string, string> | undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Zipkin Span
|
|
38
|
-
* @see https://github.com/openzipkin/zipkin-api/blob/master/zipkin2-api.yaml
|
|
39
|
-
*/
|
|
40
|
-
export interface Span {
|
|
41
|
-
/**
|
|
42
|
-
* Trace identifier, set on all spans within it.
|
|
43
|
-
*/
|
|
44
|
-
traceId: string;
|
|
45
|
-
/**
|
|
46
|
-
* The logical operation this span represents in lowercase (e.g. rpc method).
|
|
47
|
-
* Leave absent if unknown.
|
|
48
|
-
*/
|
|
49
|
-
name: string;
|
|
50
|
-
/**
|
|
51
|
-
* The parent span ID or absent if this the root span in a trace.
|
|
52
|
-
*/
|
|
53
|
-
parentId?: string;
|
|
54
|
-
/**
|
|
55
|
-
* Unique 64bit identifier for this operation within the trace.
|
|
56
|
-
*/
|
|
57
|
-
id: string;
|
|
58
|
-
/**
|
|
59
|
-
* When present, kind clarifies timestamp, duration and remoteEndpoint.
|
|
60
|
-
* When absent, the span is local or incomplete.
|
|
61
|
-
*/
|
|
62
|
-
kind?: SpanKind;
|
|
63
|
-
/**
|
|
64
|
-
* Epoch microseconds of the start of this span, possibly absent if
|
|
65
|
-
* incomplete.
|
|
66
|
-
*/
|
|
67
|
-
timestamp: number;
|
|
68
|
-
/**
|
|
69
|
-
* Duration in microseconds of the critical path, if known.
|
|
70
|
-
*/
|
|
71
|
-
duration: number;
|
|
72
|
-
/**
|
|
73
|
-
* True is a request to store this span even if it overrides sampling policy.
|
|
74
|
-
* This is true when the `X-B3-Flags` header has a value of 1.
|
|
75
|
-
*/
|
|
76
|
-
debug?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* True if we are contributing to a span started by another tracer (ex on a
|
|
79
|
-
* different host).
|
|
80
|
-
*/
|
|
81
|
-
shared?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* The host that recorded this span, primarily for query by service name.
|
|
84
|
-
*/
|
|
85
|
-
localEndpoint: Endpoint;
|
|
86
|
-
/**
|
|
87
|
-
* Associates events that explain latency with the time they happened.
|
|
88
|
-
*/
|
|
89
|
-
annotations?: Annotation[];
|
|
90
|
-
/**
|
|
91
|
-
* Tags give your span context for search, viewing and analysis.
|
|
92
|
-
*/
|
|
93
|
-
tags: Tags;
|
|
94
|
-
/**
|
|
95
|
-
* TODO: `remoteEndpoint`, do we need to support it?
|
|
96
|
-
* When an RPC (or messaging) span, indicates the other side of the
|
|
97
|
-
* connection.
|
|
98
|
-
*/
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Associates an event that explains latency with a timestamp.
|
|
103
|
-
* Unlike log statements, annotations are often codes. Ex. "ws" for WireSend
|
|
104
|
-
* Zipkin v1 core annotations such as "cs" and "sr" have been replaced with
|
|
105
|
-
* Span.Kind, which interprets timestamp and duration.
|
|
106
|
-
*/
|
|
107
|
-
export interface Annotation {
|
|
108
|
-
/**
|
|
109
|
-
* Epoch microseconds of this event.
|
|
110
|
-
* For example, 1502787600000000 corresponds to 2017-08-15 09:00 UTC
|
|
111
|
-
*/
|
|
112
|
-
timestamp: number;
|
|
113
|
-
/**
|
|
114
|
-
* Usually a short tag indicating an event, like "error"
|
|
115
|
-
* While possible to add larger data, such as garbage collection details, low
|
|
116
|
-
* cardinality event names both keep the size of spans down and also are easy
|
|
117
|
-
* to search against.
|
|
118
|
-
*/
|
|
119
|
-
value: string;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* The network context of a node in the service graph.
|
|
124
|
-
*/
|
|
125
|
-
export interface Endpoint {
|
|
126
|
-
/**
|
|
127
|
-
* Lower-case label of this node in the service graph, such as "favstar".
|
|
128
|
-
* Leave absent if unknown.
|
|
129
|
-
* This is a primary label for trace lookup and aggregation, so it should be
|
|
130
|
-
* intuitive and consistent. Many use a name from service discovery.
|
|
131
|
-
*/
|
|
132
|
-
serviceName?: string;
|
|
133
|
-
/**
|
|
134
|
-
* The text representation of the primary IPv4 address associated with this
|
|
135
|
-
* connection. Ex. 192.168.99.100 Absent if unknown.
|
|
136
|
-
*/
|
|
137
|
-
ipv4?: string;
|
|
138
|
-
/**
|
|
139
|
-
* The text representation of the primary IPv6 address associated with a
|
|
140
|
-
* connection. Ex. 2001:db8::c001 Absent if unknown.
|
|
141
|
-
* Prefer using the ipv4 field for mapped addresses.
|
|
142
|
-
*/
|
|
143
|
-
port?: number;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Adds context to a span, for search, viewing and analysis.
|
|
148
|
-
* For example, a key "your_app.version" would let you lookup traces by version.
|
|
149
|
-
* A tag "sql.query" isn't searchable, but it can help in debugging when viewing
|
|
150
|
-
* a trace.
|
|
151
|
-
*/
|
|
152
|
-
export interface Tags {
|
|
153
|
-
[tagKey: string]: unknown;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* When present, kind clarifies timestamp, duration and remoteEndpoint. When
|
|
158
|
-
* absent, the span is local or incomplete. Unlike client and server, there
|
|
159
|
-
* is no direct critical path latency relationship between producer and
|
|
160
|
-
* consumer spans.
|
|
161
|
-
* `CLIENT`
|
|
162
|
-
* timestamp is the moment a request was sent to the server.
|
|
163
|
-
* duration is the delay until a response or an error was received.
|
|
164
|
-
* remoteEndpoint is the server.
|
|
165
|
-
* `SERVER`
|
|
166
|
-
* timestamp is the moment a client request was received.
|
|
167
|
-
* duration is the delay until a response was sent or an error.
|
|
168
|
-
* remoteEndpoint is the client.
|
|
169
|
-
* `PRODUCER`
|
|
170
|
-
* timestamp is the moment a message was sent to a destination.
|
|
171
|
-
* duration is the delay sending the message, such as batching.
|
|
172
|
-
* remoteEndpoint is the broker.
|
|
173
|
-
* `CONSUMER`
|
|
174
|
-
* timestamp is the moment a message was received from an origin.
|
|
175
|
-
* duration is the delay consuming the message, such as from backlog.
|
|
176
|
-
* remoteEndpoint - Represents the broker. Leave serviceName absent if unknown.
|
|
177
|
-
*/
|
|
178
|
-
export enum SpanKind {
|
|
179
|
-
CLIENT = 'CLIENT',
|
|
180
|
-
SERVER = 'SERVER',
|
|
181
|
-
CONSUMER = 'CONSUMER',
|
|
182
|
-
PRODUCER = 'PRODUCER',
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* interface for function that will send zipkin spans
|
|
187
|
-
*/
|
|
188
|
-
export type SendFunction = (
|
|
189
|
-
zipkinSpans: Span[],
|
|
190
|
-
done: (result: ExportResult) => void
|
|
191
|
-
) => void;
|
|
192
|
-
|
|
193
|
-
export type GetHeaders = () => Record<string, string> | undefined;
|
|
194
|
-
|
|
195
|
-
export type SendFn = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
|
package/zipkin/utils.ts
DELETED
|
@@ -1,29 +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/utils.ts
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { GetHeaders } from './types';
|
|
22
|
-
|
|
23
|
-
export function prepareGetHeaders(
|
|
24
|
-
getExportRequestHeaders: GetHeaders
|
|
25
|
-
): () => Record<string, string> | undefined {
|
|
26
|
-
return function () {
|
|
27
|
-
return getExportRequestHeaders();
|
|
28
|
-
};
|
|
29
|
-
}
|
package/zipkin/zipkin.ts
DELETED
|
@@ -1,157 +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/zipkin.ts
|
|
19
|
-
*
|
|
20
|
-
* Modified to prioritise input serviceName over SemanticResourceAttributes.SERVICE_NAME
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { diag } from '@opentelemetry/api';
|
|
24
|
-
import { ExportResult, ExportResultCode, getEnv } from '@opentelemetry/core';
|
|
25
|
-
import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
26
|
-
import { prepareSend } from './platform/index';
|
|
27
|
-
import * as zipkinTypes from './types';
|
|
28
|
-
import {
|
|
29
|
-
toZipkinSpan,
|
|
30
|
-
defaultStatusCodeTagName,
|
|
31
|
-
defaultStatusErrorTagName,
|
|
32
|
-
} from './transform';
|
|
33
|
-
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
|
|
34
|
-
import { prepareGetHeaders } from './utils';
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Zipkin Exporter
|
|
38
|
-
*/
|
|
39
|
-
export class ZipkinExporter implements SpanExporter {
|
|
40
|
-
private readonly DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
|
|
41
|
-
private readonly _statusCodeTagName: string;
|
|
42
|
-
private readonly _statusDescriptionTagName: string;
|
|
43
|
-
private _urlStr: string;
|
|
44
|
-
private _send: zipkinTypes.SendFunction;
|
|
45
|
-
private _getHeaders: zipkinTypes.GetHeaders | undefined;
|
|
46
|
-
private _serviceName?: string;
|
|
47
|
-
private _isShutdown: boolean;
|
|
48
|
-
private _sendingPromises: Promise<unknown>[] = [];
|
|
49
|
-
|
|
50
|
-
constructor(config: zipkinTypes.ExporterConfig = {}) {
|
|
51
|
-
this._urlStr = config.url || getEnv().OTEL_EXPORTER_ZIPKIN_ENDPOINT;
|
|
52
|
-
this._send = prepareSend(this._urlStr, config.headers);
|
|
53
|
-
this._serviceName = config.serviceName;
|
|
54
|
-
this._statusCodeTagName = config.statusCodeTagName || defaultStatusCodeTagName;
|
|
55
|
-
this._statusDescriptionTagName =
|
|
56
|
-
config.statusDescriptionTagName || defaultStatusErrorTagName;
|
|
57
|
-
this._isShutdown = false;
|
|
58
|
-
if (typeof config.getExportRequestHeaders === 'function') {
|
|
59
|
-
this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders);
|
|
60
|
-
} else {
|
|
61
|
-
// noop
|
|
62
|
-
this._beforeSend = function () {};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Export spans.
|
|
68
|
-
*/
|
|
69
|
-
export(
|
|
70
|
-
spans: ReadableSpan[],
|
|
71
|
-
resultCallback: (result: ExportResult) => void
|
|
72
|
-
): void {
|
|
73
|
-
const serviceName = String(
|
|
74
|
-
this._serviceName ||
|
|
75
|
-
spans[0].resource.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
|
|
76
|
-
this.DEFAULT_SERVICE_NAME
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
diag.debug('Zipkin exporter export');
|
|
80
|
-
if (this._isShutdown) {
|
|
81
|
-
setTimeout(() =>
|
|
82
|
-
resultCallback({
|
|
83
|
-
code: ExportResultCode.FAILED,
|
|
84
|
-
error: new Error('Exporter has been shutdown'),
|
|
85
|
-
})
|
|
86
|
-
);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const promise = new Promise<void>(resolve => {
|
|
90
|
-
this._sendSpans(spans, serviceName, result => {
|
|
91
|
-
resolve();
|
|
92
|
-
resultCallback(result);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this._sendingPromises.push(promise);
|
|
98
|
-
const popPromise = () => {
|
|
99
|
-
const index = this._sendingPromises.indexOf(promise);
|
|
100
|
-
this._sendingPromises.splice(index, 1);
|
|
101
|
-
};
|
|
102
|
-
promise.then(popPromise, popPromise);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Shutdown exporter. Noop operation in this exporter.
|
|
107
|
-
*/
|
|
108
|
-
shutdown(): Promise<void> {
|
|
109
|
-
diag.debug('Zipkin exporter shutdown');
|
|
110
|
-
this._isShutdown = true;
|
|
111
|
-
return new Promise((resolve, reject) => {
|
|
112
|
-
Promise.all(this._sendingPromises).then(() => {
|
|
113
|
-
resolve();
|
|
114
|
-
}, reject);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* if user defines getExportRequestHeaders in config then this will be called
|
|
120
|
-
* everytime before send, otherwise it will be replaced with noop in
|
|
121
|
-
* constructor
|
|
122
|
-
* @default noop
|
|
123
|
-
*/
|
|
124
|
-
private _beforeSend() {
|
|
125
|
-
if (this._getHeaders) {
|
|
126
|
-
this._send = prepareSend(this._urlStr, this._getHeaders());
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Transform spans and sends to Zipkin service.
|
|
132
|
-
*/
|
|
133
|
-
private _sendSpans(
|
|
134
|
-
spans: ReadableSpan[],
|
|
135
|
-
serviceName: string,
|
|
136
|
-
done?: (result: ExportResult) => void
|
|
137
|
-
) {
|
|
138
|
-
const zipkinSpans = spans.map(span =>
|
|
139
|
-
toZipkinSpan(
|
|
140
|
-
span,
|
|
141
|
-
String(
|
|
142
|
-
serviceName ||
|
|
143
|
-
span.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
|
|
144
|
-
span.resource.attributes[SemanticResourceAttributes.SERVICE_NAME]
|
|
145
|
-
),
|
|
146
|
-
this._statusCodeTagName,
|
|
147
|
-
this._statusDescriptionTagName
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
this._beforeSend();
|
|
151
|
-
return this._send(zipkinSpans, (result: ExportResult) => {
|
|
152
|
-
if (done) {
|
|
153
|
-
return done(result);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|