refactor(otel): share OTLP trace provider setup - #2567
Conversation
Extract common OpenTelemetry provider construction into openshell-otel so OpenShell services share one OTLP/gRPC export implementation. The shared crate owns: - typed exporter setup errors and non-fatal provider enablement; - endpoint trimming and URI validation before lazy exporter connection; - fixed and environment-or-default service-name policies; - service version and caller-supplied resource attributes; - batch tracer-provider construction; and - span-only tracing layers that exclude OpenTelemetry exporter callsites. Migrate the gateway to the shared provider while retaining its configurable service name, error marking, and tracing test collector. Add the shared crate to the architecture inventory and document the tracing boundary. Refs #2507 Signed-off-by: Kris Hicks <khicks@nvidia.com>
2ffd547 to
1011bcd
Compare
| match config.service_name { | ||
| ServiceName::Fixed(name) => Resource::builder() | ||
| .with_service_name(name.trim().to_string()) | ||
| .with_attributes(attributes) |
There was a problem hiding this comment.
this is an ultra-nit:
[P2] Fixed service names can be overwritten by generic attributes. In crates/openshell-otel/src/lib.rs (line 70), with_service_name() runs before with_attributes(). OpenTelemetry resource merging gives later attributes priority, so a caller-supplied service.name silently defeats ServiceName::Fixed. The EnvironmentOr path has the same ambiguity because caller attributes participate in detecting the selected name. Apply generic attributes first, then enforce the selected service-name policy, and add collision tests.
I guess the only concern here would be if an agent accidentally decided to overwrite service.name, that would be possible because with_attributes comes after with_service_name. meh ¯_(ツ)_/¯
Summary
Extract common OpenTelemetry provider construction into openshell-otel so OpenShell services share one OTLP/gRPC export implementation.
Related Issue
Refs #2507
Changes
The shared crate owns:
Migrate the gateway to the shared provider while retaining its configurable service name, error marking, and tracing test collector. Add the shared crate to the architecture inventory and document the tracing boundary.
Testing
mise run pre-commitpassesChecklist