|
| 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 | +} |
0 commit comments