Skip to content

Support output_stream in declarative config of otlp_file/development - #8676

Open
robintra wants to merge 2 commits into
open-telemetry:mainfrom
robintra:declarative-config-output-stream
Open

Support output_stream in declarative config of otlp_file/development#8676
robintra wants to merge 2 commits into
open-telemetry:mainfrom
robintra:declarative-config-output-stream

Conversation

@robintra

Copy link
Copy Markdown

Fixes #8675.

The OTLP file exporter builders already accept an arbitrary OutputStream and the generated config model already carries output_stream, but the declarative configuration component providers never read it so only stdout was reachable without writing code. The support table in opentelemetry-configuration reports Java as not_implemented for this option, while C++ and PHP report supported.

This wires the option through for spans, metrics and logs:

  • stdout sets System.out explicitly, rather than relying on the default installed by the static builder() factory. Matching is case-insensitive, like the sibling options parsed in the same create() call.
  • A file URI is resolved through java.net.URI, so both file:///path and the authority-less file:/path are accepted, with any scheme casing. Missing parent directories are created, the file is opened with CREATE + APPEND and the stream is wrapped in a BufferedOutputStream. StreamJsonWriter flushes after every record so buffering does not delay output.
  • Anything else fails with a ConfigurationException, distinguishing an unusable value from a file that could not be opened.

Two choices worth confirming:

  • Append rather than truncate follows the "Streaming appending" section of the file exporter spec, which does not state it outright.
  • Creating missing parent directories avoids taking the whole application down at startup when the directory is created by another process, but it is a behaviour the spec does not mention.

Tests are added to AbstractOtlpStdoutExporterTest so they run for all three signals: stdout, a plain file:// URI producing the expected JSON, the authority-less and upper case URI form, parent directory creation, an unrecognized value, and a path that cannot be opened.

DeclarativeConfigurationCreateTest.parseAndCreate_Examples needed one adjustment. The ExperimentalOtlpFile*_file.yaml snippets write to file:///var/log/*.jsonl, which is not writable in tests. The test already rewrites ca_file, key_file and cert_file to temp files for the same reason so output_stream is rewritten the same way.

Two limitations are left as-is, since addressing either would go beyond wiring up the option. I am happy to follow up if maintainers want them handled here:

  • Pointing several signals at the same path opens one stream per signal and StreamJsonWriter does not synchronize so concurrent writes can interleave.
  • The handle is held for the exporter's lifetime so external log rotation is not picked up.

Verification

./gradlew :exporters:logging-otlp:check and ./gradlew :sdk-extensions:declarative-config:check pass. jApiCmp reports no API change since the new class lives in an internal package so docs/apidiffs is unchanged.

Also verified end to end with a throwaway test that runs DeclarativeConfiguration.parseAndCreate on:

file_format: "1.0"
tracer_provider:
  processors:
    - simple:
        exporter:
          otlp_file/development:
            output_stream: file:///tmp/traces.jsonl

and confirms the span is written as one JSON line to the file with nothing on stdout.

@robintra
robintra requested a review from a team as a code owner July 31, 2026 16:32
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 31, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: robintra / name: robintra (b3ab6ed)

@robintra
robintra force-pushed the declarative-config-output-stream branch from b3ab6ed to 3d94c71 Compare July 31, 2026 16:38
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.48%. Comparing base (bc956bc) to head (054525a).

Files with missing lines Patch % Lines
.../logging/otlp/internal/OutputStreamConfigUtil.java 96.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8676      +/-   ##
============================================
+ Coverage     91.47%   91.48%   +0.01%     
- Complexity    10465    10471       +6     
============================================
  Files          1021     1022       +1     
  Lines         27694    27722      +28     
  Branches       3247     3251       +4     
============================================
+ Hits          25333    25362      +29     
+ Misses         1617     1615       -2     
- Partials        744      745       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 31, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-07-31 19:39 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

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.

Declarative config: output_stream is not implemented for otlp_file/development

1 participant