Skip to content

feat: add OpenTelemetry error reporting#13

Open
matheus1lva wants to merge 1 commit into
mainfrom
feat/add-sentry
Open

feat: add OpenTelemetry error reporting#13
matheus1lva wants to merge 1 commit into
mainfrom
feat/add-sentry

Conversation

@matheus1lva

@matheus1lva matheus1lva commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Report Worker errors as OpenTelemetry log records over OTLP/HTTP. Cloudflare Workers can't run the OpenTelemetry Node SDK (its OTLP exporter is Node-coupled), so the OTLP/HTTP log payload is built and sent directly via fetch — still standard OTLP. Vendor-neutral: point OTEL_EXPORTER_OTLP_ENDPOINT (and OTEL_EXPORTER_OTLP_HEADERS for auth) at any OTLP backend. No-op until configured.

How to review

  • src/observability.ts: captureError(ctx, env, error) POSTs an OTLP LogsData payload (ERROR severity, exception.* attributes) to ${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/logs. Auth headers come from OTEL_EXPORTER_OTLP_HEADERS. Uses ctx.waitUntil so the export completes after the response is returned — no added request latency.
  • src/index.ts: the unexpected-error branch (non-ApiError, 500) calls captureError; ApiError (expected 4xx) paths are unchanged. OTEL_* fields added to the Env type.

Test plan

  • Manual: set OTEL_EXPORTER_OTLP_ENDPOINT (+ OTEL_EXPORTER_OTLP_HEADERS), trigger the 500 branch, confirm the log record reaches the backend.
  • Manual: leave the endpoint unset, confirm nothing is exported and responses are unchanged.
  • Automated: bun run test (33 tests) and bun run typecheck.

Risk / impact

Low. With the OTLP endpoint unset (the default), reporting is a no-op and behavior is unchanged. No funds, auth, or migration paths touched.

@matheus1lva matheus1lva changed the title feat: add Sentry error monitoring feat: add OpenTelemetry error reporting Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant