chore: Refactor OTel concerns in preparation for metric provider#123
chore: Refactor OTel concerns in preparation for metric provider#123morgan-wowk wants to merge 1 commit intomasterfrom
Conversation
8a5aa83 to
7672232
Compare
7672232 to
0d953d1
Compare
cloud_pipelines_backend/instrumentation/opentelemetry/_internal/config.py
Show resolved
Hide resolved
cloud_pipelines_backend/instrumentation/opentelemetry/_internal/tests/conftest.py
Show resolved
Hide resolved
cloud_pipelines_backend/instrumentation/opentelemetry/_internal/config.py
Outdated
Show resolved
Hide resolved
cloud_pipelines_backend/instrumentation/opentelemetry/_internal/config.py
Outdated
Show resolved
Hide resolved
…ider
**Changes:**
* Better organize opentelemetry code to create a better API for callers (various entrypoints) to:
* Setup providers (tracing, metrics, logging eventually)
* Setup FastAPI auto instrumentation
Made-with: Cursor
0d953d1 to
f2c09c1
Compare
|
@yuechao-qin Feedback addressed. |
| # region: OpenTelemetry initialization | ||
| from cloud_pipelines_backend.instrumentation import opentelemetry as otel | ||
|
|
||
| otel.setup_providers() |
There was a problem hiding this comment.
Question: for local setup, should otel service be run separately? What would happen if no OTEL endpoint is configured (e.g. in case of e2e tests on CI)?
There was a problem hiding this comment.
Great question.
I'll answer in two ways.
For local development, we have this example stack I added and have personally been using to test traces and metrics for OSS: https://github.com/TangleML/tangle/tree/master/examples/observability/otel-jaeger-prometheus
For writing tests, or adding new metrics, here are some important things to know:
- The OTel Python SDK that we consume, and even our FastAPI auto-instrumentation consumes, is intentionally designed so that every action is a NOOP if no providers are set.
- It means, no exceptions from emitting metrics or opening traces when OTel is not configured.
- We only set providers on our end if they have filled out correctly shaped values for the environment variables.
- We only auto-instrument FastAPI if providers are set.
- For verfiying a metric, or trace, was used, via testing (whether its unit or e2e) that is possible and I'll follow up with instructions and examples in a separate PR. Consider this is a TODO. We will have to manipulate the type of reader / exporter we use at the start of tests.
Hmm. Are you sure we're simplifying things? It's hard to get more simple than the current 1-liner: otel_tracing.setup_api_tracing(app) |

Refactor OpenTelemetry instrumentation into modular package
Changes:
setup_providers()andinstrument_fastapi())