@uoa/lambda-tracing 2.0.0-beta.4 → 2.0.0-beta.5
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/dist/UoaB3Propagator.d.ts +20 -0
- package/dist/UoaB3Propagator.js +142 -0
- package/dist/logging.d.ts +1 -0
- package/dist/logging.js +70 -0
- package/dist/tracing.d.ts +3 -0
- package/dist/tracing.js +53 -0
- package/dist/uoaHttps.d.ts +1 -0
- package/dist/uoaHttps.js +222 -0
- 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 +118 -0
- package/package.json +2 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class extended from OpenTelemetry B3MultiPropagator so that we can propagate & log the X-B3-Info header
|
|
3
|
+
*
|
|
4
|
+
* See {@link https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts}
|
|
5
|
+
*/
|
|
6
|
+
import { Context, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opentelemetry/api';
|
|
7
|
+
export declare const X_B3_TRACE_ID = "x-b3-traceid";
|
|
8
|
+
export declare const X_B3_SPAN_ID = "x-b3-spanid";
|
|
9
|
+
export declare const X_B3_SAMPLED = "x-b3-sampled";
|
|
10
|
+
export declare const X_B3_PARENT_SPAN_ID = "x-b3-parentspanid";
|
|
11
|
+
export declare const X_B3_FLAGS = "x-b3-flags";
|
|
12
|
+
export declare const X_B3_INFO = "x-b3-info";
|
|
13
|
+
export declare const B3_DEBUG_FLAG_KEY: symbol;
|
|
14
|
+
export declare const B3_INFO_KEY: symbol;
|
|
15
|
+
export declare const B3_TRACE_ID_LENGTH_KEY: symbol;
|
|
16
|
+
export declare class UoaB3Propagator implements TextMapPropagator {
|
|
17
|
+
inject(context: Context, carrier: any, setter: TextMapSetter<any>): void;
|
|
18
|
+
extract(context: Context, carrier: any, getter: TextMapGetter<any>): Context;
|
|
19
|
+
fields(): string[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UoaB3Propagator = exports.B3_TRACE_ID_LENGTH_KEY = exports.B3_INFO_KEY = exports.B3_DEBUG_FLAG_KEY = exports.X_B3_INFO = exports.X_B3_FLAGS = exports.X_B3_PARENT_SPAN_ID = exports.X_B3_SAMPLED = exports.X_B3_SPAN_ID = exports.X_B3_TRACE_ID = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Class extended from OpenTelemetry B3MultiPropagator so that we can propagate & log the X-B3-Info header
|
|
6
|
+
*
|
|
7
|
+
* See {@link https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts}
|
|
8
|
+
*/
|
|
9
|
+
const api_1 = require("@opentelemetry/api");
|
|
10
|
+
const core_1 = require("@opentelemetry/core");
|
|
11
|
+
const tracing_1 = require("./tracing");
|
|
12
|
+
const crypto = require('crypto');
|
|
13
|
+
exports.X_B3_TRACE_ID = 'x-b3-traceid';
|
|
14
|
+
exports.X_B3_SPAN_ID = 'x-b3-spanid';
|
|
15
|
+
exports.X_B3_SAMPLED = 'x-b3-sampled';
|
|
16
|
+
exports.X_B3_PARENT_SPAN_ID = 'x-b3-parentspanid';
|
|
17
|
+
exports.X_B3_FLAGS = 'x-b3-flags';
|
|
18
|
+
exports.X_B3_INFO = 'x-b3-info';
|
|
19
|
+
exports.B3_DEBUG_FLAG_KEY = (0, api_1.createContextKey)('B3 Debug Flag');
|
|
20
|
+
exports.B3_INFO_KEY = (0, api_1.createContextKey)('B3 Info Header');
|
|
21
|
+
exports.B3_TRACE_ID_LENGTH_KEY = (0, api_1.createContextKey)('B3 TraceId Header Length');
|
|
22
|
+
const VALID_SAMPLED_VALUES = new Set([true, 'true', 'True', '1', 1]);
|
|
23
|
+
const VALID_UNSAMPLED_VALUES = new Set([false, 'false', 'False', '0', 0]);
|
|
24
|
+
function parseHeader(header) {
|
|
25
|
+
return Array.isArray(header) ? header[0] : header;
|
|
26
|
+
}
|
|
27
|
+
function getHeaderValue(carrier, getter, key) {
|
|
28
|
+
const header = getter.get(carrier, key);
|
|
29
|
+
return parseHeader(header);
|
|
30
|
+
}
|
|
31
|
+
function getTraceIdLength(carrier, getter) {
|
|
32
|
+
const traceId = getHeaderValue(carrier, getter, exports.X_B3_TRACE_ID);
|
|
33
|
+
if (typeof traceId === 'string') {
|
|
34
|
+
if (traceId.length <= 16 || traceId.length > 32) {
|
|
35
|
+
return 16;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return 32;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return 16;
|
|
42
|
+
}
|
|
43
|
+
function getTraceId(carrier, getter) {
|
|
44
|
+
const traceId = getHeaderValue(carrier, getter, exports.X_B3_TRACE_ID);
|
|
45
|
+
if (typeof traceId === 'string') {
|
|
46
|
+
return traceId.padStart(32, '0');
|
|
47
|
+
}
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
function getSpanId(carrier, getter) {
|
|
51
|
+
const spanId = getHeaderValue(carrier, getter, exports.X_B3_SPAN_ID);
|
|
52
|
+
if (typeof spanId === 'string') {
|
|
53
|
+
return spanId;
|
|
54
|
+
}
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
function getDebug(carrier, getter) {
|
|
58
|
+
const debug = getHeaderValue(carrier, getter, exports.X_B3_FLAGS);
|
|
59
|
+
return debug === '1' ? '1' : undefined;
|
|
60
|
+
}
|
|
61
|
+
function getTraceFlags(carrier, getter) {
|
|
62
|
+
const traceFlags = getHeaderValue(carrier, getter, exports.X_B3_SAMPLED);
|
|
63
|
+
const debug = getDebug(carrier, getter);
|
|
64
|
+
if (debug === '1' || VALID_SAMPLED_VALUES.has(traceFlags)) {
|
|
65
|
+
return api_1.TraceFlags.SAMPLED;
|
|
66
|
+
}
|
|
67
|
+
if (traceFlags === undefined || VALID_UNSAMPLED_VALUES.has(traceFlags)) {
|
|
68
|
+
return api_1.TraceFlags.NONE;
|
|
69
|
+
}
|
|
70
|
+
// This indicates to isValidSampledValue that this is not valid
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
function getInfo(carrier, getter) {
|
|
74
|
+
const info = getHeaderValue(carrier, getter, exports.X_B3_INFO);
|
|
75
|
+
if (typeof info === 'string') {
|
|
76
|
+
return info;
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
class UoaB3Propagator {
|
|
81
|
+
inject(context, carrier, setter) {
|
|
82
|
+
const spanContext = api_1.trace.getSpanContext(context);
|
|
83
|
+
if (!spanContext ||
|
|
84
|
+
!(0, api_1.isSpanContextValid)(spanContext) ||
|
|
85
|
+
(0, core_1.isTracingSuppressed)(context))
|
|
86
|
+
return;
|
|
87
|
+
const debug = context.getValue(exports.B3_DEBUG_FLAG_KEY);
|
|
88
|
+
const traceIdLength = context.getValue(exports.B3_TRACE_ID_LENGTH_KEY);
|
|
89
|
+
setter.set(carrier, exports.X_B3_TRACE_ID, spanContext.traceId.slice(spanContext.traceId.length - traceIdLength));
|
|
90
|
+
setter.set(carrier, exports.X_B3_SPAN_ID, crypto.randomBytes(8).toString('hex'));
|
|
91
|
+
setter.set(carrier, exports.X_B3_PARENT_SPAN_ID, spanContext.spanId);
|
|
92
|
+
const info = context.getValue(exports.B3_INFO_KEY);
|
|
93
|
+
if ((0, tracing_1.getTraceInfoHeader)()) {
|
|
94
|
+
setter.set(carrier, exports.X_B3_INFO, (0, tracing_1.getTraceInfoHeader)());
|
|
95
|
+
}
|
|
96
|
+
else if (info && typeof info === 'string') {
|
|
97
|
+
setter.set(carrier, exports.X_B3_INFO, info.toString());
|
|
98
|
+
}
|
|
99
|
+
// According to the B3 spec, if the debug flag is set,
|
|
100
|
+
// the sampled flag shouldn't be propagated as well.
|
|
101
|
+
if (debug === '1') {
|
|
102
|
+
setter.set(carrier, exports.X_B3_FLAGS, debug);
|
|
103
|
+
}
|
|
104
|
+
else if (spanContext.traceFlags !== undefined) {
|
|
105
|
+
// We set the header only if there is an existing sampling decision.
|
|
106
|
+
// Otherwise we will omit it => Absent.
|
|
107
|
+
setter.set(carrier, exports.X_B3_SAMPLED, (api_1.TraceFlags.SAMPLED & spanContext.traceFlags) === api_1.TraceFlags.SAMPLED
|
|
108
|
+
? '1'
|
|
109
|
+
: '0');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
extract(context, carrier, getter) {
|
|
113
|
+
const traceIdLength = getTraceIdLength(carrier, getter);
|
|
114
|
+
context = context.setValue(exports.B3_TRACE_ID_LENGTH_KEY, traceIdLength);
|
|
115
|
+
const traceId = getTraceId(carrier, getter);
|
|
116
|
+
const spanId = getSpanId(carrier, getter);
|
|
117
|
+
const traceFlags = getTraceFlags(carrier, getter);
|
|
118
|
+
const debug = getDebug(carrier, getter);
|
|
119
|
+
const info = getInfo(carrier, getter);
|
|
120
|
+
context = context.setValue(exports.B3_DEBUG_FLAG_KEY, debug);
|
|
121
|
+
if (info) {
|
|
122
|
+
context = context.setValue(exports.B3_INFO_KEY, info);
|
|
123
|
+
}
|
|
124
|
+
return api_1.trace.setSpanContext(context, {
|
|
125
|
+
traceId,
|
|
126
|
+
spanId,
|
|
127
|
+
isRemote: true,
|
|
128
|
+
traceFlags,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
fields() {
|
|
132
|
+
return [
|
|
133
|
+
exports.X_B3_TRACE_ID,
|
|
134
|
+
exports.X_B3_SPAN_ID,
|
|
135
|
+
exports.X_B3_FLAGS,
|
|
136
|
+
exports.X_B3_SAMPLED,
|
|
137
|
+
exports.X_B3_PARENT_SPAN_ID,
|
|
138
|
+
exports.X_B3_INFO
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.UoaB3Propagator = UoaB3Propagator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const UoaB3Propagator_1 = require("./UoaB3Propagator");
|
|
4
|
+
const tracing_1 = require("./tracing");
|
|
5
|
+
const winston = require('winston');
|
|
6
|
+
const moment = require('moment');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { trace, context } = require('@opentelemetry/api');
|
|
9
|
+
const defaultLogPattern = '%date [%thread] %level %class - [[[%traceId,%spanId,%info]]] %message';
|
|
10
|
+
const uoaLogLevels = {
|
|
11
|
+
error: 0,
|
|
12
|
+
warn: 1,
|
|
13
|
+
info: 2,
|
|
14
|
+
debug: 3
|
|
15
|
+
};
|
|
16
|
+
const uoaLoggingFormat = function (callingModule) {
|
|
17
|
+
return winston.format.printf((logInfo) => {
|
|
18
|
+
let logPattern = process.env.loggingPattern ? process.env.loggingPattern : defaultLogPattern;
|
|
19
|
+
const logReplacements = getLogReplacementValues(callingModule, logInfo);
|
|
20
|
+
logReplacements.forEach((value, key) => {
|
|
21
|
+
logPattern = logPattern.replace(key, value);
|
|
22
|
+
});
|
|
23
|
+
return logPattern;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
function getLogReplacementValues(callingModule, logInfo) {
|
|
27
|
+
const parts = callingModule.filename.substring(0, callingModule.filename.lastIndexOf('.js')).split(path.sep);
|
|
28
|
+
const moduleParts = parts.slice(parts.indexOf('src'));
|
|
29
|
+
let traceId = '-';
|
|
30
|
+
let spanId = '-';
|
|
31
|
+
const currentContext = trace.getSpanContext(context.active());
|
|
32
|
+
if (currentContext) {
|
|
33
|
+
traceId = currentContext.traceId;
|
|
34
|
+
spanId = currentContext.spanId;
|
|
35
|
+
}
|
|
36
|
+
let info = '-';
|
|
37
|
+
const infoHeader = context.active().getValue(UoaB3Propagator_1.B3_INFO_KEY);
|
|
38
|
+
if ((0, tracing_1.getTraceInfoHeader)()) {
|
|
39
|
+
info = (0, tracing_1.getTraceInfoHeader)();
|
|
40
|
+
}
|
|
41
|
+
else if (infoHeader) {
|
|
42
|
+
info = infoHeader.toString();
|
|
43
|
+
}
|
|
44
|
+
let message = '-';
|
|
45
|
+
if (logInfo.message != null) {
|
|
46
|
+
message = logInfo.message;
|
|
47
|
+
}
|
|
48
|
+
const traceIdLength = context.active().getValue(UoaB3Propagator_1.B3_TRACE_ID_LENGTH_KEY);
|
|
49
|
+
let logReplacements = new Map();
|
|
50
|
+
logReplacements.set('%date', moment().toISOString());
|
|
51
|
+
logReplacements.set('%thread', '-');
|
|
52
|
+
logReplacements.set('%level', logInfo.level.toUpperCase());
|
|
53
|
+
logReplacements.set('%class', moduleParts.join('.'));
|
|
54
|
+
logReplacements.set('%traceId', traceId.slice(traceId.length - traceIdLength));
|
|
55
|
+
logReplacements.set('%spanId', spanId);
|
|
56
|
+
logReplacements.set('%info', info);
|
|
57
|
+
logReplacements.set('%message', message.replace(/\n/g, ''));
|
|
58
|
+
return logReplacements;
|
|
59
|
+
}
|
|
60
|
+
module.exports = function (callingModule) {
|
|
61
|
+
return winston.createLogger({
|
|
62
|
+
levels: uoaLogLevels,
|
|
63
|
+
transports: [
|
|
64
|
+
new winston.transports.Console({
|
|
65
|
+
level: process.env.loggingLevel ? process.env.loggingLevel.toLowerCase() : 'info'
|
|
66
|
+
})
|
|
67
|
+
],
|
|
68
|
+
format: uoaLoggingFormat(callingModule)
|
|
69
|
+
});
|
|
70
|
+
};
|
package/dist/tracing.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setTraceInfoHeader = exports.getTraceInfoHeader = exports.initializeTracing = void 0;
|
|
4
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
5
|
+
const instrumentation_aws_lambda_1 = require("@opentelemetry/instrumentation-aws-lambda");
|
|
6
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
7
|
+
const UoaB3Propagator_1 = require("./UoaB3Propagator");
|
|
8
|
+
const api_1 = require("@opentelemetry/api");
|
|
9
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
10
|
+
const zipkin_1 = require("./zipkin/zipkin");
|
|
11
|
+
const provider = new sdk_trace_node_1.NodeTracerProvider({ sampler: new sdk_trace_base_1.AlwaysOnSampler() });
|
|
12
|
+
let infoHeader;
|
|
13
|
+
function initializeTracing(serviceName) {
|
|
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 sdk_trace_node_1.BatchSpanProcessor(new zipkin_1.ZipkinExporter(options)));
|
|
19
|
+
provider.register({
|
|
20
|
+
propagator: new UoaB3Propagator_1.UoaB3Propagator()
|
|
21
|
+
});
|
|
22
|
+
(0, instrumentation_1.registerInstrumentations)({
|
|
23
|
+
instrumentations: [
|
|
24
|
+
new instrumentation_aws_lambda_1.AwsLambdaInstrumentation({
|
|
25
|
+
requestHook: (span, { event, context }) => {
|
|
26
|
+
span.setAttribute('faas.name', context.functionName);
|
|
27
|
+
infoHeader = undefined; //reset header value in case lambda execution environment maintained since last invocation
|
|
28
|
+
},
|
|
29
|
+
responseHook: (span, { err, res }) => {
|
|
30
|
+
if (err instanceof Error)
|
|
31
|
+
span.setAttribute('faas.error', err.message);
|
|
32
|
+
if (res)
|
|
33
|
+
span.setAttribute('faas.res', res);
|
|
34
|
+
},
|
|
35
|
+
disableAwsContextPropagation: true
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.initializeTracing = initializeTracing;
|
|
41
|
+
function getTraceInfoHeader() {
|
|
42
|
+
if (infoHeader) {
|
|
43
|
+
return infoHeader;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return api_1.context.active().getValue(UoaB3Propagator_1.B3_INFO_KEY);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.getTraceInfoHeader = getTraceInfoHeader;
|
|
50
|
+
function setTraceInfoHeader(info) {
|
|
51
|
+
infoHeader = info;
|
|
52
|
+
}
|
|
53
|
+
exports.setTraceInfoHeader = setTraceInfoHeader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/uoaHttps.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const https = __importStar(require("https"));
|
|
36
|
+
const api_1 = require("@opentelemetry/api");
|
|
37
|
+
function request(...args) {
|
|
38
|
+
if (args[2]) {
|
|
39
|
+
api_1.propagation.inject(api_1.context.active(), args[1].headers);
|
|
40
|
+
return https.request(args[0], args[1], args[2]);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
api_1.propagation.inject(api_1.context.active(), args[0].headers);
|
|
44
|
+
return https.request(args[0], args[1]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function doGetRequest(hostname, path, headers, port = 443) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return new Promise(function (resolve, reject) {
|
|
50
|
+
const options = {
|
|
51
|
+
"method": "GET",
|
|
52
|
+
"hostname": hostname,
|
|
53
|
+
"path": path,
|
|
54
|
+
"headers": headers,
|
|
55
|
+
"port": port
|
|
56
|
+
};
|
|
57
|
+
api_1.propagation.inject(api_1.context.active(), options.headers);
|
|
58
|
+
const req = https.request(options, function (response) {
|
|
59
|
+
const chunks = [];
|
|
60
|
+
response.on("data", function (chunk) {
|
|
61
|
+
chunks.push(chunk);
|
|
62
|
+
});
|
|
63
|
+
response.on("end", function () {
|
|
64
|
+
let body = Buffer.concat(chunks);
|
|
65
|
+
body = JSON.parse(body.toString());
|
|
66
|
+
resolve(body);
|
|
67
|
+
});
|
|
68
|
+
response.on("error", function (e) {
|
|
69
|
+
reject(e);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
req.end();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function doPostRequest(hostname, path, headers, data, port = 443) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return new Promise(function (resolve, reject) {
|
|
79
|
+
const options = {
|
|
80
|
+
"method": "POST",
|
|
81
|
+
"hostname": hostname,
|
|
82
|
+
"path": path,
|
|
83
|
+
"headers": headers,
|
|
84
|
+
"port": port
|
|
85
|
+
};
|
|
86
|
+
api_1.propagation.inject(api_1.context.active(), options.headers);
|
|
87
|
+
const req = https.request(options, function (response) {
|
|
88
|
+
const chunks = [];
|
|
89
|
+
response.on("data", function (chunk) {
|
|
90
|
+
chunks.push(chunk);
|
|
91
|
+
});
|
|
92
|
+
response.on("end", function () {
|
|
93
|
+
if (response.statusCode == 204) {
|
|
94
|
+
//204 is no content, and most JSON parses blow up on an empty string
|
|
95
|
+
resolve(null);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
let body = Buffer.concat(chunks);
|
|
99
|
+
if (!('Content-Type' in options.headers) || options.headers['Content-Type'] === 'application/json') {
|
|
100
|
+
body = JSON.parse(body.toString());
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
body = body.toString();
|
|
104
|
+
}
|
|
105
|
+
resolve(body);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
response.on("error", function (e) {
|
|
109
|
+
reject(e);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
if (data) {
|
|
113
|
+
if (!('Content-Type' in options.headers) || options.headers['Content-Type'] === 'application/json') {
|
|
114
|
+
//We serialize using JSON.stringify as a default, or if a JSON is specified
|
|
115
|
+
req.write(JSON.stringify(data));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// If another content-type is specified however, we respect the serialization provided
|
|
119
|
+
req.write(data);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
req.end();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function doPutRequest(hostname, path, headers, data, port = 443) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
return new Promise(function (resolve, reject) {
|
|
129
|
+
const options = {
|
|
130
|
+
"method": "PUT",
|
|
131
|
+
"hostname": hostname,
|
|
132
|
+
"path": path,
|
|
133
|
+
"headers": headers,
|
|
134
|
+
"port": port
|
|
135
|
+
};
|
|
136
|
+
api_1.propagation.inject(api_1.context.active(), options.headers);
|
|
137
|
+
const req = https.request(options, function (response) {
|
|
138
|
+
const chunks = [];
|
|
139
|
+
response.on("data", function (chunk) {
|
|
140
|
+
chunks.push(chunk);
|
|
141
|
+
});
|
|
142
|
+
response.on("end", function () {
|
|
143
|
+
if (response.statusCode == 204) {
|
|
144
|
+
//204 is no content, and most JSON parses blow up on an empty string
|
|
145
|
+
resolve(null);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
let body = Buffer.concat(chunks);
|
|
149
|
+
if (!('Content-Type' in options.headers) || options.headers['Content-Type'] === 'application/json') {
|
|
150
|
+
body = JSON.parse(body.toString());
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
body = body.toString();
|
|
154
|
+
}
|
|
155
|
+
resolve(body);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
response.on("error", function (e) {
|
|
159
|
+
reject(e);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
if (data) {
|
|
163
|
+
if (!('Content-Type' in options.headers) || options.headers['Content-Type'] === 'application/json') {
|
|
164
|
+
//We serialize using JSON.stringify as a default, or if a JSON is specified
|
|
165
|
+
req.write(JSON.stringify(data));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// If another content-type is specified however, we respect the serialization provided
|
|
169
|
+
req.write(data);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
req.end();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function doDeleteRequest(hostname, path, headers, port = 443) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
return new Promise(function (resolve, reject) {
|
|
179
|
+
const options = {
|
|
180
|
+
"method": "DELETE",
|
|
181
|
+
"hostname": hostname,
|
|
182
|
+
"path": path,
|
|
183
|
+
"headers": headers,
|
|
184
|
+
"port": port
|
|
185
|
+
};
|
|
186
|
+
api_1.propagation.inject(api_1.context.active(), options.headers);
|
|
187
|
+
const req = https.request(options, function (response) {
|
|
188
|
+
const chunks = [];
|
|
189
|
+
response.on("data", function (chunk) {
|
|
190
|
+
chunks.push(chunk);
|
|
191
|
+
});
|
|
192
|
+
response.on("end", function () {
|
|
193
|
+
if (response.statusCode == 204) {
|
|
194
|
+
//204 is no content, and most JSON parses blow up on an empty string
|
|
195
|
+
resolve(null);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
let body = Buffer.concat(chunks);
|
|
199
|
+
if (!('Content-Type' in options.headers) || options.headers['Content-Type'] === 'application/json') {
|
|
200
|
+
body = JSON.parse(body.toString());
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
body = body.toString();
|
|
204
|
+
}
|
|
205
|
+
resolve(body);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
response.on("error", function (e) {
|
|
209
|
+
reject(e);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
req.end();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
module.exports = {
|
|
217
|
+
request,
|
|
218
|
+
doGetRequest,
|
|
219
|
+
doPostRequest,
|
|
220
|
+
doPutRequest,
|
|
221
|
+
doDeleteRequest
|
|
222
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uoa/lambda-tracing",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.5",
|
|
4
4
|
"description": "Library for logging & distributed tracing in UoA Lambda projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"types": "dist/tracing.d.ts",
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
-
"
|
|
22
|
+
"prepare": "tsc"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./dist/tracing.js",
|