Skip to content

feat(observability)!: export OTLP traces to a local file - #1042

Merged
rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
SandyChapman:feat/otlp-file-exporter
Sep 29, 2026
Merged

rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
SandyChapman:feat/otlp-file-exporter

Conversation

@SandyChapman

@SandyChapman SandyChapman commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Breaking Rust API Change
The Rust API for manual configuration of OTel Endpoints has changed to include a common
shared struct (also in use by the new OTel File Sink). Those relying just on the
Observability 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 same ExportTraceServiceRequest an 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.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

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 own models.py:

if self.enabled and not self.endpoints:
    raise ValueError("enabled NeMo Relay OpenTelemetry requires at least one endpoint")

Checked against nemo-fabric 0.3.0b1:

  • Multiple endpoints already work and need nothing from anyone.
  • A file sink alongside at least one endpoint works with this PR alone: the model sets extra="allow", so file_sinks survives serialization and reaches Relay untouched.
  • A file sink as the only destination — the configuration an eval actually wants — is rejected by Fabric before Relay sees the config.

Fabric needs file_sinks on the model and the validator relaxed to accept a file sink as a destination, which is the same shape as the validate_opentelemetry_section change in the second commit here.

Details

Two config types, not one. OpenTelemetryConfig keeps its endpoint-only shape and OpenTelemetryFileSinkConfig is its own type, matching the split the bindings already expose. The options both carry live in a private SharedTraceOptions, with a macro generating identical builders on each, so with_service_name means 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::export returns impl 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_scope and the SpanData → protobuf From impls come from opentelemetry-proto, the crate opentelemetry-otlp already uses to build its wire payload. That crate and prost become direct dependencies of nemo-relay with the trace and with-serde features; both were already resolved in Cargo.lock, so the only new lock entry is tempfile, a dev dependency of the Python crate's tests.

A file-sink-only section is not empty. opentelemetry_section_is_empty decides whether the automatic, environment-configured exporter replaces the configured one. Until it counted file_sinks, a host with OTEL_EXPORTER_OTLP_ENDPOINT set 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 the file_sinks slot 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 edit lists file sinks beside trace endpoints; Python, Node, Go, and the FFI each gain the destination, and every binding trims output_directory before 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. Then crates/core/tests/unit/observability/otel_file_tests.rs: the round-trips decode with prost and serde_json directly 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_hex is the OTLP/JSON conformance check.

file_sinks_register_even_when_the_environment_configures_automatic_signals and delivery_identity_sanitizes_endpoints_and_preserves_file_paths cover the two behaviours most likely to regress.

The design decision worth arguing about is file_sinks as a separate array versus a transport = "file" variant on endpoints. I chose the former because endpoint is 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-targets and cargo fmt --all clean; uv run pre-commit run clean.
  • Node: 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.
  • Python: pytest python/tests/test_types.py — 63/63, ruff and ty clean.
  • Go: go test on otel_test.go passes; gofmt and go vet clean.
  • Not run locally: cargo deny (not installed), and three Go plugin-host tests that need just build-test-plugin-fixtures.

Coverage gates. codecov/patch passes at 92.73%. Rust Runtime and Dynamic Plugin SDKs fail, and both fail identically on the base commit 0be6ecf3 with this branch absent — Dynamic Plugin SDKs matches it to the decimal and covers paths this change does not touch, and on Rust Runtime this branch is slightly above the base. They should clear when main's own coverage recovers.

Breaking changes

None. file_sinks defaults to empty and every existing configuration behaves identically.

Related Issues:

Relates to #1089

Summary by CodeRabbit

  • New Features
    • Export OpenTelemetry traces to local files in JSON Lines or protobuf format, with append or overwrite options.
    • Configure file destinations alongside network endpoints, including span projection, resource metadata, and batching.
    • File sinks can serve as the sole trace destination, and generated filenames use the selected format.
    • File-sink configuration and subscriber APIs are available in the Rust, Node.js, Python, and Go interfaces.
  • Documentation
    • Added guidance on configuring file sinks, supported formats, output settings, and file access behavior.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

OpenTelemetry 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.

Changes

OTLP file-sink support

