Skip to content

Declarative spring_starter.debug never enables span logging #19726

Description

@colamong

Describe the bug

In declarative configuration mode, instrumentation/development/java/spring_starter/debug never
takes effect, so span logging cannot be enabled at all on that path.

Two things combine:

  1. DeclarativeConfigLoggingExporterAutoConfiguration is missing from both auto-configuration
    registration files (AutoConfiguration.imports and spring.factories), so Spring Boot never
    discovers it and its DeclarativeConfigurationCustomizerProvider bean is never created. This is
    the same omission as Register LoggingExporterAutoConfiguration so otel.spring-starter.debug works #19725, which fixes the properties-mode counterpart.

  2. Registering it is not sufficient. SpanLoggingCustomizerProvider.isEnabled reads the flag via
    the upstream SdkConfigProvider:

    return SdkConfigProvider.create(DeclarativeConfiguration.toConfigProperties(model))
        .getInstrumentationConfig("spring_starter")
        .getBoolean("debug", false);

    In the Spring starter, EmbeddedConfigFile builds the declarative model from
    Map<String, String>, so every scalar arrives as a String. getBoolean("debug", false)
    does not coerce, and returns false for a configured debug: true.

    That is exactly why this module already carries SpringConfigProvider and
    SpringDeclarativeConfigProperties, whose Javadoc says it "tries to coerce types, because
    spring doesn't tell what the original type was"
    — but isEnabled does not go through them.

Observed while working on #19725: with the class registered, the provider bean is created and
consumed, but the exporter is still not installed. Reading the same key directly shows
getString("debug")"true" while getBoolean("debug", false)false.

Steps to reproduce

Use the Spring Boot starter with declarative configuration and set
instrumentation/development/java/spring_starter/debug: true. No LoggingSpanExporter is
installed and no spans are printed.

Expected behavior

Enabling the declarative spring_starter.debug flag installs the logging span exporter, matching
the behaviour of otel.spring-starter.debug in properties mode.

Actual behavior

The flag is ignored. Even with the auto-configuration registered, isEnabled evaluates to false
because the configured value is a String and getBoolean does not coerce it.

Javaagent or library instrumentation version

main (verified at 4225fbe)

Environment

JDK 21, Spring Boot 3.2.4 / 2.6.15

Additional context

There seem to be at least three ways to fix this, and I did not want to pick one without
maintainer input, which is why #19725 deliberately leaves the declarative class out:

  1. Have isEnabled read through the Spring-aware coercing provider
    (SpringConfigProvider / SpringDeclarativeConfigProperties) instead of SdkConfigProvider.
  2. Preserve scalar types in EmbeddedConfigFile instead of flattening everything to String.
  3. Make the upstream getBoolean coerce string values — SpringDeclarativeConfigProperties has a
    TODO pointing at DeclarativeConfigProperties: no way to coerce types without triggering warnings opentelemetry-java#8101, which looks related.

Whichever direction is preferred, the registration entries for
DeclarativeConfigLoggingExporterAutoConfiguration need to be added as part of it. Happy to
send a PR once the direction is settled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions