# @askrjs/otel

> Published API exports for @askrjs/otel.

Source: [https://askrjs.com/docs/reference/api/otel/root](https://askrjs.com/docs/reference/api/otel/root)

Status: stable. Packages: @askrjs/otel.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Exports

This entrypoint publishes 7 exports from the declarations shipped by @askrjs/otel.

### `createTelemetry`

```ts
createTelemetry: (options?: TelemetryOptions) => Telemetry
```

Creates a function-first bridge to the application's installed OpenTelemetry
provider. This package never installs an SDK, processor, backend, or exporter.

### `Telemetry`

```ts
Telemetry: any
```

Function-first bridge to the application's installed OpenTelemetry provider.
Every method wraps a unit of work in a span (or emits a log line) and never
throws on account of tracing/logging failures — application behavior is
always isolated from observability failures.

- `span`: Wraps `work` in a span for the given `operation`, recording `fields` as attributes.

- `request`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.request"`.

- `routeMatch`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.route.match"`.

- `loader`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.loader"`.

- `action`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.action"`.

- `apiOperation`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.api.operation"`.

- `queryPrefetch`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.query.prefetch"`.

- `ssrRender`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.ssr.render"`.

- `viteDocument`: Convenience wrapper for {@link Telemetry.span} with operation `"askr.vite.document"`.

- `log`: Emits a single sanitized log line without opening a span.

- `extract`: Extracts a trace {@link Context} from a carrier (e.g. incoming request headers) using `getter`.

- `inject`: Injects the active (or given) {@link Context} into `carrier` using `setter`, returning the carrier.

- `withContext`: Runs `work` with `value` as the active OpenTelemetry context.

- `traceId`: Returns the trace ID of the currently active span, if any and if valid.

### `TelemetryFields`

```ts
TelemetryFields: any
```

Structured fields attached to a span or log line. Only these known keys are
ever sanitized and forwarded; unknown keys on a passed-in object are dropped.

- `requestId`: requestId?: string;

- `traceId`: traceId?: string;

- `route`: route?: string;

- `action`: action?: string;

- `operation`: operation?: string;

- `status`: status?: number;

- `durationMs`: durationMs?: number;

### `TelemetryLevel`

```ts
TelemetryLevel: "debug" | "info" | "warn" | "error"
```

Severity of a telemetry log line, mirrored from common structured-logging conventions.

### `TelemetryLogger`

```ts
TelemetryLogger: (level: TelemetryLevel, event: TelemetryOperation, fields: Readonly<TelemetryFields>) => void
```

Callback invoked with each sanitized telemetry log line.

### `TelemetryOperation`

```ts
TelemetryOperation: "askr.request" | "askr.route.match" | "askr.loader" | "askr.action" | "askr.api.operation" | "askr.query.prefetch" | "askr.ssr.render" | "askr.vite.document"
```

The set of Askr lifecycle stages that {@link Telemetry} can wrap with a span.

### `TelemetryOptions`

```ts
TelemetryOptions: any
```

Configuration accepted by {@link createTelemetry}.

- `tracerName`: Name passed to `trace.getTracer`. Defaults to `"@askrjs/otel"`.

- `tracerVersion`: Version passed to `trace.getTracer`.

- `logger`: Sink for sanitized log lines. Defaults to a no-op.

- `now`: Clock used for span durations. Defaults to `performance.now`.

- `maxFieldLength`: Maximum length, in characters, retained for any string field. Defaults to 256.

- `sanitizeField`: Per-field hook to redact or transform a field before it is logged or attached to a span; return `undefined` to drop it.

- `sanitizeException`: Exceptions are not exported unless this hook returns a sanitized value.

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/node/mcp/index.md) | [Next](https://askrjs.com/docs/reference/api/schema/root/index.md)