Layer / File(s) Summary
Core exporter and destination configuration
crates/core/src/observability/otel_file.rs, crates/core/src/observability/otel.rs, crates/core/src/observability/mod.rs, crates/core/Cargo.toml, crates/core/tests/unit/observability/*
The core adds file export in JSON Lines and length-delimited protobuf formats. It adds shared trace options and file-sink subscriber construction. Tests cover encoding, lifecycle, file handling, and errors.
Plugin configuration and registration
crates/core/src/observability/plugin_component.rs, crates/core/tests/unit/observability/plugin_component_tests.rs, docs/configure-plugins/observability/opentelemetry.mdx
The plugin accepts file sinks, validates settings and duplicate paths, and adds file destinations to trace fan-out. The editor schema, tests, and documentation cover sink options and behavior.
FFI and Go bindings
crates/ffi/nemo_relay.h, crates/ffi/src/api/observability.rs, crates/ffi/tests/unit/api/coverage_sweeps_tests.rs, go/nemo_relay/*.go
The C FFI and Go APIs expose file-sink subscriber creation and configuration. Tests cover output creation, defaults, and invalid arguments.
Node.js bindings
crates/node/observability.*, crates/node/src/api/mod.rs, crates/node/tests/observability_plugin_tests.mjs
Node.js adds file-sink types, a configuration factory, and subscriber construction. Tests cover normalization, validation, and file-only plugin configuration.
Python bindings
crates/python/src/py_types/*, crates/python/tests/coverage/py_types_coverage_tests.rs, python/nemo_relay/*, python/tests/test_types.py, crates/python/Cargo.toml
Python adds file-sink configuration and subscriber construction, exports the new type, and tests output creation and invalid settings.

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
Loading

Merge Risk: 🔵 Low · up to e6850

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:

  • Two direct subscribers with different formats on one file produce a mixed file.
  • Direct Rust callers that pass unusual paths can create directories outside the output directory.
  • Validation may differ slightly between bindings.
  • Some tests are weak.

The change is mergeable, with follow-up on these items.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 67.54% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 228 functions across 24 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title follows Conventional Commits format, uses the allowed lowercase type and scope, states the main change, and is 55 characters without a trailing period.
Description check ✅ Passed The description includes the required Overview, Details, reviewer guidance, and Related Issues sections. It also provides testing results, breaking-change status, design context, and required checklis…
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch feat/otlp-file-exporter
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size:XL PR is extra large Feature a new feature lang:go PR changes/introduces Go code lang:js PR changes/introduces Javascript/Typescript code lang:python PR changes/introduces Python code lang:rust PR changes/introduces Rust code labels Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

License Diff

Compared against origin/main.

Lockfile license changes

Lockfile License Changes

Rust

Added

  • None

Removed

  • None

Updated/Changed

  • None

Node

Added

  • None

Removed

  • None

Updated/Changed

  • None

Python

Added

  • None

Removed

  • None

Updated/Changed

langchain-nvidia-ai-endpoints

Before:

  • langchain-nvidia-ai-endpoints 1.4.3 (MIT)

After:

  • langchain-nvidia-ai-endpoints 1.4.1 (MIT)
Status output
[license-diff] selected languages: rust, node, python
[license-diff] generating current inventory
[license-diff] current: generating Rust inventory
[license-diff] current: Rust inventory complete (469 packages)
[license-diff] current: generating Node inventory
[license-diff] current: Node inventory complete (424 packages)
[license-diff] current: generating Python inventory
[license-diff] current: Python inventory complete (115 packages)
[license-diff] current inventory complete
[license-diff] checking out base ref origin/main into a temporary worktree
[license-diff] base: generating Rust inventory
[license-diff] base: Rust inventory complete (469 packages)
[license-diff] base: generating Node inventory
[license-diff] base: Node inventory complete (424 packages)
[license-diff] base: generating Python inventory
[license-diff] base: Python inventory complete (115 packages)
[license-diff] base inventory complete
[license-diff] removing temporary base worktree
[license-diff] comparing inventories
[license-diff] rendering Markdown output
[license-diff] done

@github-actions

Copy link
Copy Markdown

@willkill07 willkill07 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/core/src/observability/otel.rs Resolved
Comment thread crates/core/src/observability/otel.rs Resolved
Comment thread crates/core/src/observability/otel.rs Resolved

@willkill07 willkill07 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving a round of comments

Comment thread crates/core/src/observability/otel.rs Resolved
@SandyChapman
SandyChapman force-pushed the feat/otlp-file-exporter branch 2 times, most recently from 62b3d11 to f5c5a29 Compare September 23, 2026 20:01
@bniladridas

Copy link
Copy Markdown

Verified locally on Apple Silicon (arm64, CPU-only) at f5c5a29:

  • Rust: cargo check -p nemo-relay --tests clean; 34/34 observability::otel_file tests and 45/45 file_sink-filtered lib tests pass.
  • Go: 7/7 file-sink tests pass against a locally built debug FFI library (cgo).
  • Python: 13/13 file-sink tests pass against a locally built pyo3 extension, including the resourceSpans field check and the proto framing check.
  • cargo fmt --check and cargo clippy -p nemo-relay --all-targets -- -D warnings: clean.
  • The implementation matches the [Enhancement]: Export OTLP traces to a local file #1089 design: file_sinks array beside traces, shared projection and batch knobs, no network-only fields, json_lines default plus proto, same-path rejection at activation, flush plus sync before a batch is reported delivered, owner-only files confined to output_directory.

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 file_sinks (currently held structurally by skip_serializing_if), and the docs section does not state the rotation and size non-goals. The only visible CI issue is the Codecov Dynamic Plugin SDKs gate at 94.33% against 95%.

@willkill07 willkill07 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need configuration alignment/consistency:

  • compared to ATOF file export
  • for all language bindings

Comment thread crates/core/src/observability/otel.rs Resolved
Comment thread python/nemo_relay/_native.pyi Resolved
Comment thread go/nemo_relay/nemo_relay.go Resolved
Comment thread crates/node/src/api/mod.rs Resolved
Comment thread crates/ffi/src/api/observability.rs Resolved
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]>
@willkill07 willkill07 self-assigned this Sep 28, 2026
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]>
@willkill07

Copy link
Copy Markdown
Member

`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]>
@willkill07

Copy link
Copy Markdown
Member

/merge

@rapids-bot
rapids-bot Bot merged commit 7bbcbf1 into NVIDIA:main Sep 29, 2026
97 checks passed
@willkill07 willkill07 changed the title feat(observability): export OTLP traces to a local file feat(observability)!: export OTLP traces to a local file Sep 29, 2026
@github-actions github-actions Bot added the breaking PR introduces a breaking change label Sep 29, 2026

This branch was previously deployed

1 inactive deployment
fern — d8046fe5 Deployed Sep 29, 2026 by rapids-bot[bot] via Clean up docs preview #5152
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking PR introduces a breaking change Feature a new feature lang:go PR changes/introduces Go code lang:js PR changes/introduces Javascript/Typescript code lang:python PR changes/introduces Python code lang:rust PR changes/introduces Rust code size:XXL PR is very large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants