@foam-ai/opentelemetry
v0.1.0-alpha.2
Published
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.
Downloads
142
Readme
@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
npm install @foam-ai/opentelemetryUsage
Call recordException inside Sentry's beforeSend to forward errors to Foam via the active OTel span:
Browser — sentry.client.config.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
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
- Gets the active span via
trace.getActiveSpan()from@opentelemetry/api - Calls
span.recordException()with the error - Wrapped in
safe()— never throws, silently no-ops if no active span
Acknowledgements
| Project | License | Link |
|---------|---------|------|
| OpenTelemetry JS (@opentelemetry/api) | Apache-2.0 | https://github.com/open-telemetry/opentelemetry-js |
