Use Micrometer to send custom metrics to SolarWinds Observability SaaS
Micrometer is a JVM instrumentation library for publishing metrics and traces to popular monitoring systems. The following sections provide an example of configuring a Spring Boot application to send metrics to SolarWinds Observability SaaS's OpenTelemetry (OTel) endpoint.
For more information about Micrometer, see the following sites:
- Micrometer configuration: https://micrometer.io/docs/registry/otlp
- Micrometer OTLP 1.11 source: https://github.com/micrometer-metrics/micrometer/tree/1.11.x/implementations/micrometer-registry-otlp
- Spring Boot Metrics: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.metrics
Configure the Micrometer dependencies
Spring Boot integrates Micrometer for metric and trace publishing. Dependency management and automated metric provider configuration is built into Spring Boot 2 and later.
The following example uses Maven to configure the Micrometer dependencies.
Spring Boot will download the dependency hierarchy, but there might be a conflict in the micrometer-core library dependency. To work around this issue, you can specify the Micrometer version number.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-otlp</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>${micrometer.version}</version>
</dependency>
Configure the Spring application
To configure the Spring application, edit the application.yaml
file. As the url
, specify the endpoint where collected metrics are sent. (For more information, see Data centers and endpoint URIs.) Specify other optional properties as shown in the following example.
management:
otlp:
metrics:
export:
enabled: true
url: "otel.collector.na-01.cloud.solarwinds.com"
step: 1m
batchSize: 1000
readTimeout: 10s
connectTimeout: 1s
numThreads: 2
Specify the token used for authentication
Authentication to the SolarWinds Observability SaaS OTel endpoint requires an Authorization Bearer Token HTTP header. You can put this in an optional environment
variable. In the following example, replace <token>
with a SolarWinds Observability SaaS API token.
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <token>"
Add tags to the metrics
The following example adds the service name (order
) and application name (swopper
) as tags to the metrics. These tags will be displayed in the SolarWinds Observability SaaS interface and can be used to filter the metrics.
export OTEL_RESOURCE_ATTRIBUTES="service.name=order,application.name=swopper"
You can also configure the tags using a MetricRegistryCustomizer callback:
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class MyMeterRegistryConfiguration {
@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return (registry) -> registry.config().commonTags("region", "us-east-1");
}
}
Another MetricRegistryCustomizer callback could be used to configure the naming scheme of the metrics. The following example prepends the application name(swopper
) to make finding all published metrics easy.
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.micrometer.registry.otlp.OtlpMeterRegistry;
import io.micrometer.core.instrument.Meter;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
@Configuration(proxyBeanMethods = false)
public class MeterRegistryConfiguration {
@Bean
public MeterRegistryCustomizer<OtlpMeterRegistry> OTLPMetricsNamingConvention() {
return (registry) -> registry.config().namingConvention(this::name);
}
private String name(String name, Meter.Type type, String baseUnit) {
return "swopper." + name;
}
}
Displayed metric data
When the application starts, SolarWinds Observability SaaS displays metric data such as the following: