-
Notifications
You must be signed in to change notification settings - Fork 1k
add spring starter span logging #14594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
laurit
merged 8 commits into
open-telemetry:main
from
zeitlinger:spring-starter-logging-exporter
Oct 9, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0ca51cc
add spring starter span logging
zeitlinger dc7442e
./gradlew spotlessApply
otelbot[bot] 17c57ed
test
zeitlinger 5a315c3
fix
zeitlinger 391b7a9
Merge branch 'main' into spring-starter-logging-exporter
zeitlinger 740b260
add metadata
zeitlinger d62556d
Merge branch 'main' into spring-starter-logging-exporter
zeitlinger cf0430d
add test
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...ring/autoconfigure/internal/instrumentation/logging/LoggingExporterAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumentation.logging; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import io.opentelemetry.exporter.logging.LoggingSpanExporter; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.SdkEnabled; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; | ||
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
@Conditional(SdkEnabled.class) | ||
// to match "otel.javaagent.debug" system property | ||
@ConditionalOnProperty(name = "otel.spring-starter.debug", havingValue = "true") | ||
@ConditionalOnClass(LoggingSpanExporter.class) | ||
@Configuration | ||
public class LoggingExporterAutoConfiguration { | ||
|
||
@Bean | ||
public AutoConfigurationCustomizerProvider loggingOtelCustomizer() { | ||
return p -> | ||
p.addTracerProviderCustomizer( | ||
(builder, config) -> { | ||
enableLoggingExporter(builder, config); | ||
return builder; | ||
}); | ||
} | ||
|
||
public static void enableLoggingExporter( | ||
SdkTracerProviderBuilder builder, ConfigProperties config) { | ||
// don't install another instance if the user has already explicitly requested it. | ||
if (loggingExporterIsNotAlreadyConfigured(config)) { | ||
builder.addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())); | ||
} | ||
} | ||
|
||
private static boolean loggingExporterIsNotAlreadyConfigured(ConfigProperties config) { | ||
return !config.getList("otel.traces.exporter", emptyList()).contains("logging"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../autoconfigure/internal/instrumentation/logging/LoggingExporterAutoConfigurationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumentation.logging; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; | ||
import java.util.Collections; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
class LoggingExporterAutoConfigurationTest { | ||
private final ApplicationContextRunner runner = | ||
new ApplicationContextRunner() | ||
.withBean( | ||
ConfigProperties.class, | ||
() -> DefaultConfigProperties.createFromMap(Collections.emptyMap())) | ||
.withConfiguration( | ||
AutoConfigurations.of( | ||
LoggingExporterAutoConfiguration.class, OpenTelemetryAutoConfiguration.class)); | ||
|
||
@Test | ||
void debugEnabled() { | ||
runner | ||
.withPropertyValues("otel.spring-starter.debug=true", "otel.traces.exporter=none") | ||
.run( | ||
context -> | ||
assertThat(context.getBean(OpenTelemetry.class).toString()) | ||
.containsOnlyOnce("LoggingSpanExporter")); | ||
} | ||
|
||
@Test | ||
void alreadyAdded() { | ||
runner | ||
.withPropertyValues("otel.spring-starter.debug=true", "otel.traces.exporter=logging") | ||
.run( | ||
context -> | ||
assertThat(context.getBean(OpenTelemetry.class).toString()) | ||
.containsOnlyOnce("LoggingSpanExporter")); | ||
} | ||
|
||
@Test | ||
void debugUnset() { | ||
runner.run( | ||
context -> | ||
assertThat(context.getBean(OpenTelemetry.class).toString()) | ||
.doesNotContain("LoggingSpanExporter")); | ||
} | ||
|
||
@Test | ||
void debugDisabled() { | ||
runner | ||
.withPropertyValues("otel.spring-starter.debug=false", "otel.traces.exporter=none") | ||
.run( | ||
context -> | ||
assertThat(context.getBean(OpenTelemetry.class).toString()) | ||
.doesNotContain("LoggingSpanExporter")); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be documented in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point - also added the missing entry for #14449