open-telemetry / open-telemetry/opentelemetry-java-instrumentation

Declarative spring_starter.debug never enables span logging

Open
#19,726 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 18h
Merged PRs (30d)
228

Description

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 #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 4225fbe18e)

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 open-telemetry/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with DeclarativeConfigLoggingExporterAutoConfiguration and compare its AutoConfiguration.imports and spring.factories registration with the properties-mode counterpart in #19725. Trace SpanLoggingCustomizerProvider.isEnabled through SdkConfigProvider, EmbeddedConfigFile, SpringConfigProvider, and SpringDeclarativeConfigProperties to confirm how the declarative debug value is read. Done means declarative spring_starter.debug: true installs LoggingSpanExporter and prints spans, with coverage for the supported configuration path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.