Skip to content

feat(supervisor): relay agent OTLP logs and metrics - #5858

Open
ericcurtin wants to merge 3 commits into
ai-openshell:mainfrom
ericcurtin:feat/5562-relay-logs-metrics/ericcurtin
Open

ericcurtin wants to merge 3 commits into
ai-openshell:mainfrom
ericcurtin:feat/5562-relay-logs-metrics/ericcurtin

Conversation

@ericcurtin

Copy link
Copy Markdown
Contributor

Summary

The agent relay now forwards OTLP logs and metrics to the agent collector, not just traces.

Related Issue

Closes #5562

Changes

  • Forward /v1/logs and /v1/metrics with the same sandbox id attribution as traces.
  • One buffer per signal, so a chatty signal can't crowd out the others.
  • Count exported, rejected and failed batches per signal in the summary log.
  • Update docs.

Release Notes

The agent relay forwards logs and metrics as well as traces.

Testing

  • Checks appropriate to the affected code and behavior pass
  • Unit tests added/updated (if applicable)
  • E2E tests added/updated (if applicable)

cargo fmt, cargo clippy -p openshell-supervisor --all-targets and cargo test -p openshell-supervisor --lib pass.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

Closes ai-openshell#5562

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin

Copy link
Copy Markdown
Contributor Author

@rhuss @TaylorMutch PTAL when you get a chance, and /ok to test 83e815e06c872751a72fbe69d98a8f33910cb20c if it looks good. Thank you!

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin

Copy link
Copy Markdown
Contributor Author

@rhuss @alangou PTAL when you get a chance, and /ok to test 0684adedddee955014e64aef4009a1fcd3049995 if it looks good. Thank you!

@rhuss rhuss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cc-review Summary

What Went Well

  • Signal (crates/openshell-supervisor/src/otlp_relay/mod.rs:41-80) owns the HTTP path, the gRPC service name and the array index in one enum, so receiver routing, buffers, counters and exporter URIs cannot drift apart, and arrays sized by Signal::ALL.len() make a new signal a compile error at every site that must handle it.
  • RelayCounters::discard_pending (mod.rs:255-264) replaces four copies of the pending-to-failure accounting in Drop and shutdown with one helper that charges each lost batch to its own signal.
  • handle_request (receiver.rs:184-193) sends logs and metrics through the same content-type, body-size, body-timeout and structural-limit checks as traces, and the old drain-and-acknowledge path is gone without leaving dead helpers or counters behind.
  • The enrichment.rs module doc (lines 6-10) and the PassthroughCodec doc (exporter.rs:264-267) explain why the bounded wire-level walk and the trace response decoder also fit logs and metrics (the shared field-1 layout), so the agent payload is still never fully decoded.
  • new_buffer (buffer.rs:77-96) gives each signal its own bounded, non-blocking queue, so a full logs or metrics queue answers 503 for that signal only and total buffered memory keeps a fixed ceiling.
  • logs_and_metrics_reach_a_grpc_collector_with_attribution (mod.rs:910-965) and logs_and_metrics_are_enriched_and_buffered (receiver.rs:671-717) spoof openshell.sandbox.id and assert the replaced value with no duplicate attribution keys, against a real tonic collector and through the typed logs and metrics request types.

Findings

Severity File Description Source
Minor crates/openshell-supervisor/README.md:135 The limits paragraph of this README section (line 137) still says 32 buffered batches and about... production
Important crates/openshell-supervisor/src/otlp_relay/buffer.rs:66 BatchReceiver::recv drains the three queues with a biased select in fixed order, so logs and... correctness
Minor crates/openshell-supervisor/src/otlp_relay/buffer.rs:128 The metrics queue capacity is never asserted: a_full_signal_does_not_block_the_others fills on... test-quality
Minor crates/openshell-supervisor/src/otlp_relay/enrichment.rs:122 The EnrichError Display impl was generalized only for Malformed; the other client-visible me... architecture
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:195 record_rejection now takes the signal, but its one-time warning still logs buffer_capacity =... correctness
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:206 No test covers a collector that rejects logs or metrics while accepting traces, so the effect of... test-quality
Important crates/openshell-supervisor/src/otlp_relay/mod.rs:212 The single last_export_failed flag is now set and cleared by exports of all three signals, so... correctness
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:277 Per-signal exported counts appear only in the 'OTLP relay summary' line, which is emitted only w... goal-alignment
Minor crates/openshell-supervisor/src/otlp_relay/mod.rs:964 Per-signal counter attribution is never asserted: every counter test records Signal::Traces, a... test-quality
Important crates/openshell-supervisor/src/otlp_relay/receiver.rs:184 Forwarding agent-authored OTLP logs (and metrics) gives the sandboxed workload a credentialed wr... security
Minor crates/openshell-supervisor/src/otlp_relay/receiver.rs:184 Logs and metrics now pass through the receiver's compression refusal, but the injected workload... correctness
Important docs/how-it-works/gateways/configuration.mdx:1110 Logs and metrics that the relay used to acknowledge and drop are now forwarded to the agent coll... goal-alignment
Notable docs/how-it-works/gateways/configuration.mdx:1120 The workload environment handling stays trace-specific: the runtime forces only the generic and... goal-alignment

