Skip to content

Latest commit

 

History

History

logging-k8s-stdout-otlp-json

Exporting Application logs using JSON logging in Kubernetes

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

Architecture

OTLP/JSON Architecture

The OpenTelemetry Collector pipeline:

OpenTelemetry Collector Pipeline

Getting Started

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.

Running locally

You can run the application locally using the following steps:

  1. Run k3d.sh to start a local Kubernetes cluster with all the necessary components.
  2. Generate traffic using generate-traffic.sh
  3. Log in to http://localhost:3000
  4. Go to "Explore"
  5. Select "Loki" as data source to view the logs