Skip to content

[feature request] Support manual enabling of tracing and metrics for runtime-created InstrumentedBuilder instances #3630

@hovvsoon

Description

@hovvsoon

Component

OpenTelemetry.Instrumentation.ConfluentKafka

Is your feature request related to a problem?

When dynamically creating Kafka producers at runtime (outside of the DI container), users must use AsInstrumentedProducerBuilder() to enable OpenTelemetry instrumentation. However, the EnableTraces and EnableMetrics properties on the resulting InstrumentedProducerBuilder are marked internal, making it impossible to manually enable tracing or metrics. As a result, even with OpenTelemetry properly configured, no spans or metrics are emitted from these runtime-created producers.

What is the expected behavior?

Provide a public API to enable tracing and/or metrics on instrumented builders created at runtime. For example:

var instrumentedBuilder = producerBuilder
    .AsInstrumentedProducerBuilder()
    .WithTracing(true)
    .WithMetrics(true);

Alternatively, respect the global OpenTelemetry SDK configuration by default (e.g., if tracing is enabled globally, enable it automatically), or allow passing an InstrumentationOptions instance to AsInstrumentedProducerBuilder().

Which alternative solutions or features have you considered?

Wrapping the builder creation in a custom factory registered with DI (not feasible in pure runtime/dynamic scenarios).
Forking the instrumentation library to expose EnableTraces/EnableMetrics as public (not sustainable).
Using reflection to set internal properties (fragile and not production-safe).

Additional context

The current implementation intentionally marks EnableTraces and EnableMetrics as internal to encourage users to register producers via the DI container. However, in legitimate scenarios where producers are created dynamically at runtime, there is no public API to configure observability features, making it impossible to enable tracing or metrics. This is not a bug, but rather a design gap in supporting non-DI usage patterns.

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions