{"version":3,"file":"ConsoleSpanExporter.mjs","names":[],"sources":["../../src/export/ConsoleSpanExporter.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SpanExporter } from './SpanExporter';\nimport type { ReadableSpan } from './ReadableSpan';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode, hrTimeToMicroseconds } from '@opentelemetry/core';\n\n/**\n * This is implementation of {@link SpanExporter} that prints spans to the\n * console. This class can be used for diagnostic purposes.\n *\n * NOTE: This {@link SpanExporter} is intended for diagnostics use only, output rendered to the console may change at any time.\n */\n\n/* eslint-disable no-console */\nexport class ConsoleSpanExporter implements SpanExporter {\n  /**\n   * Export spans.\n   * @param spans\n   * @param resultCallback\n   */\n  export(\n    spans: ReadableSpan[],\n    resultCallback: (result: ExportResult) => void\n  ): void {\n    return this._sendSpans(spans, resultCallback);\n  }\n\n  /**\n   * Shutdown the exporter.\n   */\n  shutdown(): Promise<void> {\n    this._sendSpans([]);\n    return this.forceFlush();\n  }\n\n  /**\n   * Exports any pending spans in exporter\n   */\n  forceFlush(): Promise<void> {\n    return Promise.resolve();\n  }\n\n  /**\n   * converts span info into more readable format\n   * @param span\n   */\n  private _exportInfo(span: ReadableSpan) {\n    return {\n      resource: {\n        attributes: span.resource.attributes,\n      },\n      instrumentationScope: span.instrumentationScope,\n      traceId: span.spanContext().traceId,\n      parentSpanContext: span.parentSpanContext,\n      traceState: span.spanContext().traceState?.serialize(),\n      name: span.name,\n      id: span.spanContext().spanId,\n      kind: span.kind,\n      timestamp: hrTimeToMicroseconds(span.startTime),\n      duration: hrTimeToMicroseconds(span.duration),\n      attributes: span.attributes,\n      status: span.status,\n      events: span.events,\n      links: span.links,\n    };\n  }\n\n  /**\n   * Showing spans in console\n   * @param spans\n   * @param done\n   */\n  private _sendSpans(\n    spans: ReadableSpan[],\n    done?: (result: ExportResult) => void\n  ): void {\n    for (const span of spans) {\n      console.dir(this._exportInfo(span), { depth: 3 });\n    }\n    if (done) {\n      return done({ code: ExportResultCode.SUCCESS });\n    }\n  }\n}\n"],"mappings":";;;;;;;;AAkBA,IAAa,sBAAb,MAAyD;;;;;;CAMvD,OACE,OACA,gBACM;EACN,OAAO,KAAK,WAAW,OAAO,cAAc;CAC9C;;;;CAKA,WAA0B;EACxB,KAAK,WAAW,CAAC,CAAC;EAClB,OAAO,KAAK,WAAW;CACzB;;;;CAKA,aAA4B;EAC1B,OAAO,QAAQ,QAAQ;CACzB;;;;;CAMA,YAAoB,MAAoB;EACtC,OAAO;GACL,UAAU,EACR,YAAY,KAAK,SAAS,WAC5B;GACA,sBAAsB,KAAK;GAC3B,SAAS,KAAK,YAAY,CAAC,CAAC;GAC5B,mBAAmB,KAAK;GACxB,YAAY,KAAK,YAAY,CAAC,CAAC,YAAY,UAAU;GACrD,MAAM,KAAK;GACX,IAAI,KAAK,YAAY,CAAC,CAAC;GACvB,MAAM,KAAK;GACX,WAAW,qBAAqB,KAAK,SAAS;GAC9C,UAAU,qBAAqB,KAAK,QAAQ;GAC5C,YAAY,KAAK;GACjB,QAAQ,KAAK;GACb,QAAQ,KAAK;GACb,OAAO,KAAK;EACd;CACF;;;;;;CAOA,WACE,OACA,MACM;EACN,KAAK,MAAM,QAAQ,OACjB,QAAQ,IAAI,KAAK,YAAY,IAAI,GAAG,EAAE,OAAO,EAAE,CAAC;EAElD,IAAI,MACF,OAAO,KAAK,EAAE,MAAM,iBAAiB,QAAQ,CAAC;CAElD;AACF"}