If you want to get logs from your Java application ingested into an OpenTelemetry-compatible logs backend, the easiest and recommended way is using an OpenTelemetry protocol (OTLP) exporter, which is explained in the logging example.
However, some scenarios require logs to be output to files or stdout due to organizational or reliability needs. Refer to Collecting OpenTelemetry-compliant Java logs from files for more details.
This example contains
- a Java application that uses the experimental experimental-otlp/stdout logs exporter
- an OpenTelemetry collector configuration that uses the
OTLP/JSON connector to turn Pod logs into
OTLP
The OpenTelemetry Collector pipeline:
The k8s directory contains the Kubernetes manifests to deploy the application and the collector.
Ignore the lgtm.yaml
file, which is only used for running locally with
LGTM
and automated testing using OATs.
You can run the application locally using the following steps:
- Run k3d.sh to start a local Kubernetes cluster with all the necessary components.
- Generate traffic using generate-traffic.sh
- Log in to http://localhost:3000
- Go to "Explore"
- Select "Loki" as data source to view the logs