Warning
This article was automatically translated by OpenAI (gpt-4o-mini).It may be edited eventually, but please be aware that it may contain incorrect information at this time.
In this article, we will install OpenTelemetry Collector on Rocky Linux 8.
The motivation for introducing OpenTelemetry Collector is that in the previous article, we introduced Zipkin, but we wanted to exclude noisy traces like health checks. We will build a configuration as follows.
Tip
By creating a declarative configuration file like this example, it is also possible to exclude specific URLs on the Java Agent side.
In this article, we will install OpenTelemetry Collector on the same server as the previous article. We will also install the rpm package on the server without using Docker.
Table of Contents
Installing the rpm Package
Download the latest rpm package from the Assets at https://github.com/open-telemetry/opentelemetry-collector-releases/releases. Here, we will use otelcol-contrib, but otelcol without contrib is also acceptable.
# For AMD64
curl -L https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.121.0/otelcol-contrib_0.121.0_linux_amd64.rpm -o otelcol-contrib.rpm
# For ARM64
curl -L https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.121.0/otelcol-contrib_0.121.0_linux_arm64.rpm -o otelcol-contrib.rpm
Install the downloaded rpm package.
sudo rpm -ivh otelcol-contrib.rpm
The following log will be output.
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:otelcol-contrib-0.121.0-1 ################################# [100%]
Created symlink /etc/systemd/system/multi-user.target.wants/otelcol-contrib.service → /usr/lib/systemd/system/otelcol-contrib.service.
Editing the Config
The configuration file for the installed OpenTelemetry Collector is located at /etc/otelcol-contrib/config.yaml.
We will overwrite the configuration file as follows. Here, we will exclude spans that start with the URL path /actuator.
extensions:
health_check:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
filter:
#! https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/filterprocessor
error_mode: ignore
traces:
span:
- IsMatch(attributes["url.path"], "/actuator.*")
exporters:
debug:
verbosity: detailed
otlphttp/zipkin:
compression: gzip
endpoint: http://localhost:9411
tls:
insecure: true
service:
pipelines:
traces:
receivers:
- otlp
processors:
- filter
exporters:
- otlphttp/zipkin
extensions:
- health_check
Note
If OpenTelemetry Collector and Zipkin are on separate servers, please change the part http://localhost:9411.
Restart the OpenTelemetry Collector.
sudo systemctl restart otelcol-contrib
Check the status.
sudo systemctl status otelcol-contrib
If the following log is output, it is OK.
● otelcol-contrib.service - OpenTelemetry Collector Contrib
Loaded: loaded (/usr/lib/systemd/system/otelcol-contrib.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2025-03-10 22:05:06 JST; 14s ago
Main PID: 1289 (otelcol-contrib)
Tasks: 15 (limit: 617204)
Memory: 279.1M
CGroup: /system.slice/otelcol-contrib.service
└─1289 /usr/bin/otelcol-contrib --config=/etc/otelcol-contrib/config.yaml
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.177+0900 info service@v0.121.0/service.go:193 Setting up own telemetry...
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.177+0900 info service@v0.121.0/service.go:258 Starting otelcol-contrib... {"Version": "0.121.0", "NumCPU": 16}
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.177+0900 info extensions/extensions.go:40 Starting extensions...
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.177+0900 info extensions/extensions.go:44 Extension is starting... {"otelcol.component.id": "health_check", "otelcol.component.kind": "Extension"}
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.177+0900 info healthcheckextension@v0.121.0/healthcheckextension.go:32 Starting health_check extension {"otelcol.component.id": "health_check", "otelcol.componen
t.kind": "Extension", "config": {"Endpoint":"localhost:13133","TLSSetting":null,"CORS":null,"Auth":null,"MaxRequestBodySize":0,"IncludeMetadata":false,"ResponseHeaders":null,"CompressionAlgorithms":null,"ReadTimeout":0,"ReadHeaderTimeout":0,"WriteTimeout"
:0,"IdleTimeout":0,"Path":"/","ResponseBody":null,"CheckCollectorPipeline":{"Enabled":false,"Interval":"5m","ExporterFailureThreshold":5}}}
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.178+0900 info extensions/extensions.go:61 Extension started. {"otelcol.component.id": "health_check", "otelcol.component.kind": "Extension"}
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.178+0900 info otlpreceiver@v0.121.0/otlp.go:116 Starting GRPC server {"otelcol.component.id": "otlp", "otelcol.component.kind": "Receiver", "endpoint": "0.0.0.0:
4317"}
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.178+0900 info otlpreceiver@v0.121.0/otlp.go:173 Starting HTTP server {"otelcol.component.id": "otlp", "otelcol.component.kind": "Receiver", "endpoint": "0.0.0.0:
4318"}
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.178+0900 info healthcheck/handler.go:132 Health Check state change {"otelcol.component.id": "health_check", "otelcol.component.kind": "Extension", "status": "rea
dy"}
Mar 10 22:05:06 zipkin otelcol-contrib[1289]: 2025-03-10T22:05:06.178+0900 info service@v0.121.0/service.go:281 Everything is ready. Begin running and processing data.
You can also check the logs with the following command.
journalctl -u otelcol-contrib -f
Creating a Sample Application
We will send traces from the OpenTelemetry Java Agent to the installed OpenTelemetry Collector.
Create a Spring Boot application template with the following command.
curl -s https://start.spring.io/starter.tgz \
-d artifactId=hello-world \
-d baseDir=hello-world \
-d type=maven-project \
-d dependencies=web,actuator \
-d packageName=com.example \
-d applicationName=HelloWorldApplication | tar -xzvf -
cd hello-world
Note
Personally, when sending OTLP traces from a Spring Boot application, I use Micrometer. This time, I wanted to confirm the operation when sending from the OpenTelemetry Java Agent, so I used Spring Boot, which allows for quick application creation, and intentionally sent traces to the OpenTelemetry Collector via the OpenTelemetry Java Agent.
Create a controller that returns "Hello World!".
cat <<EOF > ./src/main/java/com/example/HelloController.java
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping(path = "/")
public String hello() {
return "Hello World!";
}
}
EOF
Build the application.
./mvnw clean package -DskipTests
Download the OpenTelemetry Java Agent.
sudo mkdir -p /opt/opentelemetry
sudo wget https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar -P /opt/opentelemetry
Set the environment variables for the OpenTelemetry Java Agent.
export OTELCOL_HOST=198.19.249.105 # change me
cat <<EOF > otel.sh
export OTEL_SERVICE_NAME=hello-world
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=none
export OTEL_LOGS_EXPORTER=none
export OTEL_EXPORTER_OTLP_ENDPOINT=http://${OTELCOL_HOST}:4318
export OTEL_TRACES_SAMPLER=traceidratio
export OTEL_TRACES_SAMPLER_ARG=1.0
export OTEL_EXPORTER_OTLP_COMPRESSION=gzip
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_RESOURCE_DISABLED_KEYS=process.command_args,process.command_line,process.executable.path,process.pid,os.type,os.description,host.arch
EOF
Load the environment variables and start the application.
source otel.sh
java -javaagent:/opt/opentelemetry/opentelemetry-javaagent.jar -jar target/hello-world-0.0.1-SNAPSHOT.jar
Send requests to the following URLs.
curl http://localhost:8080
curl http://localhost:8080/actuator
curl http://localhost:8080/actuator/health
curl http://localhost:8080
Check the traces in the Zipkin UI. If traces starting with the URL path /actuator are not displayed and other traces are shown, it is OK.