-
Notifications
You must be signed in to change notification settings - Fork 867
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
Add metrics & micrometer support to spring-boot-autoconfigure #6270
Merged
trask
merged 3 commits into
open-telemetry:main
from
mateuszrzeszutek:spring-boot-autoconfigure-metrics
Jul 7, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains 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
This file contains 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
25 changes: 25 additions & 0 deletions
25
...in/java/io/opentelemetry/instrumentation/spring/autoconfigure/MetricExportProperties.java
This file contains 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,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure; | ||
|
||
import java.time.Duration; | ||
import javax.annotation.Nullable; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "otel.metric.export") | ||
public class MetricExportProperties { | ||
|
||
@Nullable private Duration interval; | ||
|
||
@Nullable | ||
public Duration getInterval() { | ||
return interval; | ||
} | ||
|
||
public void setInterval(@Nullable Duration interval) { | ||
this.interval = interval; | ||
} | ||
} |
This file contains 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
49 changes: 49 additions & 0 deletions
49
...try/instrumentation/spring/autoconfigure/exporters/logging/LoggingExporterProperties.java
This file contains 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,49 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.logging; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* Configuration for {@link io.opentelemetry.exporter.logging.LoggingSpanExporter} and {@link | ||
* io.opentelemetry.exporter.logging.LoggingMetricExporter}. | ||
*/ | ||
@ConfigurationProperties(prefix = "otel.exporter.logging") | ||
public final class LoggingExporterProperties { | ||
|
||
private boolean enabled = true; | ||
private final SignalProperties traces = new SignalProperties(); | ||
private final SignalProperties metrics = new SignalProperties(); | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public SignalProperties getTraces() { | ||
return traces; | ||
} | ||
|
||
public SignalProperties getMetrics() { | ||
return metrics; | ||
} | ||
|
||
public static class SignalProperties { | ||
|
||
private boolean enabled = true; | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...tation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfiguration.java
This file contains 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,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.logging; | ||
|
||
import io.opentelemetry.exporter.logging.LoggingMetricExporter; | ||
import io.opentelemetry.exporter.logging.LoggingSpanExporter; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** Configures {@link LoggingSpanExporter} bean for tracing. */ | ||
@Configuration | ||
@EnableConfigurationProperties(LoggingExporterProperties.class) | ||
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class) | ||
@ConditionalOnProperty( | ||
prefix = "otel.exporter.logging", | ||
name = {"enabled", "metrics.enabled"}, | ||
matchIfMissing = true) | ||
@ConditionalOnClass(LoggingMetricExporter.class) | ||
public class LoggingMetricExporterAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public LoggingMetricExporter otelLoggingMetricExporter() { | ||
return LoggingMetricExporter.create(); | ||
} | ||
} |
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
...trumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfiguration.java
This file contains 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,53 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp; | ||
|
||
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; | ||
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; | ||
import java.time.Duration; | ||
import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class) | ||
@EnableConfigurationProperties(OtlpExporterProperties.class) | ||
@ConditionalOnProperty( | ||
prefix = "otel.exporter.otlp", | ||
name = {"enabled", "metrics.enabled"}, | ||
matchIfMissing = true) | ||
@ConditionalOnClass(OtlpGrpcMetricExporter.class) | ||
public class OtlpMetricExporterAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public OtlpGrpcMetricExporter otelOtlpGrpcMetricExporter(OtlpExporterProperties properties) { | ||
OtlpGrpcMetricExporterBuilder builder = OtlpGrpcMetricExporter.builder(); | ||
|
||
String endpoint = properties.getMetrics().getEndpoint(); | ||
if (endpoint == null) { | ||
endpoint = properties.getEndpoint(); | ||
} | ||
if (endpoint != null) { | ||
builder.setEndpoint(endpoint); | ||
} | ||
|
||
Duration timeout = properties.getMetrics().getTimeout(); | ||
if (timeout == null) { | ||
timeout = properties.getTimeout(); | ||
} | ||
if (timeout != null) { | ||
builder.setTimeout(timeout); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
} |
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 we open sdk issue to add these as sdk autoconfigure properties?
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.
I don't really think so - the spring starter uses a bit different configuration scheme than the SDK (which I dislike, I think they should use exactly the same property names), and the exporters are enabled/disabled in a bit different way.
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.
I fully support changing the sprint boot configuration to match sdk configuration if that's possible