Skip to content

Commit fd9951c

Browse files
committed
Integrate OpenTelemetry java agent
1 parent 0e636bc commit fd9951c

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- 'master'
77
- 'main'
8+
- 'epic/**'
89

910
jobs:
1011
deploy:

pom.xml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212

1313
<artifactId>shared-resources</artifactId>
14-
<version>3.0.1</version>
14+
<version>4.0.0-test-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

1717
<name>Java shared resources</name>
@@ -38,6 +38,10 @@
3838
<url>https://github.com/valitydev/java-shared-resources/tree/master</url>
3939
</scm>
4040

41+
<properties>
42+
<opentelemetry.javaagent.version>2.22.0</opentelemetry.javaagent.version>
43+
</properties>
44+
4145
<dependencies>
4246
<dependency>
4347
<groupId>org.springframework.boot</groupId>
@@ -55,10 +59,48 @@
5559
<artifactId>janino</artifactId>
5660
<version>3.1.9</version>
5761
</dependency>
62+
<dependency>
63+
<groupId>io.opentelemetry.javaagent</groupId>
64+
<artifactId>opentelemetry-javaagent</artifactId>
65+
<version>${opentelemetry.javaagent.version}</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>io.opentelemetry.instrumentation</groupId>
69+
<artifactId>opentelemetry-logback-mdc-1.0</artifactId>
70+
<version>2.22.0-alpha</version>
71+
<scope>runtime</scope>
72+
</dependency>
5873
</dependencies>
5974

6075
<build>
6176
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-dependency-plugin</artifactId>
80+
<version>3.6.1</version>
81+
<executions>
82+
<execution>
83+
<id>copy-opentelemetry-javaagent</id>
84+
<phase>process-resources</phase>
85+
<goals>
86+
<goal>copy</goal>
87+
</goals>
88+
<configuration>
89+
<artifactItems>
90+
<artifactItem>
91+
<groupId>io.opentelemetry.javaagent</groupId>
92+
<artifactId>opentelemetry-javaagent</artifactId>
93+
<version>${opentelemetry.javaagent.version}</version>
94+
<type>jar</type>
95+
<overWrite>true</overWrite>
96+
<outputDirectory>${project.build.directory}/classes</outputDirectory>
97+
<destFileName>opentelemetry-javaagent.jar</destFileName>
98+
</artifactItem>
99+
</artifactItems>
100+
</configuration>
101+
</execution>
102+
</executions>
103+
</plugin>
62104
<plugin>
63105
<artifactId>maven-remote-resources-plugin</artifactId>
64106
<version>3.0.0</version>

src/main/resources/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ FROM ghcr.io/valitydev/temurin-jemalloc:sha-14c0b34
22

33
RUN useradd -s /bin/false -U -u 20000 vality
44

5+
COPY --chown=vality:vality opentelemetry-javaagent.jar /opt/${artifactId}/opentelemetry-javaagent.jar
56
COPY --chown=vality:vality ${artifactId}-${version}.jar /opt/${artifactId}/${artifactId}.jar
67

78
USER vality:vality
89

9-
CMD ["java", "-jar","/opt/${artifactId}/${artifactId}.jar"]
10+
CMD ["java", "-javaagent:/opt/${artifactId}/opentelemetry-javaagent.jar", "-jar","/opt/${artifactId}/${artifactId}.jar"]
1011

1112
EXPOSE ${exposed.ports}
1213

src/main/resources/logback-spring.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,17 @@
6666
</encoder>
6767
</appender>
6868

69-
<root level="${loggingLevelRoot}">
69+
<appender name="JSON_K8S_CONSOLE_OTEL"
70+
class="io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender">
71+
<addBaggage>true</addBaggage>
72+
<traceIdKey>otel_trace_id</traceIdKey>
73+
<spanIdKey>otel_span_id</spanIdKey>
74+
<traceFlagsKey>otel_trace_flags</traceFlagsKey>
7075
<appender-ref ref="JSON_K8S_CONSOLE"/>
76+
</appender>
77+
78+
<root level="${loggingLevelRoot}">
79+
<appender-ref ref="JSON_K8S_CONSOLE_OTEL"/>
7180
</root>
7281
</then>
7382
</if>

0 commit comments

Comments
 (0)