Search code examples
spring-bootspring-boot-actuatoropen-telemetrymicrometerspring-micrometer

How to turn on/off observability for local or test environments?


  • What I am trying to achieve:

Turn on/off observability for local or test environments.

  • What did I try:

Our project has below dependencies. With those, it generates and send metrics, traces, to some observability platform. In production, we are able to see those traces, those metrics, meaning, all dependencies are working

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-otlp</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-otlp</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-otel</artifactId>
        </dependency>
  • Issue;

However, in non prod environments, such as localhost or QA, we do not want to deal with observability, traces, metrics, at all. Therefore, what we are doing right now, is that for dev or QA, we remove the dependency entirely from the pom, meaning, we manage another pon (which has observability dependency taken out) just for non prod. If we were to leave those, by default, the dependencies will try to send to some localhost, expecting the observability platform to be in localhost, and again, in QA and local, there is no such.

  • Question:

Instead of maintaining two pom files, is there a way to deactivate sending traces and metrics entirely, maybe via some spring properties?


Solution

  • You can use the following properties to disable tracing and metrics:

    management:
      otlp:
        metrics:
          export:
            enabled: false
      tracing:
        enabled: false
    

    Spring starters, such as https://opentelemetry.io/docs/languages/java/automatic/spring-boot/ or https://github.com/grafana/grafana-opentelemetry-starter have their own properties disable properties.