UNPKG

2.28 kBJavaScriptView Raw
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 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.ConsoleSpanExporter = void 0;
19const core_1 = require("@opentelemetry/core");
20/**
21 * This is implementation of {@link SpanExporter} that prints spans to the
22 * console. This class can be used for diagnostic purposes.
23 */
24/* eslint-disable no-console */
25class ConsoleSpanExporter {
26 /**
27 * Export spans.
28 * @param spans
29 * @param resultCallback
30 */
31 export(spans, resultCallback) {
32 return this._sendSpans(spans, resultCallback);
33 }
34 /**
35 * Shutdown the exporter.
36 */
37 shutdown() {
38 this._sendSpans([]);
39 return Promise.resolve();
40 }
41 /**
42 * converts span info into more readable format
43 * @param span
44 */
45 _exportInfo(span) {
46 return {
47 traceId: span.spanContext().traceId,
48 parentId: span.parentSpanId,
49 name: span.name,
50 id: span.spanContext().spanId,
51 kind: span.kind,
52 timestamp: core_1.hrTimeToMicroseconds(span.startTime),
53 duration: core_1.hrTimeToMicroseconds(span.duration),
54 attributes: span.attributes,
55 status: span.status,
56 events: span.events,
57 };
58 }
59 /**
60 * Showing spans in console
61 * @param spans
62 * @param done
63 */
64 _sendSpans(spans, done) {
65 for (const span of spans) {
66 console.log(this._exportInfo(span));
67 }
68 if (done) {
69 return done({ code: core_1.ExportResultCode.SUCCESS });
70 }
71 }
72}
73exports.ConsoleSpanExporter = ConsoleSpanExporter;
74//# sourceMappingURL=ConsoleSpanExporter.js.map
\No newline at end of file