open-index/open-npm huggingface dataset:
npm package: @foam-ai/opentelemetry
Description: Records exceptions on the active OpenTelemetry span. Designed to be called inside Sentry's `beforeSend` to bridge errors to Foam. Works in both browser and server environments.
Latest version: 0.1.0-alpha.2

# @foam-ai/opentelemetry

Records exceptions on the active OpenTelemetry span. Designed to be called inside Sentry's `beforeSend` to bridge errors to Foam. Works in both browser and server environments.

## Installation

```sh
npm install @foam-ai/opentelemetry
```

## Usage

Call `recordException` inside Sentry's `beforeSend` to forward errors to Foam via the active OTel span:

### Browser — `sentry.client.config.ts`

```ts
import * as Sentry from "@sentry/nextjs";
import { recordException } from "@foam-ai/opentelemetry";

Sentry.init({
  dsn: "...",

  beforeSend: (event, hint) => {
    recordException(hint.originalException);
    return event;
  },
});
```

### Server — `sentry.server.config.ts`

```ts
import * as Sentry from "@sentry/nextjs";
import { recordException } from "@foam-ai/opentelemetry";

Sentry.init({
  dsn: "...",

  beforeSend: (event, hint) => {
    recordException(hint.originalException);
    return event;
  },
});
```

## How it works

1. Gets the active span via `trace.getActiveSpan()` from `@opentelemetry/api`
2. Calls `span.recordException()` with the error
3. Wrapped in `safe()` — never throws, silently no-ops if no active span

## Acknowledgements

| Project | License | Link |
|---------|---------|------|
| [OpenTelemetry JS](https://github.com/open-telemetry/opentelemetry-js) (`@opentelemetry/api`) | Apache-2.0 | https://github.com/open-telemetry/opentelemetry-js |