Skip to content

Instantly share code, notes, and snippets.

@up1
Last active November 3, 2024 12:07
Show Gist options
  • Save up1/f172f267fd850e91bdefd0c7e5524da1 to your computer and use it in GitHub Desktop.
Save up1/f172f267fd850e91bdefd0c7e5524da1 to your computer and use it in GitHub Desktop.
Spring Boot 3 + OpenTelemetry
# For OTLP - OTLP Prometheus endpoint, OTLP requires pushing
management.otlp.metrics.export.url=http://localhost:9090/api/v1/otlp/v1/metrics
# only for demo purposes
management.otlp.metrics.export.step=2s
# All traces should be sent to latency analysis tool
management.tracing.sampling.probability=1.0
# OTLP endpoint - OTLP Tempo endpoint
management.zipkin.tracing.endpoint=http://localhost:4318/v1/traces
management.zipkin.tracing.encoding=PROTO3
# For Exemplars to work we need histogram buckets - TODO: Micrometer OTLP doesn't yet support exemplars
management.metrics.distribution.percentiles-histogram.http.server.requests=true
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<springProperty scope="context" name="appName" source="spring.application.name"/>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://localhost:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>app=${appName},host=${HOSTNAME},level=%level</pattern>
</label>
<message>
<pattern>${FILE_LOG_PATTERN}</pattern>
</message>
<sortByTime>true</sortByTime>
</format>
</appender>
<root level="INFO">
<appender-ref ref="LOKI"/>
</root>
</configuration>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Prerequisite for observability -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- For Observation AOP -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- For Metrics -->
<!-- For OTLP -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-otlp</artifactId>
</dependency>
<!-- Brave version -->
<!-- For Tracing -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<!-- For Latency Visualization -->
<dependency>
<groupId>io.zipkin.contrib.otel</groupId>
<artifactId>encoder-brave</artifactId>
<version>0.1.0</version>
</dependency>
<!-- For pushing logs out -->
<dependency>
<groupId>com.github.loki4j</groupId>
<artifactId>loki-logback-appender</artifactId>
<version>1.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment