Repository navigation
feat(observability)!: export OTLP traces to a local file - #1042
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughOpenTelemetry trace export now supports local JSON Lines and length-delimited protobuf files. The change adds file-sink configuration to plugin and language APIs, routes spans to file exporters, and validates output settings and destination paths. ChangesOTLP file-sink support
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~60 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant TraceSubscriber
participant OtlpFileSpanExporter
participant LocalFile
TraceSubscriber->>OtlpFileSpanExporter: export span batch
OtlpFileSpanExporter->>LocalFile: encode and write JSON Lines or protobuf
OtlpFileSpanExporter->>LocalFile: flush output
Merge Risk: 🔵 Low · up to Relay can now write OpenTelemetry traces to local JSON Lines or protobuf files through configuration and every language binding. The earlier truncation and activation problems are fixed. The remaining issues are narrow edge cases:
The change is mergeable, with follow-up on these items. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
🧪 Generate unit tests (beta)
Comment |
License DiffCompared against Lockfile license changesLockfile License ChangesRustAdded
Removed
Updated/Changed
NodeAdded
Removed
Updated/Changed
PythonAdded
Removed
Updated/Changed
|
willkill07
left a comment
There was a problem hiding this comment.
I feel like this needs a proper proposal rather than instructing Claude to implement the functionality loosely based on need.
I understand this is in draft form, but it isn't conducive to any significant review time without a corresponding proposal.
Ultimately, we need a configuration shape for the new functionality without breaking existing plugin configuration files.
dad6459 to
a7621e8
Compare
willkill07
left a comment
There was a problem hiding this comment.
Just leaving a round of comments
c5991b7 to
e8dc3c1
Compare
e8dc3c1 to
b44e544
Compare
b44e544 to
921a2cd
Compare
62b3d11 to
f5c5a29
Compare
|
Verified locally on Apple Silicon (arm64, CPU-only) at
Not run: Node tests (napi build not set up here); the Node coverage is present in the diff. Two minor gaps, neither blocking: there is no explicit byte-identical round-trip regression test for configs without |
f5c5a29 to
777b9ef
Compare
willkill07
left a comment
There was a problem hiding this comment.
We need configuration alignment/consistency:
- compared to ATOF file export
- for all language bindings
Relay's OpenTelemetry plugin could only ship spans to a collector. ATIF and ATOF can both be written to a file, so OTLP was the one trajectory output that could not be kept on disk. An evaluation harness that scores the trace it just produced, an offline replay, and any environment with no collector all had to stand up an OTLP receiver purely to catch the export and write it out. `[[components.config.opentelemetry.file_sinks]]` writes the same `ExportTraceServiceRequest` an endpoint would receive. The default `json_lines` format implements the OpenTelemetry Protocol File Exporter specification, one OTLP/JSON record per line; `proto` writes the same records length-delimited for consumers that would rather not pay JSON's size and parse cost. The conversion comes from `opentelemetry-proto`, the crate `opentelemetry-otlp` already uses to build its wire payload, so a span means the same thing whichever destination it goes to. That crate and `prost` were already present as dev dependencies of `nemo-relay` and as transitive dependencies of the workspace; this promotes them to direct dependencies and adds the `trace` and `with-serde` features. Nothing new enters `Cargo.lock` except `tempfile`, a dev dependency of the Python crate's tests. The endpoint and the file sink are separate config types, matching the split the bindings already expose. Options they share live in `SharedTraceOptions`, so a file sink cannot be given an endpoint, a transport, headers, or a timeout: those are absent from the type rather than rejected at runtime. Existing configuration files are unaffected, since `file_sinks` is a new optional array that is skipped on serialization when empty. A section carrying only file sinks is not empty. Without that, an environment that sets `OTEL_EXPORTER_OTLP_ENDPOINT` let the automatic exporter displace the configured sinks and the files were never written, which is the arrangement an evaluation host is most likely to have. Delivery diagnostics report the destination each kind of exporter actually has: an endpoint is reduced to scheme, host and port so no credentials or query reach a log, while a file sink reports its path, which URL sanitization would have turned into "an invalid OTLP endpoint". A skipped sink is reported against the `file_sinks` slot the user wrote rather than its position in the fan-out. Malformed filenames and batch settings are reported during configuration validation as well as at activation, matching the endpoint path, so they surface before the plugin starts rather than only as a warning once it has. Each export is flushed and synced before it is reported as delivered, so a run that exits between batches leaves a readable prefix and an acknowledged batch survives a host that loses power. Every exporter writing one path shares one open file, so the extra pipelines that resource-metadata promotion creates add records to the sink's file rather than truncating and interleaving it. Output is created with owner-only permissions and confined to `output_directory`, matching the ATOF and ATIF sinks. Two file sinks writing one path are rejected at activation. The process-global OTLP header variables are rejected only for a network destination, since they cannot reach a file. `nemo-relay plugins edit` lists file sinks beside trace endpoints, and the Python, Node.js, Go, and C FFI surfaces each gain the destination. Every binding trims `output_directory` before use so the same string resolves to the same path. A Go coverage test built an ATOF exporter from the default config, whose file sink resolves against the working directory: under `go test` that is the package directory, so each run left a timestamped event file in the worktree. It now uses `t.TempDir()`. The shared DTO crate gains tests for its metric enum `Display` impls, validation error text, and attribute-array rejection arms. Those paths were uncovered on main and kept the Dynamic Plugin SDKs coverage gate red for every pull request. Relates to NVIDIA#1089 Signed-off-by: Sandy Chapman <[email protected]>
`OtlpFileSinkSettings` carried a full `path` alongside `output_directory`, so the same location was stored twice and the two could disagree: the fields are public, and only `from_parts` kept them consistent. The open mode was a bare `append` boolean, which reads as an unexplained `false` at every call site. It now holds `output_directory`, `filename`, and an `OtlpFileSinkMode` enum, matching `AtofFileSinkConfig`, with `path()` doing the join. The mode keeps its `overwrite` default: a run that reuses a filename should not read as one trajectory appended to another. Signed-off-by: Sandy Chapman <[email protected]>
The file-sink subscriber constructors carried only the destination and service identity, so `mark_projection`, `mark_exclude_names`, `attribute_mappings`, both metadata-promotion prefix lists, and the completed-span-context TTL could be set on an endpoint but not on a file sink. The plugin configuration already accepted all of them, so the gap was limited to the programmatic API. `nemo_relay_otel_subscriber_create_file_sink` takes the six settings and routes them through the validators the endpoint entrypoints use, so a malformed projection, mapping, or prefix is refused rather than dropped. Go, Node.js, and Python pass them through, with tests that emit a scope and assert the promoted metadata reaches the exported record. `promote_resource_metadata_prefixes` is new to the FFI here. The endpoint entrypoints still omit it, so Go can promote resource metadata to a file but not yet to a collector. Signed-off-by: Sandy Chapman <[email protected]>
…produces The binding tests set every shared option but only asserted the promoted metadata, so `mark_projection`, `mark_exclude_names`, `attribute_mappings`, and the completed-span-context TTL could be parsed and then discarded without a failure. Validating a value is not the same as applying it. Each option now has its own observable: an alias that appears only through `attribute_mappings`, a `mark:` span that appears only under the `tool` projection, and an excluded mark that must be absent. The TTL keeps its construction and rejection coverage; its effect on late marks is not reachable from a binding test. Signed-off-by: Sandy Chapman <[email protected]>
The registry keyed an open file by its lexical absolute path, so two sinks that reach one file through different symlinked directories were handed separate writers. The second opened the file again, truncating what the first had written, and the two then wrote through independent offsets. The key is now the resolved parent joined with the filename, and confinement is checked before any directory is created rather than after the registry lookup. A binding that omitted the filename also took a fixed default while the plugin path took a timestamped one, so the same configuration wrote to different files depending on how it was expressed. Both now use one `default_otlp_file_sink_filename`. Signed-off-by: Sandy Chapman <[email protected]>
777b9ef to
ac28dc1
Compare
`delivery_identity` now derives its path through `OtlpFileSinkSettings::path`, which joins with the platform separator, so the test's hardcoded `/var/log/nemo-relay/trace.jsonl` only matched on Unix. Windows produced `/var/log/nemo-relay\trace.jsonl` and the assertion failed. The expected value is built with the same join. The sibling assertions compare `Path` values, which match component-wise on either platform. Signed-off-by: Sandy Chapman <[email protected]>
`promote_resource_metadata_prefixes` reached the core from the plugin config and from the Node.js and Python bindings, which build the Rust config directly, but never from the C FFI. Go therefore could not promote root-scope metadata onto the OTLP resource for any destination. `nemo_relay_otel_subscriber_create_with_projection_options_v5` takes the prefix list; the released `..._v4` keeps its signature and forward-delegates with a null, which parses to the empty list it already used. Go's endpoint config gains the field and calls v5. The Go test asserts the promoted key appears once, since promotion moves it off the scope events onto the resource. It is the only coverage that proves the value is applied rather than parsed: the FFI test still passes if v5 validates the list and discards it. Signed-off-by: Sandy Chapman <[email protected]>
|
/merge |
Warning
Breaking Rust API Change
The Rust API for manual configuration of OTel Endpoints has changed to include a common
sharedstruct (also in use by the new OTel File Sink). Those relying just on theObservability plugin configuration are not affected.
Overview
Relay's OpenTelemetry plugin can only ship spans to a collector. ATIF and ATOF both write to disk, so a consumer that treats a trajectory as an artifact rather than as telemetry has no OTLP option at all. This adds
[[components.config.opentelemetry.file_sinks]], which writes the sameExportTraceServiceRequestan endpoint would receive to a local file.The argument for a sink here rather than a collector is that it removes a routable address and an egress rule for isolated sandboxes. Additionally, some users using Fabric+Relay for evaluation, may not have provision the infrastructure required to collect traces.
Note for reviewers: a companion change is needed in NeMo-Fabric
This change is necessary but not sufficient for the evaluation use case.
Callers that reach Relay through Fabric use
nemo_fabric.RelayOpenTelemetryConfig, which has two fields (enabled,endpoints) and a hand-written validator in its ownmodels.py:Checked against
nemo-fabric0.3.0b1:extra="allow", sofile_sinkssurvives serialization and reaches Relay untouched.Fabric needs
file_sinkson the model and the validator relaxed to accept a file sink as a destination, which is the same shape as thevalidate_opentelemetry_sectionchange in the second commit here.Details
Two config types, not one.
OpenTelemetryConfigkeeps its endpoint-only shape andOpenTelemetryFileSinkConfigis its own type, matching the split the bindings already expose. The options both carry live in a privateSharedTraceOptions, with a macro generating identical builders on each, sowith_service_namemeans the same thing wherever it is called.A file sink therefore has no
with_endpoint,with_transport,with_timeout, or header builders at all. Passing an endpoint option to one is a compile error rather than a runtime rejection, and there is no machinery to record or report the misuse.SpanExporter::exportreturnsimpl Future, so the trait is not dyn-compatible and the two exporters cannot share a boxed type. Provider construction is generic over the exporter instead, and each destination hands over its concrete one. Everything above that point — projection, id generation, batching, resource attributes, shutdown — is shared.Conversion is upstream.
group_spans_by_resource_and_scopeand theSpanData→ protobufFromimpls come fromopentelemetry-proto, the crateopentelemetry-otlpalready uses to build its wire payload. That crate andprostbecome direct dependencies ofnemo-relaywith thetraceandwith-serdefeatures; both were already resolved inCargo.lock, so the only new lock entry istempfile, a dev dependency of the Python crate's tests.A file-sink-only section is not empty.
opentelemetry_section_is_emptydecides whether the automatic, environment-configured exporter replaces the configured one. Until it countedfile_sinks, a host withOTEL_EXPORTER_OTLP_ENDPOINTset silently wrote no files — the arrangement an evaluation host is most likely to have. Covered by a test that spawns a child process with that variable set.Diagnostics name the destination each exporter has. An endpoint is reduced to scheme, host and port so no credentials or query reach a log; a file sink reports its path, which URL sanitization would otherwise render as
"an invalid OTLP endpoint". A skipped sink is reported against thefile_sinksslot the user wrote rather than its position in the fan-out.Validation parity. Malformed filenames and batch settings are reported during configuration validation as well as at activation, as the endpoint path already did, so they surface before the plugin starts rather than only as a warning once it has.
Durability and permissions. Each export is flushed before it is reported as delivered, so a run that exits between batches leaves a readable prefix. Output is created with the same owner-only permissions and directory confinement as the ATOF and ATIF sinks, because a trajectory carries prompt and response content. Two sinks writing one path are rejected at activation. The process-global OTLP header variables are rejected only for a network destination, since they cannot reach a file.
Surfaces.
nemo-relay plugins editlists file sinks beside trace endpoints; Python, Node, Go, and the FFI each gain the destination, and every binding trimsoutput_directorybefore use so one string resolves to one path.Where should the reviewer start?
crates/core/src/observability/otel_file.rs— the exporter is ~200 lines and the whole design is visible there. Thencrates/core/tests/unit/observability/otel_file_tests.rs: the round-trips decode withprostandserde_jsondirectly rather than through this module's own encoder, so a writer and reader that agree only with each other cannot pass.json_lines_encode_span_identifiers_as_hexis the OTLP/JSON conformance check.file_sinks_register_even_when_the_environment_configures_automatic_signalsanddelivery_identity_sanitizes_endpoints_and_preserves_file_pathscover the two behaviours most likely to regress.The design decision worth arguing about is
file_sinksas a separate array versus atransport = "file"variant onendpoints. I chose the former becauseendpointis required and URL-validated, and conditional validation on a field that sometimes holds a path seemed worse than a second array.Testing
cargo test— 1762 core lib, 107 FFI, 81 Python-crate tests pass.cargo clippy --workspace --all-targetsandcargo fmt --allclean;uv run pre-commit runclean.node --test crates/node/tests/observability_plugin_tests.mjs— 10/10. One test drives a file-sink-only section through the plugin host and asserts the trace file appears.pytest python/tests/test_types.py— 63/63,ruffandtyclean.go testonotel_test.gopasses;gofmtandgo vetclean.cargo deny(not installed), and three Go plugin-host tests that needjust build-test-plugin-fixtures.Coverage gates.
codecov/patchpasses at 92.73%.Rust RuntimeandDynamic Plugin SDKsfail, and both fail identically on the base commit0be6ecf3with this branch absent —Dynamic Plugin SDKsmatches it to the decimal and covers paths this change does not touch, and onRust Runtimethis branch is slightly above the base. They should clear when main's own coverage recovers.Breaking changes
None.
file_sinksdefaults to empty and every existing configuration behaves identically.Related Issues:
Relates to #1089
Summary by CodeRabbit