@uoa/lambda-tracing 1.5.0 → 2.0.0-beta.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.
@@ -0,0 +1,116 @@
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
+ const api_1 = require("@opentelemetry/api");
23
+ const core_1 = require("@opentelemetry/core");
24
+ const index_1 = require("./platform/index");
25
+ const transform_1 = require("./transform");
26
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
27
+ const utils_1 = require("./utils");
28
+ /**
29
+ * Zipkin Exporter
30
+ */
31
+ class ZipkinExporter {
32
+ constructor(config = {}) {
33
+ this.DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
34
+ this._sendingPromises = [];
35
+ this._urlStr = config.url || (0, core_1.getEnv)().OTEL_EXPORTER_ZIPKIN_ENDPOINT;
36
+ this._send = (0, index_1.prepareSend)(this._urlStr, config.headers);
37
+ this._serviceName = config.serviceName;
38
+ this._statusCodeTagName = config.statusCodeTagName || transform_1.defaultStatusCodeTagName;
39
+ this._statusDescriptionTagName =
40
+ config.statusDescriptionTagName || transform_1.defaultStatusErrorTagName;
41
+ this._isShutdown = false;
42
+ if (typeof config.getExportRequestHeaders === 'function') {
43
+ this._getHeaders = (0, utils_1.prepareGetHeaders)(config.getExportRequestHeaders);
44
+ }
45
+ else {
46
+ // noop
47
+ this._beforeSend = function () { };
48
+ }
49
+ }
50
+ /**
51
+ * Export spans.
52
+ */
53
+ export(spans, resultCallback) {
54
+ const serviceName = String(this._serviceName ||
55
+ spans[0].resource.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
56
+ this.DEFAULT_SERVICE_NAME);
57
+ api_1.diag.debug('Zipkin exporter export');
58
+ if (this._isShutdown) {
59
+ setTimeout(() => resultCallback({
60
+ code: core_1.ExportResultCode.FAILED,
61
+ error: new Error('Exporter has been shutdown'),
62
+ }));
63
+ return;
64
+ }
65
+ const promise = new Promise(resolve => {
66
+ this._sendSpans(spans, serviceName, result => {
67
+ resolve();
68
+ resultCallback(result);
69
+ });
70
+ });
71
+ this._sendingPromises.push(promise);
72
+ const popPromise = () => {
73
+ const index = this._sendingPromises.indexOf(promise);
74
+ this._sendingPromises.splice(index, 1);
75
+ };
76
+ promise.then(popPromise, popPromise);
77
+ }
78
+ /**
79
+ * Shutdown exporter. Noop operation in this exporter.
80
+ */
81
+ shutdown() {
82
+ api_1.diag.debug('Zipkin exporter shutdown');
83
+ this._isShutdown = true;
84
+ return new Promise((resolve, reject) => {
85
+ Promise.all(this._sendingPromises).then(() => {
86
+ resolve();
87
+ }, reject);
88
+ });
89
+ }
90
+ /**
91
+ * if user defines getExportRequestHeaders in config then this will be called
92
+ * everytime before send, otherwise it will be replaced with noop in
93
+ * constructor
94
+ * @default noop
95
+ */
96
+ _beforeSend() {
97
+ if (this._getHeaders) {
98
+ this._send = (0, index_1.prepareSend)(this._urlStr, this._getHeaders());
99
+ }
100
+ }
101
+ /**
102
+ * Transform spans and sends to Zipkin service.
103
+ */
104
+ _sendSpans(spans, serviceName, done) {
105
+ const zipkinSpans = spans.map(span => (0, transform_1.toZipkinSpan)(span, String(span.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
106
+ span.resource.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
107
+ serviceName), this._statusCodeTagName, this._statusDescriptionTagName));
108
+ this._beforeSend();
109
+ return this._send(zipkinSpans, (result) => {
110
+ if (done) {
111
+ return done(result);
112
+ }
113
+ });
114
+ }
115
+ }
116
+ exports.ZipkinExporter = ZipkinExporter;
package/logging.ts CHANGED
@@ -47,6 +47,11 @@ function getLogReplacementValues(callingModule: NodeModule, logInfo: any): Map<s
47
47
  info = infoHeader.toString();
48
48
  }
49
49
 
50
+ let message = '-';
51
+ if (logInfo.message != null) {
52
+ message = logInfo.message;
53
+ }
54
+
50
55
  const traceIdLength: number = <number>context.active().getValue(B3_TRACE_ID_LENGTH_KEY);
51
56
 
52
57
  let logReplacements: Map<string, string> = new Map<string, string>();
@@ -57,7 +62,7 @@ function getLogReplacementValues(callingModule: NodeModule, logInfo: any): Map<s
57
62
  logReplacements.set('%traceId', traceId.slice(traceId.length - traceIdLength));
58
63
  logReplacements.set('%spanId', spanId);
59
64
  logReplacements.set('%info', info);
60
- logReplacements.set('%message', logInfo.message.replace(/\n/g, ''));
65
+ logReplacements.set('%message', message.replace(/\n/g, ''));
61
66
 
62
67
  return logReplacements;
63
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uoa/lambda-tracing",
3
- "version": "1.5.0",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "Library for logging & distributed tracing in UoA Lambda projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,10 +29,10 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@opentelemetry/api": "^1.1.0",
32
- "@opentelemetry/core": "^1.2.0",
32
+ "@opentelemetry/core": "^1.8.0",
33
33
  "@opentelemetry/instrumentation": "^0.28.0",
34
34
  "@opentelemetry/instrumentation-aws-lambda": "^0.31.0",
35
- "@opentelemetry/sdk-trace-node": "^1.2.0",
35
+ "@opentelemetry/sdk-trace-node": "^1.8.0",
36
36
  "moment": "^2.29.3",
37
37
  "winston": "^3.7.2"
38
38
  },
package/tracing.ts CHANGED
@@ -1,13 +1,22 @@
1
- import {NodeTracerProvider} from '@opentelemetry/sdk-trace-node';
1
+ import {NodeTracerProvider, BatchSpanProcessor} from '@opentelemetry/sdk-trace-node';
2
2
  import {AwsLambdaInstrumentation} from '@opentelemetry/instrumentation-aws-lambda';
3
3
  import {registerInstrumentations} from '@opentelemetry/instrumentation';
4
4
  import {B3_INFO_KEY, UoaB3Propagator} from "./UoaB3Propagator";
5
5
  import {context} from "@opentelemetry/api";
6
+ import {AlwaysOnSampler} from "@opentelemetry/sdk-trace-base";
7
+ import {ZipkinExporter} from "./zipkin/zipkin";
8
+ import {SemanticResourceAttributes} from "@opentelemetry/semantic-conventions";
6
9
 
7
- const provider = new NodeTracerProvider();
10
+ const provider = new NodeTracerProvider({sampler: new AlwaysOnSampler()});
8
11
  let infoHeader: string | undefined;
9
12
 
10
- export function initializeTracing() {
13
+ export function initializeTracing(serviceName: string) {
14
+ const options = {
15
+ url: process.env.zipkinUrl ? process.env.zipkinUrl : 'http://zipkin-uoa-its-nonprod-external-1074907196.ap-southeast-2.elb.amazonaws.com:9411/api/v2/spans',
16
+ serviceName: serviceName
17
+ }
18
+ provider.addSpanProcessor(new BatchSpanProcessor(new ZipkinExporter(options)));
19
+
11
20
  provider.register({
12
21
  propagator: new UoaB3Propagator()
13
22
  });
@@ -17,6 +26,7 @@ export function initializeTracing() {
17
26
  new AwsLambdaInstrumentation({
18
27
  requestHook: (span, { event, context }) => {
19
28
  span.setAttribute('faas.name', context.functionName);
29
+ span.setAttribute(SemanticResourceAttributes.SERVICE_NAME, serviceName);
20
30
  infoHeader = undefined; //reset header value in case lambda execution environment maintained since last invocation
21
31
  },
22
32
  responseHook: (span, { err, res }) => {
@@ -0,0 +1,21 @@
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';
@@ -0,0 +1,21 @@
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';
@@ -0,0 +1,98 @@
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
+ }
@@ -0,0 +1,116 @@
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
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_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 zipkinSpan: zipkinTypes.Span = {
57
+ traceId: traceId,
58
+ parentId: span.parentSpanId,
59
+ name: span.name,
60
+ id: span.spanContext().spanId,
61
+ kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
62
+ timestamp: hrTimeToMicroseconds(span.startTime),
63
+ duration: hrTimeToMicroseconds(span.duration),
64
+ localEndpoint: { serviceName },
65
+ tags: _toZipkinTags(
66
+ span.attributes,
67
+ span.status,
68
+ statusCodeTagName,
69
+ statusErrorTagName,
70
+ span.resource
71
+ ),
72
+ annotations: span.events.length
73
+ ? _toZipkinAnnotations(span.events)
74
+ : undefined,
75
+ };
76
+
77
+ return zipkinSpan;
78
+ }
79
+
80
+ /** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */
81
+ export function _toZipkinTags(
82
+ attributes: api.SpanAttributes,
83
+ status: api.SpanStatus,
84
+ statusCodeTagName: string,
85
+ statusErrorTagName: string,
86
+ resource: Resource
87
+ ): zipkinTypes.Tags {
88
+ const tags: { [key: string]: string } = {};
89
+ for (const key of Object.keys(attributes)) {
90
+ tags[key] = String(attributes[key]);
91
+ }
92
+ if (status.code !== api.SpanStatusCode.UNSET) {
93
+ tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
94
+ }
95
+ if (status.code === api.SpanStatusCode.ERROR && status.message) {
96
+ tags[statusErrorTagName] = status.message;
97
+ }
98
+
99
+ Object.keys(resource.attributes).forEach(
100
+ name => (tags[name] = String(resource.attributes[name]))
101
+ );
102
+
103
+ return tags;
104
+ }
105
+
106
+ /**
107
+ * Converts OpenTelemetry Events to Zipkin Annotations format.
108
+ */
109
+ export function _toZipkinAnnotations(
110
+ events: TimedEvent[]
111
+ ): zipkinTypes.Annotation[] {
112
+ return events.map(event => ({
113
+ timestamp: hrTimeToMicroseconds(event.time),
114
+ value: event.name,
115
+ }));
116
+ }
@@ -0,0 +1,195 @@
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;
@@ -0,0 +1,29 @@
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
+ }