opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

Prototype disabling scope across traces, metrics, and logs

Open jack-berg opened this issue 1 year ago • 0 comments

A prototype solution for #6197.

The idea is to start to more fully realize the potential of scope as a concept. Today, scope is just a piece of metadata attached to records because there is no SDK level configuration surface area involving scopes besides views which allow you to select on scope.

This PR introduces the notion of scope level configuration for all three signals:

  • Each provider has the ability to register configuration which applies scope configuration to some selection of matching scopes.
  • When evaluating the scope config for a Tracer / Meter / Logger, use the first matching scope config.
  • Scope configs manifest as holders of configuration options relevant to the particular signal. We have TracerConfig, MeterConfig, LoggerConfig.
  • For now, each scope config type only has the ability to specify that a scope is disabled. This capability is shared across all signals, but in the future, scope config may be extended to support signal level properties. For example, its common in logging to specify a log level threshold for a particular logger. This concept is not applicable to metrics.
  • When a scope is disabled, the tracer / meter / logger uses the behavior of the relevant noop tracer / meter / logger.
  • For tracing, the noop tracer returns Span.wrap(parentContext). This means that disabling a tracer is an effective solution to the broken trace problem discussed in #6197.
OpenTelemetrySdk sdk =
    OpenTelemetrySdk.builder()
        .setTracerProvider(
            SdkTracerProvider.builder()
                .addScopeConfig(named("scopeB"), TracerConfig.disabled())
                .build())
        .setMeterProvider(
            SdkMeterProvider.builder()
                .addScopeConfig(named("scopeB"), MeterConfig.disabled())
                .build())
        .setLoggerProvider(
            SdkLoggerProvider.builder()
                .addScopeConfig(named("scopeB"), LoggerConfig.disabled())
                .build())
        .build();

jack-berg avatar Feb 06 '24 20:02 jack-berg