@uoa/lambda-tracing 2.0.0-beta.2 → 2.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,124 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * https://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ZipkinExporter = void 0;
19
- /**
20
- * Copied from https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-exporter-zipkin/src/zipkin.ts
21
- *
22
- * Modified to prioritise input serviceName over SemanticResourceAttributes.SERVICE_NAME
23
- */
24
- const api_1 = require("@opentelemetry/api");
25
- const core_1 = require("@opentelemetry/core");
26
- const index_1 = require("./platform/index");
27
- const transform_1 = require("./transform");
28
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
29
- const utils_1 = require("./utils");
30
- /**
31
- * Zipkin Exporter
32
- */
33
- class ZipkinExporter {
34
- constructor(config = {}) {
35
- this.DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
36
- this._sendingPromises = [];
37
- this._urlStr = config.url || (0, core_1.getEnv)().OTEL_EXPORTER_ZIPKIN_ENDPOINT;
38
- this._send = (0, index_1.prepareSend)(this._urlStr, config.headers);
39
- this._serviceName = config.serviceName;
40
- this._statusCodeTagName = config.statusCodeTagName || transform_1.defaultStatusCodeTagName;
41
- this._statusDescriptionTagName =
42
- config.statusDescriptionTagName || transform_1.defaultStatusErrorTagName;
43
- this._isShutdown = false;
44
- if (typeof config.getExportRequestHeaders === 'function') {
45
- this._getHeaders = (0, utils_1.prepareGetHeaders)(config.getExportRequestHeaders);
46
- }
47
- else {
48
- // noop
49
- this._beforeSend = function () { };
50
- }
51
- }
52
- /**
53
- * Export spans.
54
- */
55
- export(spans, resultCallback) {
56
- const serviceName = String(this._serviceName ||
57
- spans[0].resource.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
58
- this.DEFAULT_SERVICE_NAME);
59
- api_1.diag.debug('export: ', serviceName);
60
- api_1.diag.debug('Zipkin exporter export');
61
- if (this._isShutdown) {
62
- setTimeout(() => resultCallback({
63
- code: core_1.ExportResultCode.FAILED,
64
- error: new Error('Exporter has been shutdown'),
65
- }));
66
- return;
67
- }
68
- const promise = new Promise(resolve => {
69
- this._sendSpans(spans, serviceName, result => {
70
- resolve();
71
- resultCallback(result);
72
- });
73
- });
74
- this._sendingPromises.push(promise);
75
- const popPromise = () => {
76
- const index = this._sendingPromises.indexOf(promise);
77
- this._sendingPromises.splice(index, 1);
78
- };
79
- promise.then(popPromise, popPromise);
80
- }
81
- /**
82
- * Shutdown exporter. Noop operation in this exporter.
83
- */
84
- shutdown() {
85
- api_1.diag.debug('Zipkin exporter shutdown');
86
- this._isShutdown = true;
87
- return new Promise((resolve, reject) => {
88
- Promise.all(this._sendingPromises).then(() => {
89
- resolve();
90
- }, reject);
91
- });
92
- }
93
- /**
94
- * if user defines getExportRequestHeaders in config then this will be called
95
- * everytime before send, otherwise it will be replaced with noop in
96
- * constructor
97
- * @default noop
98
- */
99
- _beforeSend() {
100
- if (this._getHeaders) {
101
- this._send = (0, index_1.prepareSend)(this._urlStr, this._getHeaders());
102
- }
103
- }
104
- /**
105
- * Transform spans and sends to Zipkin service.
106
- */
107
- _sendSpans(spans, serviceName, done) {
108
- const zipkinSpans = spans.map(span => {
109
- api_1.diag.debug('sendSpans: ', String(serviceName ||
110
- span.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
111
- span.resource.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]));
112
- return (0, transform_1.toZipkinSpan)(span, String(serviceName ||
113
- span.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] ||
114
- span.resource.attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]), this._statusCodeTagName, this._statusDescriptionTagName);
115
- });
116
- this._beforeSend();
117
- return this._send(zipkinSpans, (result) => {
118
- if (done) {
119
- return done(result);
120
- }
121
- });
122
- }
123
- }
124
- exports.ZipkinExporter = ZipkinExporter;