Skip to content

Make OpenTelemetry tracing opt-in and handle exporter failures #43

Description

@priscaenoch

Problem

src/tracer.ts constructs a NodeSDK and calls sdk.start() unconditionally at import time, with OTLP_ENDPOINT defaulting to http://localhost:4318. This means every run of the service starts tracing and attempts to export spans to a local collector, even in development or CI where no collector exists, producing connection errors and overhead. There is no flag to disable it and no graceful shutdown.

What needs to be done

  • Gate startup behind an explicit env flag (for example TRACING_ENABLED), off by default, or auto-disable when OTLP_ENDPOINT is unset.
  • Wrap sdk.start() so exporter/connection errors are logged and do not crash or spam the process.
  • Register a shutdown hook (sdk.shutdown()) on SIGTERM/SIGINT so spans flush cleanly.
  • Document the tracing environment variables (OTLP_ENDPOINT, SERVICE_NAME, the new enable flag) in the README and .env.example.

Files

  • src/tracer.ts
  • .env.example, README.md

Acceptance deliverables

  • Tracing is off by default and only starts when explicitly enabled or configured.
  • A missing/unreachable collector does not produce repeated crashes or error spam.
  • All CI checks pass; the change cannot be merged until CI is green.

Tests to pass

  • Test: with tracing disabled/unconfigured, the SDK does not start.
  • Test: an exporter initialization error is handled without throwing.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions