Skip to content

Commit a0140ec

Browse files
mayurkale22bg451
authored andcommitted
feat: add ConsoleSpanExporter (open-telemetry#300)
1 parent 013a1e4 commit a0140ec

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*!
2+
* Copyright 2019, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { SpanExporter } from './SpanExporter';
18+
import { ReadableSpan } from './ReadableSpan';
19+
import { ExportResult } from './ExportResult';
20+
import { hrTimeToMilliseconds } from '@opentelemetry/core';
21+
22+
/**
23+
* This is implementation of {@link SpanExporter} that prints spans to the
24+
* console. This class can be used for diagnostic purposes.
25+
*/
26+
export class ConsoleSpanExporter implements SpanExporter {
27+
export(
28+
spans: ReadableSpan[],
29+
resultCallback: (result: ExportResult) => void
30+
): void {
31+
for (const span of spans) {
32+
console.log(
33+
`{name=${span.name}, traceId=${span.spanContext.traceId}, spanId=${
34+
span.spanContext.spanId
35+
}, kind=${span.kind}, parent=${
36+
span.parentSpanId
37+
}, duration=${hrTimeToMilliseconds(span.duration)}}}`
38+
);
39+
}
40+
return resultCallback(ExportResult.SUCCESS);
41+
}
42+
43+
shutdown(): void {}
44+
}

Diff for: packages/opentelemetry-basic-tracer/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
export * from './BasicTracer';
18+
export * from './export/ConsoleSpanExporter';
1819
export * from './export/ExportResult';
1920
export * from './export/InMemorySpanExporter';
2021
export * from './export/ReadableSpan';

0 commit comments

Comments
 (0)