Review Details

I went through these findings one by one and selected the ones posted here; cc-review's reviewer agents produced them. Failure scenarios were derived from reading the code and were not executed.

  • Findings posted: 13
  • Findings reviewed and not posted: 7
  • Gate outcome: FAIL
  • Participating reviewers: architecture, correctness, goal-alignment, production, security, test-quality, gator

## OTLP agent trace relay

The `otlp_relay` module forwards the workload's OTLP/HTTP protobuf trace exports to the collector named by `OPENSHELL_OTLP_AGENT_ENDPOINT`, over the transport named by `OPENSHELL_OTLP_AGENT_PROTOCOL` (`grpc` when unset, or `http/protobuf`). Each export carries the collector headers from the launch bundle's `agent_otlp_headers` and, for an `https` collector, verifies it and authenticates with `agent_otlp_tls`; the supervisor's own span and OCSF exporters use the `traces_` and `ocsf_` fields the same way. The gateway sets those variables only when `[openshell.gateway.otlp.agent]` is enabled, so trace export alone leaves the relay inactive. Metrics and logs exports to the relay are acknowledged and discarded. The workload exports to the reserved address `192.0.0.8:4318`; the sandbox broker stages that connection to the supervisor, and the network proxy hands the stream to the relay's HTTP/1.1 receiver through the generic reserved-destination hook instead of evaluating policy. The receiver replaces the `openshell.sandbox.id` and `openshell.telemetry.source=agent` resource attributes, pushes the re-encoded batch into a bounded buffer, and a single export task forwards the encoded batches to the collector with a lazy connection.
The `otlp_relay` module forwards the workload's OTLP/HTTP protobuf trace, log, and metrics exports to the collector named by `OPENSHELL_OTLP_AGENT_ENDPOINT`, over the transport named by `OPENSHELL_OTLP_AGENT_PROTOCOL` (`grpc` when unset, or `http/protobuf`). Each export carries the collector headers from the launch bundle's `agent_otlp_headers` and, for an `https` collector, verifies it and authenticates with `agent_otlp_tls`; the supervisor's own span and OCSF exporters use the `traces_` and `ocsf_` fields the same way. The gateway sets those variables only when `[openshell.gateway.otlp.agent]` is enabled, so trace export alone leaves the relay inactive. The workload exports to the reserved address `192.0.0.8:4318`; the sandbox broker stages that connection to the supervisor, and the network proxy hands the stream to the relay's HTTP/1.1 receiver through the generic reserved-destination hook instead of evaluating policy. The receiver replaces the `openshell.sandbox.id` and `openshell.telemetry.source=agent` resource attributes, pushes the re-encoded batch into the bounded buffer of its signal, and a single export task forwards the encoded batches to the collector with a lazy connection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: The limits paragraph of this README section (line 137) still says 32 buffered batches and about 67 MiB, but the relay now buffers up to 48 batches (about 100 MiB).

Why this matters: new_buffer (buffer.rs:77-87) creates a 32-slot trace queue plus two 8-slot queues, each slot holding up to MAX_ENRICHED_BYTES (about 2.08 MiB), and the doc comment on that constant (mod.rs:87-89) already says about 100 MiB. With all three queues full behind a slow collector, each sandbox supervisor pins about 33 MiB more than README.md:137 documents, so the stated total of roughly 115 MiB is really about 148 MiB. Anyone who sizes supervisor memory from this paragraph under-provisions.

Suggested fix: Update README.md:137 to 32 trace plus 8 logs plus 8 metrics batches and about 100 MiB of buffered batches.

Source: production agent (also flagged by: architecture agent, gator agent)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a561522.

pub async fn recv(&mut self) -> Option<(Signal, Bytes)> {
let [traces, logs, metrics] = &mut self.queues;
tokio::select! {
biased;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: BatchReceiver::recv drains the three queues with a biased select in fixed order, so logs and metrics are exported only when the trace queue is empty at that moment. While traces arrive at least as fast as the collector completes exports, logs and metrics are starved completely.

Why this matters: The single export task (mod.rs:548) exports one batch per collector round trip. With a remote collector at about 200 ms per export (5 batches per second) and an agent that posts more than 5 trace batches per second (a per-span SimpleSpanProcessor, or several processes), traces.recv() is ready on every call and the logs and metrics branches are never taken. Their 8-slot queues fill, every later /v1/logs and /v1/metrics POST gets 503 (receiver.rs:325-329), the SDK retries and then drops the data, and at shutdown the 5 second flush bound is also spent on traces first. The comment at mod.rs:112-114 and the configuration docs say the separate buffers exist so that one signal cannot crowd out the others, which holds for admission but not for the drain order.

Suggested fix: Drain fairly: rotate the starting queue on each call (round robin), or drop biased; so tokio picks a random ready branch, and adjust the doc comment on ordering. If strict trace priority is intended, bound it (for example at most N consecutive trace batches while another queue is non-empty) and correct the 'cannot crowd out' statements.

Source: correctness agent (also flagged by: architecture agent, production agent, gator agent)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a561522: dropped biased, queues drain at random.

tx.try_send(Signal::Logs, Bytes::from_static(b"l")),
Err(SendError::BufferFull)
);
tx.try_send(Signal::Metrics, Bytes::from_static(b"m"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: The metrics queue capacity is never asserted: a_full_signal_does_not_block_the_others fills only the logs queue and sends a single metrics batch.

Why this matters: new_buffer (buffer.rs:80-83) sizes logs and metrics in one match arm, but this test (buffer.rs:119-133) checks the bound for logs only, and the relay-level flood test buffer_never_exceeds_capacity_under_flood (mod.rs:1515) posts traces only. Judged by inspection and not executed: splitting the arm so that Signal::Metrics => capacity (or any larger value) would not be caught by any existing test, while an agent could then keep 32 instead of 8 metrics batches of about 2 MiB each in supervisor memory. That bound is documented (configuration.mdx: logs and metrics buffer 8 each) and is part of the memory estimate for agent-controlled input in mod.rs:87-96.

Suggested fix: In the buffer test, fill the metrics queue to 8 as well and assert that the ninth send returns BufferFull; optionally flood each signal at relay level and assert 32, 8 and 8 accepted.

Source: test-quality agent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a561522.

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Malformed(error) => write!(f, "malformed ExportTraceServiceRequest: {error}"),
Self::Malformed(error) => write!(f, "malformed OTLP export request: {error}"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: The EnrichError Display impl was generalized only for Malformed; the other client-visible messages still name resource_spans, so logs and metrics exporters get an error about a field their request does not have.

Why this matters: receiver.rs:287-296 puts the Display text into the google.rpc.Status body, so a POST /v1/logs with 513 ResourceLogs entries returns HTTP 413 'more than 512 resource_spans entries' (enrichment.rs:124), and a field 1 that is not length-delimited on /v1/metrics yields 'malformed OTLP export request: resource_spans is not length-delimited' (line 177). Trace-schema names are fine for internal identifiers, but these strings leave the module, and configuration.mdx:1124 promises that the message states the reason.

Suggested fix: Use signal-neutral wording such as 'more than 512 resource entries' and 'resource entry is not length-delimited', or pass the Signal into enrich and name the matching field.

Source: architecture agent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a561522.

pub fn record_rejection(&self) {
self.rejected.fetch_add(1, Ordering::Relaxed);
pub fn record_rejection(&self, signal: Signal) {
self.counts(signal).rejected.fetch_add(1, Ordering::Relaxed);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: record_rejection now takes the signal, but its one-time warning still logs buffer_capacity = BUFFER_CAPACITY (32) and no signal, which is wrong when the full queue is the 8-slot logs or metrics queue. The shared first-occurrence latches also hide which signal is affected.

Why this matters: When an agent posts 9 logs batches behind a slow collector, the ninth gets 503 because the logs queue holds BUFFER_CAPACITY.div_ceil(4) = 8 batches (buffer.rs:82), yet the warning reports buffer_capacity=32 and sends the operator to look at trace volume while the trace queue is empty. Because first_rejection_logged and first_failure_logged are shared across signals, a later first rejection or export failure of another signal (for example the first real trace export failure after a logs 404) produces no warning at all. These two warnings are the only immediate operator-facing signal of loss, and the 30 second summary is the only place the per-signal split appears.

Suggested fix: Add signal as a field to both warnings, log the capacity of the queue that was full (BUFFER_CAPACITY for traces, BUFFER_CAPACITY.div_ceil(4) otherwise, ideally from one helper shared with new_buffer), and keep the first-occurrence latch per signal in SignalCounts.

Source: correctness agent (also flagged by: architecture agent, production agent, gator agent)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a561522: signal and real capacity logged, latches per signal.

"spoofed attribution keys were appended to, not replaced: {:?}",
received.duplicate_resource_keys
);
assert_eq!(relay.counters.snapshot().exported, 2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: Per-signal counter attribution is never asserted: every counter test records Signal::Traces, and the new logs and metrics tests check only cross-signal totals, so a mismatch between the accept side and the export side goes unnoticed.

Why this matters: SignalCounts::pending (mod.rs:156-166) now subtracts per signal with saturation, so counts recorded on different signals no longer cancel, yet the only assertions that involve logs or metrics counters are sums (snapshot().exported == 2 here and pending() == 2 at receiver.rs:716). Judged by inspection and not executed: changing the export loop (mod.rs:550) to record_export_success(Signal::Traces) would leave pending() at 2 forever, so flush waits its full 5 s bound before every exit report and Drop reports two phantom discarded batches; swapping logs and metrics in log_summary (mod.rs:272) would mislabel the only place an operator sees per-signal counts. No current test reads a logs_* or metrics_* field, so neither change would be caught.

Suggested fix: In logs_and_metrics_reach_a_grpc_collector_with_attribution, wait for relay.counters.pending() == 0 and call relay.flush(FLUSH_TIMEOUT), asserting that it returns promptly; add a gated test that buffers one batch per signal, drops the relay and asserts export_failures == 3 and pending() == 0; and record one event per signal on a bare RelayCounters, emit the summary under LogCapture and assert logs_exported, metrics_rejected and the other per-signal fields.

Source: test-quality agent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a561522.

.expect("static response builds"));
}
if request.method() != Method::POST || request.uri().path() != "/v1/traces" {
let Some(signal) = (request.method() == Method::POST)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: Forwarding agent-authored OTLP logs (and metrics) gives the sandboxed workload a credentialed write path into the collector that by default also receives supervisor and gateway OCSF audit logs, and a forged record can match every documented marker of a genuine OCSF event except one deny-list resource attribute.

Why this matters: With [openshell.gateway.otlp] endpoint set and [otlp.ocsf] and [otlp.agent] enabled without their own endpoints, RawCollector::resolve (crates/openshell-server/src/config_file.rs:1048-1062, 1103-1118) gives both the same endpoint, headers and TLS client identity. The workload can then POST to http://192.0.0.8:4318/v1/logs a request with scope openshell.ocsf, the record attributes ocsf.class_uid, ocsf.activity_id, ocsf.metadata.uid and openshell.sandbox.id=<another sandbox>, and an OCSF JSON body (a fake network activity or detection finding); enrich_resource_spans rewrites only openshell.sandbox.id and openshell.telemetry.source on the resource (enrichment.rs:312-320) and copies scopes and records byte for byte (enrichment.rs:332-337). A SIEM pipeline built on the documented OCSF Log Export contract ingests the forgery as an audit event, possibly attributed to another sandbox, and since infrastructure resources carry no positive openshell.telemetry.source value, pipelines written before this change fail open; in backends that keep only service.name and service.instance.id, agent-sent openshell_server_* metric series can likewise collide with the gateway's.

Suggested fix: Stamp supervisor and gateway resources with a positive openshell.telemetry.source value (for example in supervisor_resource_attributes, crates/openshell-supervisor/src/main.rs:854) so consumers can allow-list it; the relay already overwrites that key, so the agent cannot forge it. In the OCSF Log Export and relay sections of docs/how-it-works/gateways/configuration.mdx, state that agent logs and metrics reach the same collector when the endpoints coincide and must be dropped from audit pipelines by that attribute, or recommend a dedicated [otlp.agent] endpoint when OCSF export is on.

Source: security agent (also flagged by: gator agent)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Docs only in a561522: agent logs share the collector, drop source=agent from audit pipelines or use a dedicated agent endpoint. Stamping infra resources would change the OCSF export contract, left out of scope.

.expect("static response builds"));
}
if request.method() != Method::POST || request.uri().path() != "/v1/traces" {
let Some(signal) = (request.method() == Method::POST)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: Logs and metrics now pass through the receiver's compression refusal, but the injected workload defaults still pin only the generic and the traces-specific compression variable to none, so a signal-specific gzip setting for logs or metrics makes every such export fail with 415.

Why this matters: crates/openshell-sandbox/src/child_env.rs:66-73 injects OTEL_EXPORTER_OTLP_COMPRESSION=none and OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=none, with a comment that a gzip value from the image or the creation request would otherwise make every export fail because SDKs prefer the signal-specific variable. If the image ENV or the creation request sets OTEL_EXPORTER_OTLP_METRICS_COMPRESSION=gzip or OTEL_EXPORTER_OTLP_LOGS_COMPRESSION=gzip, the relay answers 415 'compression is not supported' to every metrics or logs export while traces from the same workload are relayed. The existing code already guards this case for traces, and the docs now say an SDK that exports the new signals needs no other setting.

Suggested fix: Add OTEL_EXPORTER_OTLP_LOGS_COMPRESSION=none and OTEL_EXPORTER_OTLP_METRICS_COMPRESSION=none to otlp_relay_env_vars() (and the matching constants in openshell-core sandbox_env), and list them in the configuration docs next to the traces variable.

Source: correctness agent (also flagged by: architecture agent)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a561522.

### Agent trace relay

Set `enabled = true` in `[openshell.gateway.otlp.agent]` to have each sandbox forward the workload's own traces. It defaults to `false`, so trace export alone never changes the workload environment. Traces go to the table's collector, or to the `[openshell.gateway.otlp]` collector when it has no `endpoint`, and that collector must be reachable from sandboxes. Use `protocol = "http/protobuf"` for trace backends that accept only OTLP/HTTP, and `headers` for the ones that need them. For example, MLflow accepts traces directly when each request names an experiment:
Set `enabled = true` in `[openshell.gateway.otlp.agent]` to have each sandbox forward the workload's own traces, logs, and metrics. It defaults to `false`, so trace export alone never changes the workload environment. They go to the table's collector, or to the `[openshell.gateway.otlp]` collector when it has no `endpoint`, and that collector must be reachable from sandboxes. Use `protocol = "http/protobuf"` for trace backends that accept only OTLP/HTTP, and `headers` for the ones that need them. For example, MLflow accepts traces directly when each request names an experiment:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: Logs and metrics that the relay used to acknowledge and drop are now forwarded to the agent collector with no opt-out, but neither the PR description nor the docs say that the collector must accept all three signals, and this section keeps a trace-only backend (MLflow) as the example.

Why this matters: A deployment that points [openshell.gateway.otlp.agent] at a backend serving only /v1/traces, as the MLflow example here and in docs/observability/overview.mdx:55-65 presents it, got a silent 200 for SDK logs and metrics before; after the upgrade every such batch is forwarded and fails (receiver.rs:184-193, exporter.rs:246-250, mod.rs:206-219). The result is one warning, an 'OTLP relay summary' line every 30 seconds while the failure count grows, and errors on the collector, in every sandbox, with no gateway setting to turn it off. Operators who enabled the relay for traces get new failures without a documented cause or remedy, and the release note only says that the relay forwards logs and metrics.

Suggested fix: State in this section that the agent collector must accept traces, logs and metrics, that a trace-only backend needs the agent to switch the other exporters off (for example OTEL_LOGS_EXPORTER=none and OTEL_METRICS_EXPORTER=none), adjust the wording around the MLflow example, and name the upgrade effect in the release notes.

Source: goal-alignment agent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Docs in a561522: collector must accept all three signals, use OTEL_LOGS_EXPORTER=none and OTEL_METRICS_EXPORTER=none for trace-only backends. No new gateway option, to keep it small.

```

While the relay is active, the sandbox runtime sets `OTEL_EXPORTER_OTLP_ENDPOINT=http://192.0.0.8:4318` and `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf` in every workload process, and sets `OTEL_EXPORTER_OTLP_COMPRESSION` and `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` to `none`, so a standard OpenTelemetry SDK exports without configuration. These are lowest-precedence defaults. They are not set when the sandbox creation request or an environment passed to `openshell sandbox exec` names `OTEL_EXPORTER_OTLP_ENDPOINT` or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, or when the image `ENV` names one for the main process, since `openshell sandbox exec` sessions do not inherit the image environment, and an endpoint the workload sets itself, for example with a shell `export`, takes precedence over them. A workload that exports elsewhere does so subject to the sandbox's network policy, and its traces carry no relay attribution. Provider credentials cannot redirect traces. While the relay is off, nothing is injected. Because the generic endpoint is set, an SDK that also exports metrics or logs sends them to the relay, which answers with an empty OTLP success and discards them. To keep metrics and logs, point those exporters elsewhere with `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` and `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`. The address is a reserved label rather than a network destination: the supervisor serves it inside the sandbox boundary and forwards accepted batches to the collector over the configured `protocol`. The collector's address is never visible inside the sandbox.
While the relay is active, the sandbox runtime sets `OTEL_EXPORTER_OTLP_ENDPOINT=http://192.0.0.8:4318` and `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf` in every workload process, and sets `OTEL_EXPORTER_OTLP_COMPRESSION` and `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` to `none`, so a standard OpenTelemetry SDK exports without configuration. These are lowest-precedence defaults. They are not set when the sandbox creation request or an environment passed to `openshell sandbox exec` names `OTEL_EXPORTER_OTLP_ENDPOINT` or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`, or when the image `ENV` names one for the main process, since `openshell sandbox exec` sessions do not inherit the image environment, and an endpoint the workload sets itself, for example with a shell `export`, takes precedence over them. A workload that exports elsewhere does so subject to the sandbox's network policy, and its traces carry no relay attribution. Provider credentials cannot redirect traces. While the relay is off, nothing is injected. The relay forwards logs and metrics too, so an SDK that exports them, for example with `OTEL_LOGS_EXPORTER=otlp` and `OTEL_METRICS_EXPORTER=otlp`, needs no other setting. The address is a reserved label rather than a network destination: the supervisor serves it inside the sandbox boundary and forwards accepted batches to the collector over the configured `protocol`. The collector's address is never visible inside the sandbox.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Notable: The workload environment handling stays trace-specific: the runtime forces only the generic and the traces compression variable to none and strips only a provider-set traces endpoint, so logs and metrics do not get the protection traces get, although the docs now say they need no other setting.

Why this matters: (a) otlp_relay_env_vars (crates/openshell-sandbox/src/child_env.rs:66-73) overrides only OTEL_EXPORTER_OTLP_COMPRESSION and OTEL_EXPORTER_OTLP_TRACES_COMPRESSION, so a gzip setting for logs or metrics leads to 415 (receiver.rs:204-210), logged at debug level and not counted, where the same export got 200 before this PR. (b) apply_otlp_relay_env (child_env.rs:135) removes only OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, so a provider-supplied OTEL_EXPORTER_OTLP_LOGS_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT still sends those signals past the relay and its attribution, while this paragraph says 'Provider credentials cannot redirect traces'. This is a design note for a follow-up rather than a defect in the changed lines, since the issue asks that logs and metrics are forwarded like traces with no agent-side change.

Suggested fix: Extend the compression defaults and the provider-endpoint removal to the logs and metrics variables, or document these limits here.

Source: goal-alignment agent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Compression fixed in a561522. Provider logs/metrics endpoint stripping is documented as a limit and left as a follow-up, since it changes when the defaults apply.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin

Copy link
Copy Markdown
Contributor Author

@rhuss @matthewgrossman Addressed the review in a561522. PTAL when you get a chance, and /ok to test a561522894b6514a0f6ed9332fe7707b5d0132cf if it looks good. Thank you!

This branch has not been deployed

No deployments
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.

feat(observability): relay agent OTLP logs and metrics from the sandbox

2 participants