Skip to main content

An exporter that can be used to output a Server-Timing header.

Works with
It is unknown whether this package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Browsers
JSR Score
100%
Published
2 weeks ago (1.1.2)

OpenTelemetry ServerTimingSpanExporter

JSR JSR Score codecov

An exporter that can be used to output a Server-Timing header.

Usage

import opentelemetry from '@opentelemetry/api';
import { BasicTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { ServerTimingSpanExporter } from '@esroyo/otel-server-timing-span-exporter';

const provider = new BasicTracerProvider();
const exporter = new ServerTimingSpanExporter();
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();

const tracer = opentelemetry.trace.getTracer('default');
const parentSpan = tracer.startSpan('main');
parentSpan.addEvent('start');
parentSpan.end();

const responseHeaders = new Headers();
responseHeaders.set(...exporter.getServerTimingHeader(parentSpan));
console.log(responseHeaders);
// Headers { "server-timing": "start,main;dur=0.269936" }

Add Package

deno add @esroyo/otel-server-timing-span-exporter

Import symbol

import * as mod from "@esroyo/otel-server-timing-span-exporter";

Add Package

npx jsr add @esroyo/otel-server-timing-span-exporter

Import symbol

import * as mod from "@esroyo/otel-server-timing-span-exporter";

Add Package

yarn dlx jsr add @esroyo/otel-server-timing-span-exporter

Import symbol

import * as mod from "@esroyo/otel-server-timing-span-exporter";

Add Package

pnpm dlx jsr add @esroyo/otel-server-timing-span-exporter

Import symbol

import * as mod from "@esroyo/otel-server-timing-span-exporter";

Add Package

bunx jsr add @esroyo/otel-server-timing-span-exporter

Import symbol

import * as mod from "@esroyo/otel-server-timing-span-exporter";