UNPKG

@fiberplane/hono-otel

Version:

Hono middleware to forward OpenTelemetry traces to a local instance of @fiberplane/studio

33 lines (32 loc) 1.43 kB
import { type ExportResult } from "@opentelemetry/core"; import { OTLPExporterError } from "@opentelemetry/otlp-exporter-base"; import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base"; import type { FpxLogger } from "./logger.js"; import type { FetchFn } from "./types/index.js"; interface OTLPExporterConfig { url: string; headers?: Record<string, string>; } /** * @NOTE - We had to implement a custom SpanExporter because the OTLPTraceExporter * was not working for us in Cloudflare Workers. * * Specifically, the OTLPTraceExporter kept thinking that we were in the browser, * _but only when we attached a `headers` object to the request._ * * The lack of browser APIs (XHR, sendBeacon) led to runtime errors. * * Solution inspired by https://github.com/evanderkoogh/otel-cf-workers/blob/450435bc136d5b81aee655096aa4b8261f42d0c7/src/exporter.ts */ export declare class FPOTLPExporter implements SpanExporter { private headers; private url; private fetchFn; private logger; constructor(config: OTLPExporterConfig, fetchFn: FetchFn, logger: FpxLogger); export(items: Array<ReadableSpan>, resultCallback: (result: ExportResult) => void): void; private _export; send(items: Array<ReadableSpan>, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void; shutdown(): Promise<void>; } export {};