Skip to content

feat(otel): add OpenTelemetry base instrumentation#1087

Draft
dimoschi wants to merge 1 commit intoopensanctions:mainfrom
dimoschi:feat/otel-base-instrumentation
Draft

feat(otel): add OpenTelemetry base instrumentation#1087
dimoschi wants to merge 1 commit intoopensanctions:mainfrom
dimoschi:feat/otel-base-instrumentation

Conversation

@dimoschi
Copy link
Copy Markdown

@dimoschi dimoschi commented Apr 2, 2026

Summary

Adds OpenTelemetry instrumentation to yente (ref #1079):

  • FastAPI auto-instrumentation for HTTP metrics and traces via FastAPIInstrumentor
  • Manual spans on all SearchProvider operations via __init_subclass__, providing consistent tracing for both Elasticsearch and OpenSearch backends
  • Uses stable OTEL semantic conventions (db.system.name, db.operation.name)
  • No custom configuration - no manual TracerProvider, no new yente env vars. Users configure everything via standard OTEL_* env vars and the opentelemetry-instrument CLI

New dependencies

  • opentelemetry-api
  • opentelemetry-sdk
  • opentelemetry-instrumentation-fastapi
  • opentelemetry-exporter-otlp-proto-http

Usage

To enable OTEL tracing, run yente with opentelemetry-instrument:

opentelemetry-instrument \
  --service_name yente \
  --traces_exporter otlp \
  --exporter_otlp_endpoint http://collector:4318 \
  yente serve

Or configure via env vars:

OTEL_SERVICE_NAME=yente
OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
opentelemetry-instrument yente serve

Without opentelemetry-instrument, OTEL is a no-op (zero overhead).

What this does NOT include (future PRs)

  • /metrics Prometheus scrape endpoint
  • Custom gauges for catalog data (datasets loaded/outdated, index staleness)

Test plan

  • New tests in tests/test_otel.py verify span creation for HTTP requests and SearchProvider operations
  • Existing test suite passes without regressions (104 tests)

- Add opentelemetry-api, opentelemetry-sdk, opentelemetry-instrumentation-fastapi,
  and opentelemetry-exporter-otlp-proto-http as dependencies
- Use FastAPIInstrumentor for automatic HTTP metrics and traces
- Add manual spans on SearchProvider operations via __init_subclass__,
  providing consistent tracing for both Elasticsearch and OpenSearch backends
- Use stable OTEL semantic conventions (db.system.name, db.operation.name)
- No manual TracerProvider setup; users configure OTEL entirely via
  standard env vars and opentelemetry-instrument CLI

Ref: opensanctions#1079
@dimoschi dimoschi force-pushed the feat/otel-base-instrumentation branch from 4a14ac0 to d5fd44d Compare April 2, 2026 00:43
@leonhandreke
Copy link
Copy Markdown
Contributor

Hi, thanks for sending this and sorry for the delay! I was out for part of the week and currently working on some urgent things - will get to this beginning of next week.

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.

2 participants