Skip to main content

OpenTelemetry using Docker

Run the OpenTelemetry Collector in a Docker container and send logs and host metrics to Coralogix. Your configuration and log file stay on the host and are mounted into the container, so you can edit them without rebuilding anything.

What you need

Configure the Collector

1.
Create the configuration file

Save this as config.yaml. It tails a log file and scrapes CPU and memory, then exports both to Coralogix.

receivers:
filelog:
start_at: beginning
include:
- /example.log
include_file_path: true
multiline: {line_start_pattern: "\\n"}
hostmetrics:
collection_interval: 30s
scrapers:
cpu:
memory:
exporters:
coralogix:
domain: "Domain"
private_key: "Private key"
application_name: "Application Name"
subsystem_name: "Subsystem Name"
timeout: 30s

service:
pipelines:
logs:
receivers: [ filelog ]
exporters: [ coralogix ]
metrics:
receivers: [ hostmetrics ]
exporters: [ coralogix ]
ValueWhat to enter
private_keyYour Coralogix Send-Your-Data API key
domainYour Coralogix domain
application_nameThe application name shown in your dashboard. A company called SuperData might use SuperData, or SuperData-Test for a test environment
subsystem_nameThe subsystem name shown in your dashboard. Most applications have several (backend servers, middleware, frontend servers) and this is what lets you separate them later
2.
Create a log file to read

Save this as example.log, so there is something for the filelog receiver to pick up.

2023-06-19 05:20:50 ERROR This is a test error message
2023-06-20 12:50:00 DEBUG This is a test debug message
2023-06-21 12:34:56 INFO This is a test info message
3.
Run the container

Mount both files from the working directory into the container. See the Collector Docker guide for the mount paths.

docker pull otel/opentelemetry-collector-contrib
docker run -d \
-v "$(pwd)"/config.yaml:/etc/otelcol-contrib/config.yaml \
-v "$(pwd)"/example.log:/example.log \
otel/opentelemetry-collector-contrib

Validate the logs

In Coralogix, select LiveTail, then Start. The three test lines arrive as structured records under the application and subsystem names you configured.

Coralogix LiveTail showing three OpenTelemetry log records with severity, application, subsystem, and body fields

Shows the test file's error, debug, and info lines as they arrive.

Validate the metrics

1.
Open Grafana
2.
Browse the metrics

In the left-hand panel, select Explore, then Metrics browser, and select a metric. The host metrics receiver produces system_cpu_time_total and system_memory_usage_By.

Grafana metrics browser with the host metrics produced by the Collector listed for selection

Shows the CPU and memory series the hostmetrics scrapers emit.

Last updated on