UNPKG

@redocly/cli

Version:

[@Redocly](https://redocly.com) CLI is your all-in-one API documentation utility. It builds, manages, improves, and quality-checks your API descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make

39 lines 1.66 kB
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; import { resourceFromAttributes } from '@opentelemetry/resources'; import { NodeTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node'; import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions'; import { processCloudEventAttributes } from '@redocly/cli-otel'; import { ulid } from 'ulid'; import { OTEL_TRACES_URL, DEFAULT_FETCH_TIMEOUT } from './constants.js'; import { version } from './package.js'; export class OtelServerTelemetry { constructor() { this.nodeTracerProvider = new NodeTracerProvider({ resource: resourceFromAttributes({ [ATTR_SERVICE_NAME]: `redocly-cli`, [ATTR_SERVICE_VERSION]: `@redocly/cli@${version}`, session_id: `ses_${ulid()}`, }), spanProcessors: [ new SimpleSpanProcessor(new OTLPTraceExporter({ url: OTEL_TRACES_URL, headers: {}, timeoutMillis: DEFAULT_FETCH_TIMEOUT, })), ], }); } send(cloudEvent) { const time = new Date(cloudEvent.time); const tracer = this.nodeTracerProvider.getTracer('CliTelemetry'); const spanName = `event.${cloudEvent.type}`; const attributes = processCloudEventAttributes(cloudEvent, time); const span = tracer.startSpan(spanName, { attributes, startTime: time, }); span.end(time); } } export const otelTelemetry = new OtelServerTelemetry(); //# sourceMappingURL=otel.js.map