Add observability: real OTLP metrics/traces to grafana/otel-lgtm, Docker Compose auto-wiring, and a dual-version (Boot 4.0 vs 4.1) proof of the new OTEL_* env var support
Companion module for the rewritten ankurm.com Prometheus/Grafana monitoring post. Verified against a real running grafana/otel-lgtm container (not mocked): 8 real requests produce a real orders_placed_total metric queried back from the bundled Prometheus-compatible API with zero management.otlp.* properties, auto-wired entirely by Boot's Docker Compose service-connection detection. Two real findings surfaced along the way and documented rather than smoothed over: @Observed silently produces no span without an explicit ObservedAspect bean (AspectJ weaving alone is not sufficient, despite Micrometer Tracing being active), and OTEL_EXPORTER_OTLP_ENDPOINT already worked on Boot 4.0 via Micrometer's own OtlpConfig fallback -- what's actually new in 4.1 is the rest of the standard OTEL_* surface (verified with OTEL_METRIC_EXPORT_INTERVAL against identical source compiled on both Boot 4.0.8 and 4.1.1). Also fixes the root README's module table, which was missing a row for resilience4j-circuit-breaker (added in a previous commit but never indexed here).
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
# env-var-proof
|
||||
|
||||
Answers one factual question with real execution instead of quoting a changelog: does Spring
|
||||
Boot 4.1 actually honor standard `OTEL_*` environment variables that Boot 4.0 did not?
|
||||
|
||||
`boot40/` and `boot41/` contain the **identical** `OtelEnvProofApplication.java` -- the only
|
||||
difference between the two Maven modules is the `spring-boot-starter-parent` version (4.0.8 vs
|
||||
4.1.1). Both start with only `OTEL_EXPORTER_OTLP_ENDPOINT` and `OTEL_METRIC_EXPORT_INTERVAL` set
|
||||
(no `management.otlp.*` Spring properties anywhere) and point at `stub-receiver/`, a
|
||||
dependency-free stand-in for an OTLP collector that just logs every POST it receives.
|
||||
|
||||
See [`../docs/output/04-otel-env-vars-4.0-vs-4.1.txt`](../docs/output/04-otel-env-vars-4.0-vs-4.1.txt)
|
||||
for the captured result, and [`../docs/03-otel-env-vars.md`](../docs/03-otel-env-vars.md) for the
|
||||
write-up. Run it yourself with [`../scripts/run-env-var-proof.sh`](../scripts/run-env-var-proof.sh).
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.0.8</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>com.ankurm</groupId>
|
||||
<artifactId>otel-env-proof-40</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-opentelemetry</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.ankurm.otelproof;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* Sets ONLY standard OTEL_* environment variables (no management.otlp.* Spring properties at
|
||||
* all) and checks whether metrics actually reach the configured OTLP endpoint within a fixed
|
||||
* observation window. Identical source file used against Boot 4.0.8 and Boot 4.1.1 -- only the
|
||||
* parent POM version differs between the two modules that compile this file.
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class OtelEnvProofApplication {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
var ctx = SpringApplication.run(OtelEnvProofApplication.class, args);
|
||||
MeterRegistry registry = ctx.getBean(MeterRegistry.class);
|
||||
Counter counter = Counter.builder("otel.env.proof.calls").register(registry);
|
||||
long start = System.currentTimeMillis();
|
||||
long windowMs = 20_000;
|
||||
while (System.currentTimeMillis() - start < windowMs) {
|
||||
counter.increment();
|
||||
Thread.sleep(200);
|
||||
}
|
||||
System.out.println("otel.env.proof.calls final count = " + counter.count());
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
CommandLineRunner logStart() {
|
||||
return args -> System.out.println("otel-env-proof app started, MeterRegistry bean present");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.1.1</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>com.ankurm</groupId>
|
||||
<artifactId>otel-env-proof-41</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-opentelemetry</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.ankurm.otelproof;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* Sets ONLY standard OTEL_* environment variables (no management.otlp.* Spring properties at
|
||||
* all) and checks whether metrics actually reach the configured OTLP endpoint within a fixed
|
||||
* observation window. Identical source file used against Boot 4.0.8 and Boot 4.1.1 -- only the
|
||||
* parent POM version differs between the two modules that compile this file.
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class OtelEnvProofApplication {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
var ctx = SpringApplication.run(OtelEnvProofApplication.class, args);
|
||||
MeterRegistry registry = ctx.getBean(MeterRegistry.class);
|
||||
Counter counter = Counter.builder("otel.env.proof.calls").register(registry);
|
||||
long start = System.currentTimeMillis();
|
||||
long windowMs = 20_000;
|
||||
while (System.currentTimeMillis() - start < windowMs) {
|
||||
counter.increment();
|
||||
Thread.sleep(200);
|
||||
}
|
||||
System.out.println("otel.env.proof.calls final count = " + counter.count());
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
CommandLineRunner logStart() {
|
||||
return args -> System.out.println("otel-env-proof app started, MeterRegistry bean present");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* A minimal, dependency-free stand-in for an OTLP collector. It accepts any POST to any path,
|
||||
* logs the path, content-length and arrival time to a file (one line per request), and returns
|
||||
* 200 OK with an empty OTLP-shaped protobuf response body. Used only to answer one factual
|
||||
* question: did this JVM actually attempt to POST metrics to the configured OTLP endpoint within
|
||||
* the observation window? Not a real collector -- doesn't parse the protobuf payload.
|
||||
*
|
||||
* Usage: java StubOtlpReceiver.java <port> <logFile>
|
||||
*/
|
||||
public class StubOtlpReceiver {
|
||||
public static void main(String[] args) throws Exception {
|
||||
int port = Integer.parseInt(args[0]);
|
||||
Path logFile = Path.of(args[1]);
|
||||
Files.deleteIfExists(logFile);
|
||||
Files.createFile(logFile);
|
||||
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress("0.0.0.0", port), 0);
|
||||
server.createContext("/", exchange -> {
|
||||
String line = Instant.now() + " " + exchange.getRequestMethod() + " " + exchange.getRequestURI()
|
||||
+ " content-length=" + exchange.getRequestHeaders().getFirst("Content-Length") + System.lineSeparator();
|
||||
Files.writeString(logFile, line, StandardOpenOption.APPEND);
|
||||
exchange.getRequestBody().readAllBytes(); // drain
|
||||
byte[] resp = new byte[0];
|
||||
exchange.sendResponseHeaders(200, resp.length);
|
||||
try (OutputStream os = exchange.getResponseBody()) {
|
||||
os.write(resp);
|
||||
}
|
||||
});
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
System.out.println("StubOtlpReceiver listening on :" + port + ", logging to " + logFile);
|
||||
// Run until killed externally.
|
||||
Thread.currentThread().join();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user