@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.
- package/ReleaseSteps.md +11 -0
- package/dist/logging.js +5 -1
- package/dist/tracing.d.ts +1 -1
- package/dist/tracing.js +9 -2
- package/dist/zipkin/platform/index.d.ts +4 -0
- package/dist/zipkin/platform/index.js +35 -0
- package/dist/zipkin/platform/node/index.d.ts +4 -0
- package/dist/zipkin/platform/node/index.js +35 -0
- package/dist/zipkin/platform/node/util.d.ts +8 -0
- package/dist/zipkin/platform/node/util.js +105 -0
- package/dist/zipkin/transform.d.ts +22 -0
- package/dist/zipkin/transform.js +112 -0
- package/dist/zipkin/types.d.ts +160 -0
- package/dist/zipkin/types.js +47 -0
- package/dist/zipkin/utils.d.ts +5 -0
- package/dist/zipkin/utils.js +24 -0
- package/dist/zipkin/zipkin.d.ts +37 -0
- package/dist/zipkin/zipkin.js +116 -0
- package/logging.ts +6 -1
- package/package.json +3 -3
- package/tracing.ts +13 -3
- package/zipkin/platform/index.ts +21 -0
- package/zipkin/platform/node/index.ts +21 -0
- package/zipkin/platform/node/util.ts +98 -0
- package/zipkin/transform.ts +116 -0
- package/zipkin/types.ts +195 -0
- package/zipkin/utils.ts +29 -0
- package/zipkin/zipkin.ts +155 -0
package/ReleaseSteps.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Steps to release package to npm
|
|
2
|
+
1. `npm login`
|
|
3
|
+
2. `npm version <new version>`
|
|
4
|
+
3. Push to git to sync new tags
|
|
5
|
+
4. `npm publish --access=public --otp=<2FA code>`
|
|
6
|
+
|
|
7
|
+
# Testing locally before release
|
|
8
|
+
1. `npm pack`
|
|
9
|
+
2. In your desired test project package.json, add the following as a dependency:
|
|
10
|
+
`"@uoa/lambda-tracing": "file:<path to this project>\\uoa-lambda-tracing-<version>.tgz"`
|
|
11
|
+
3. Run `npm install` in the test project to use the local dependency
|
package/dist/logging.js
CHANGED
|
@@ -41,6 +41,10 @@ function getLogReplacementValues(callingModule, logInfo) {
|
|
|
41
41
|
else if (infoHeader) {
|
|
42
42
|
info = infoHeader.toString();
|
|
43
43
|
}
|
|
44
|
+
let message = '-';
|
|
45
|
+
if (logInfo.message != null) {
|
|
46
|
+
message = logInfo.message;
|
|
47
|
+
}
|
|
44
48
|
const traceIdLength = context.active().getValue(UoaB3Propagator_1.B3_TRACE_ID_LENGTH_KEY);
|
|
45
49
|
let logReplacements = new Map();
|
|
46
50
|
logReplacements.set('%date', moment().toISOString());
|
|
@@ -50,7 +54,7 @@ function getLogReplacementValues(callingModule, logInfo) {
|
|
|
50
54
|
logReplacements.set('%traceId', traceId.slice(traceId.length - traceIdLength));
|
|
51
55
|
logReplacements.set('%spanId', spanId);
|
|
52
56
|
logReplacements.set('%info', info);
|
|
53
|
-
logReplacements.set('%message',
|
|
57
|
+
logReplacements.set('%message', message.replace(/\n/g, ''));
|
|
54
58
|
return logReplacements;
|
|
55
59
|
}
|
|
56
60
|
module.exports = function (callingModule) {
|
package/dist/tracing.d.ts
CHANGED
package/dist/tracing.js
CHANGED
|
@@ -6,9 +6,16 @@ const instrumentation_aws_lambda_1 = require("@opentelemetry/instrumentation-aws
|
|
|
6
6
|
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
7
7
|
const UoaB3Propagator_1 = require("./UoaB3Propagator");
|
|
8
8
|
const api_1 = require("@opentelemetry/api");
|
|
9
|
-
const
|
|
9
|
+
const core_1 = require("@opentelemetry/core");
|
|
10
|
+
const zipkin_1 = require("./zipkin/zipkin");
|
|
11
|
+
const provider = new sdk_trace_node_1.NodeTracerProvider({ sampler: new core_1.AlwaysOnSampler() });
|
|
10
12
|
let infoHeader;
|
|
11
|
-
function initializeTracing() {
|
|
13
|
+
function initializeTracing(serviceName) {
|
|
14
|
+
const options = {
|
|
15
|
+
url: '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 sdk_trace_node_1.BatchSpanProcessor(new zipkin_1.ZipkinExporter(options)));
|
|
12
19
|
provider.register({
|
|
13
20
|
propagator: new UoaB3Propagator_1.UoaB3Propagator()
|
|
14
21
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
29
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
/**
|
|
33
|
+
* Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/platform/index.ts
|
|
34
|
+
*/
|
|
35
|
+
__exportStar(require("./node"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
29
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
/**
|
|
33
|
+
* Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/platform/node/index.ts
|
|
34
|
+
*/
|
|
35
|
+
__exportStar(require("./util"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.prepareSend = void 0;
|
|
42
|
+
/**
|
|
43
|
+
* Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts
|
|
44
|
+
*/
|
|
45
|
+
const api_1 = require("@opentelemetry/api");
|
|
46
|
+
const core_1 = require("@opentelemetry/core");
|
|
47
|
+
const http = __importStar(require("http"));
|
|
48
|
+
const https = __importStar(require("https"));
|
|
49
|
+
const url = __importStar(require("url"));
|
|
50
|
+
/**
|
|
51
|
+
* Prepares send function that will send spans to the remote Zipkin service.
|
|
52
|
+
* @param urlStr - url to send spans
|
|
53
|
+
* @param headers - headers
|
|
54
|
+
* send
|
|
55
|
+
*/
|
|
56
|
+
function prepareSend(urlStr, headers) {
|
|
57
|
+
const urlOpts = url.parse(urlStr);
|
|
58
|
+
const reqOpts = Object.assign({
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, headers),
|
|
61
|
+
}, urlOpts);
|
|
62
|
+
/**
|
|
63
|
+
* Send spans to the remote Zipkin service.
|
|
64
|
+
*/
|
|
65
|
+
return function send(zipkinSpans, done) {
|
|
66
|
+
if (zipkinSpans.length === 0) {
|
|
67
|
+
api_1.diag.debug('Zipkin send with empty spans');
|
|
68
|
+
return done({ code: core_1.ExportResultCode.SUCCESS });
|
|
69
|
+
}
|
|
70
|
+
const { request } = reqOpts.protocol === 'http:' ? http : https;
|
|
71
|
+
const req = request(reqOpts, (res) => {
|
|
72
|
+
let rawData = '';
|
|
73
|
+
res.on('data', chunk => {
|
|
74
|
+
rawData += chunk;
|
|
75
|
+
});
|
|
76
|
+
res.on('end', () => {
|
|
77
|
+
const statusCode = res.statusCode || 0;
|
|
78
|
+
api_1.diag.debug(`Zipkin response status code: ${statusCode}, body: ${rawData}`);
|
|
79
|
+
// Consider 2xx and 3xx as success.
|
|
80
|
+
if (statusCode < 400) {
|
|
81
|
+
return done({ code: core_1.ExportResultCode.SUCCESS });
|
|
82
|
+
// Consider 4xx as failed non-retriable.
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return done({
|
|
86
|
+
code: core_1.ExportResultCode.FAILED,
|
|
87
|
+
error: new Error(`Got unexpected status code from zipkin: ${statusCode}`),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
req.on('error', error => {
|
|
93
|
+
return done({
|
|
94
|
+
code: core_1.ExportResultCode.FAILED,
|
|
95
|
+
error,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
// Issue request to remote service
|
|
99
|
+
const payload = JSON.stringify(zipkinSpans);
|
|
100
|
+
api_1.diag.debug(`Zipkin request payload: ${payload}`);
|
|
101
|
+
req.write(payload, 'utf8');
|
|
102
|
+
req.end();
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
exports.prepareSend = prepareSend;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/transform.ts
|
|
3
|
+
*
|
|
4
|
+
* Modified to handle our traceId length being either 16 or 32 characters
|
|
5
|
+
*/
|
|
6
|
+
import * as api from '@opentelemetry/api';
|
|
7
|
+
import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
|
|
8
|
+
import * as zipkinTypes from './types';
|
|
9
|
+
import { Resource } from '@opentelemetry/resources';
|
|
10
|
+
export declare const defaultStatusCodeTagName = "otel.status_code";
|
|
11
|
+
export declare const defaultStatusErrorTagName = "error";
|
|
12
|
+
/**
|
|
13
|
+
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
|
|
14
|
+
* @param span Span to be translated
|
|
15
|
+
*/
|
|
16
|
+
export declare function toZipkinSpan(span: ReadableSpan, serviceName: string, statusCodeTagName: string, statusErrorTagName: string): zipkinTypes.Span;
|
|
17
|
+
/** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */
|
|
18
|
+
export declare function _toZipkinTags(attributes: api.SpanAttributes, status: api.SpanStatus, statusCodeTagName: string, statusErrorTagName: string, resource: Resource): zipkinTypes.Tags;
|
|
19
|
+
/**
|
|
20
|
+
* Converts OpenTelemetry Events to Zipkin Annotations format.
|
|
21
|
+
*/
|
|
22
|
+
export declare function _toZipkinAnnotations(events: TimedEvent[]): zipkinTypes.Annotation[];
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports._toZipkinAnnotations = exports._toZipkinTags = exports.toZipkinSpan = exports.defaultStatusErrorTagName = exports.defaultStatusCodeTagName = void 0;
|
|
42
|
+
/**
|
|
43
|
+
* Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/transform.ts
|
|
44
|
+
*
|
|
45
|
+
* Modified to handle our traceId length being either 16 or 32 characters
|
|
46
|
+
*/
|
|
47
|
+
const api = __importStar(require("@opentelemetry/api"));
|
|
48
|
+
const core_1 = require("@opentelemetry/core");
|
|
49
|
+
const zipkinTypes = __importStar(require("./types"));
|
|
50
|
+
const api_1 = require("@opentelemetry/api");
|
|
51
|
+
const UoaB3Propagator_1 = require("../UoaB3Propagator");
|
|
52
|
+
const ZIPKIN_SPAN_KIND_MAPPING = {
|
|
53
|
+
[api.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,
|
|
54
|
+
[api.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,
|
|
55
|
+
[api.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,
|
|
56
|
+
[api.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,
|
|
57
|
+
// When absent, the span is local.
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
[api.SpanKind.INTERNAL]: undefined,
|
|
60
|
+
};
|
|
61
|
+
exports.defaultStatusCodeTagName = 'otel.status_code';
|
|
62
|
+
exports.defaultStatusErrorTagName = 'error';
|
|
63
|
+
/**
|
|
64
|
+
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
|
|
65
|
+
* @param span Span to be translated
|
|
66
|
+
*/
|
|
67
|
+
function toZipkinSpan(span, serviceName, statusCodeTagName, statusErrorTagName) {
|
|
68
|
+
const traceIdLength = api_1.context.active().getValue(UoaB3Propagator_1.B3_TRACE_ID_LENGTH_KEY);
|
|
69
|
+
let traceId = span.spanContext().traceId.slice(span.spanContext().traceId.length - traceIdLength);
|
|
70
|
+
const zipkinSpan = {
|
|
71
|
+
traceId: traceId,
|
|
72
|
+
parentId: span.parentSpanId,
|
|
73
|
+
name: span.name,
|
|
74
|
+
id: span.spanContext().spanId,
|
|
75
|
+
kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
|
|
76
|
+
timestamp: (0, core_1.hrTimeToMicroseconds)(span.startTime),
|
|
77
|
+
duration: (0, core_1.hrTimeToMicroseconds)(span.duration),
|
|
78
|
+
localEndpoint: { serviceName },
|
|
79
|
+
tags: _toZipkinTags(span.attributes, span.status, statusCodeTagName, statusErrorTagName, span.resource),
|
|
80
|
+
annotations: span.events.length
|
|
81
|
+
? _toZipkinAnnotations(span.events)
|
|
82
|
+
: undefined,
|
|
83
|
+
};
|
|
84
|
+
return zipkinSpan;
|
|
85
|
+
}
|
|
86
|
+
exports.toZipkinSpan = toZipkinSpan;
|
|
87
|
+
/** Converts OpenTelemetry SpanAttributes and SpanStatus to Zipkin Tags format. */
|
|
88
|
+
function _toZipkinTags(attributes, status, statusCodeTagName, statusErrorTagName, resource) {
|
|
89
|
+
const tags = {};
|
|
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
|
+
Object.keys(resource.attributes).forEach(name => (tags[name] = String(resource.attributes[name])));
|
|
100
|
+
return tags;
|
|
101
|
+
}
|
|
102
|
+
exports._toZipkinTags = _toZipkinTags;
|
|
103
|
+
/**
|
|
104
|
+
* Converts OpenTelemetry Events to Zipkin Annotations format.
|
|
105
|
+
*/
|
|
106
|
+
function _toZipkinAnnotations(events) {
|
|
107
|
+
return events.map(event => ({
|
|
108
|
+
timestamp: (0, core_1.hrTimeToMicroseconds)(event.time),
|
|
109
|
+
value: event.name,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
exports._toZipkinAnnotations = _toZipkinAnnotations;
|
|
@@ -0,0 +1,160 @@
|
|
|
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;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 = {}));
|
|
@@ -0,0 +1,5 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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;
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
}
|