Skip to content

Commit ed65594

Browse files
committed
logs injection working
1 parent e1add1a commit ed65594

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

content/en/other/3-auto-instrumentation/3-java-microservices-pet-clinic/30-auto-instrumentation.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ In the previous chapter, we enabled the OpenTelemetry Collector for Kubernetes o
1010
It is important to understand that Zero Config Auto instrumentation is designed to get Trace/Span & Profiling data out of your existing application, without requiring you to change your code or requiring to rebuild.
1111
{{% /notice %}}
1212

13-
1413
For this workshop we will be using the Zero config option of the Opentelemetry Collector in Kubernetes.
1514
This means that the Collector monitors you pods running in Kubernetes, and if they match certain criteria, they will en able auto instrumentation on the pod.
1615

17-
For Java this is the Kubernetes TAG `instrumentation.opentelemetry.io/inject-java\` set to `true`
16+
For Java it is looking for the Kubernetes TAG `instrumentation.opentelemetry.io/inject-java\` set to `true`
1817

1918
## 1. Setting up Java auto instrumentation on the first pod
2019

2120
If you enable Zero configuration for a pod, the Collector will attach an initContainer to your existing pod, and restart the pod to activate it.
2221

23-
To show what happens when you enable Auto instrumentation let first do a for & after of the content of a pod, the `api-gateway` in this case:
22+
To show what happens when you enable Auto instrumentation, lets do a For & After of the content of a pod, the `api-gateway` in this case:
2423

2524
```bash
2625
kubectl describe pods api-gateway |grep Image:
@@ -32,6 +31,8 @@ The resulting output should say:
3231
Image: quay.io/phagen/spring-petclinic-api-gateway:0.0.2
3332
```
3433

34+
This container is pulled from a remote repository `quay.io` and as you will see
35+
3536
Lets add the Java auto instrumentation TAG to the api-gateway service first with the `kubectl patch deployment` command.
3637
{{< tabs >}}
3738
{{% tab title="Patch api-gateway service" %}}

content/en/other/3-auto-instrumentation/3-java-microservices-pet-clinic/60-log-observer-connect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The Services are now ready to be build, so run the script that will use the `mav
101101
{{% tab title="Running maven" %}}
102102

103103
```bash
104-
./mvnw clean install -DskipTests -P buildDocker
104+
./mvnw clean install -D skipTests -P buildDocker
105105
```
106106

107107
{{% /tab %}}
@@ -195,7 +195,7 @@ The result should be :
195195

196196
## 5. Deploy new services to kubernetes
197197

198-
To see the changes in effect, we need to redeploy the services, First let change the location of the images from the exterenal repo to the local one by running the following script:
198+
To see the changes in effect, we need to redeploy the services, First let change the location of the images from the external repo to the local one by running the following script:
199199

200200
```bash
201201
. ~/workshop/petclinic/scripts/set_local.sh

workshop/petclinic/scripts/add_otel.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ new_dependencies="
1515
</dependency>
1616
<dependency>
1717
<groupId>io.opentelemetry.instrumentation</groupId>
18-
<artifactId>opentelemetry-logback-mdc-1.0</artifactId>
18+
<artifactId>opentelemetry-logback-appender-1.0</artifactId>
1919
<version>2.0.0-alpha</version>
20-
</dependency>"
20+
</dependency>
21+
<dependency>
22+
<groupId>io.opentelemetry.instrumentation</groupId>
23+
<artifactId>opentelemetry-logback-mdc-1.0</artifactId>
24+
<version>2.0.0-alpha</version>
25+
</dependency>
26+
"
2127

2228
# Loop through the specified directories
2329
for dir in "${directories[@]}"; do
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Specify the constant prefix
4+
pod_prefix="petclinic-loadgen-deployment-"
5+
6+
# Get the current pod name with the specified prefix
7+
pod_name=$(kubectl get pods -o=name | grep "$pod_prefix" | cut -d'/' -f 2)
8+
9+
# Check if a pod with the specified prefix is found
10+
if [ -n "$pod_name" ]; then
11+
# Continuously tail the logs from the specified pod
12+
kubectl logs -f "$pod_name"
13+
else
14+
echo "Error: No pod found with the specified prefix."
15+
fi

workshop/petclinic/scripts/update_logback.sh

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,47 @@
11
#!/bin/bash
22

3+
# '<?xml version="1.0" encoding="UTF-8"?>
4+
# <configuration>
5+
# <include resource="org/springframework/boot/logging/logback/base.xml"/>
6+
# <!-- Required for Loglevel managment into the Spring Petclinic Admin Server-->
7+
# <jmxConfigurator/>
8+
# <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
9+
# <encoder>
10+
# <pattern>
11+
# %d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg trace_id=%X{trace_id} span_id=%X{span_id} trace_flags=%X{trace_flags} %n service.name=%property{otel.resource.service.name}, deployment.environment=%property{otel.resource.deployment.environment}: %m%n
12+
# </pattern>
13+
# </encoder>
14+
# </appender>
15+
16+
# <!-- Just wrap your logging appender, for example ConsoleAppender, with OpenTelemetryAppender -->
17+
# <appender name="OTEL" class="io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender">
18+
# <appender-ref ref="CONSOLE"/>
19+
# </appender>
20+
21+
# <!-- Use the wrapped "OTEL" appender instead of the original "CONSOLE" one -->
22+
# <root level="INFO">
23+
# <appender-ref ref="OTEL"/>
24+
# </root>
25+
# </configuration>'
26+
27+
328
xml_content='<?xml version="1.0" encoding="UTF-8"?>
429
<configuration>
5-
<include resource="org/springframework/boot/logging/logback/base.xml"/>
6-
<!-- Required for Loglevel managment into the Spring Petclinic Admin Server-->
7-
<jmxConfigurator/>
8-
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
30+
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
931
<encoder>
10-
<pattern>
11-
%d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg trace_id=%X{trace_id} span_id=%X{span_id} trace_flags=%X{trace_flags} %n service.name=%property{otel.resource.service.name}, deployment.environment=%property{otel.resource.deployment.environment}: %m%n
12-
</pattern>
13-
</encoder>
32+
<pattern>
33+
logback: %d{HH:mm:ss.SSS} [%thread] %level %logger{36} - trace_id=%X{trace_id} span_id=%X{span_id} service.name=%property{otel.resource.service.name} trace_flags=%X{trace_flags} - %msg %kvp{DOUBLE}%n
34+
</encoder>
1435
</appender>
15-
16-
<!-- Just wrap your logging appender, for example ConsoleAppender, with OpenTelemetryAppender -->
17-
<appender name="OTEL" class="io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender">
18-
<appender-ref ref="CONSOLE"/>
36+
<appender name="OpenTelemetry"
37+
class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
38+
<captureExperimentalAttributes>true</captureExperimentalAttributes>
39+
<captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
1940
</appender>
20-
21-
<!-- Use the wrapped "OTEL" appender instead of the original "CONSOLE" one -->
22-
<root level="INFO">
23-
<appender-ref ref="OTEL"/>
24-
</root>
41+
<root level="INFO">
42+
<appender-ref ref="console"/>
43+
<appender-ref ref="OpenTelemetry"/>
44+
</root>
2545
</configuration>'
2646

2747
directory_paths=("admin-server" "api-gateway" "config-server" "customers-service" "discovery-server" "vets-service" "visits-service")

0 commit comments

Comments
 (0)