Skip to content

feat(append-opentelemetry): add OpentelemetryLog::from_provider and scope configuration - #316

Open
tisonkun wants to merge 1 commit into
mainfrom
feat/otel-from-provider
Open

tisonkun wants to merge 1 commit into
mainfrom
feat/otel-from-provider

Conversation

@tisonkun

@tisonkun tisonkun commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

OpentelemetryLogBuilder currently creates a dedicated SdkLoggerProvider (with_batch_exporter), allows setting only the InstrumentationScope name string, and unconditionally calls SdkLoggerProvider::shutdown inside OpentelemetryLog::drop. That prevents callers from sharing one SdkLoggerProvider (with custom Resource attributes or custom LogProcessor pipelines) across multiple Logger channels with distinct InstrumentationScope metadata, and causes dropping one channel to shut down the shared provider while sibling channels are still active.

This PR decouples provider ownership from OpentelemetryLog while keeping OpentelemetryLogBuilder ergonomic for single-pipeline setups:

  • Add OpentelemetryLog::from_provider(provider: SdkLoggerProvider, scope: InstrumentationScope) -> Self and OpentelemetryLog::with_make_body so multiple appenders can share a caller-configured SdkLoggerProvider under distinct InstrumentationScope descriptors.
  • Guard Drop for OpentelemetryLog with owned_provider: bool so builder-owned providers continue to shut down on drop while shared providers created via from_provider leave shutdown to the caller (or opentelemetry_sdk's automatic shutdown when the final provider reference drops).
  • Add OpentelemetryLogBuilder::scope(self, scope: InstrumentationScope) -> Self so single-provider builder callers can also configure full InstrumentationScope metadata (version, schema_url, attributes).

Test Plan

  • Verify multi-appender provider sharing, distinct InstrumentationScope emission, with_make_body, and Drop lifetime isolation in tests-integration/tests/append_test/opentelemetry.rs (opentelemetry_appenders_preserve_scopes_and_share_provider_lifetime).
  • Run rustdoc doctests and clippy/doc checks on logforth-append-opentelemetry.

…cope configuration

Allow constructing `OpentelemetryLog` from a caller-managed `SdkLoggerProvider` and `InstrumentationScope` via `OpentelemetryLog::from_provider` (plus `OpentelemetryLog::with_make_body`), and allow overriding the builder's full `InstrumentationScope` via `OpentelemetryLogBuilder::scope`.

Appenders constructed via `from_provider` leave provider shutdown to the caller (or `opentelemetry_sdk`'s final-reference drop) rather than calling `SdkLoggerProvider::shutdown` when an individual appender drops, so multiple logging channels can share one provider, resource, and processor pipeline with distinct scopes.

Signed-off-by: tison <wander4096@gmail.com>
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.

1 participant