# Tracing and OpenTelemetry

Correlate supported requests and export JavaScript spans into the same project.


## Propagate only to approved origins

The SDK uses W3C `traceparent` context for supported instrumented requests. Same-origin requests can be correlated; use an explicit allowlist for additional origins.

```ts title="Allowed trace targets"
import { init } from '@everock/sdk';
init({
  publicKey: 'pk_YOUR_PROJECT_KEY',
  endpoint: 'https://collector.example.com',
  tracePropagationTargets: ['https://api.example.com'],
});
```

Cross-origin propagation can require appropriate CORS configuration on the receiving API. Do not allow every third-party origin by default.

## Server spans

```ts title="Business operation"
import { withSpan } from '@everock/sdk/node';
const order = await withSpan('checkout.create', async () => createOrder());
```

`withSpan` adds context around the operation. It does not automatically trace an uninstrumented remote service.

## OpenTelemetry exporter

```ts title="exporter.ts"
import { EverockSpanExporter } from '@everock/sdk/opentelemetry';
const exporter = new EverockSpanExporter({
  publicKey: process.env.EVEROCK_PUBLIC_KEY!,
  endpoint: process.env.EVEROCK_ENDPOINT!,
  component: 'api',
  environment: 'production',
});
```

Pass this exporter to a compatible OpenTelemetry JavaScript span processor in your existing instrumentation. It maps span identities, timing, status, attributes, and span events into telemetry. It skips collector requests to avoid observing its own delivery loop.

Flush your processor/exporter before a short-lived process exits. This exporter is not a native Swift, Kotlin, or arbitrary OTLP collector endpoint.
