Skip to content

Commit a186517

Browse files
committed
add example for OTLP logging via stdout and k8s
1 parent eb70bb2 commit a186517

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed
Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
11
# Exporting Application logs using JSON logging in Kubernetes
22

3-
## Running the example
4-
5-
1. Build the Docker image using using `build.sh`
6-
2. Deploy the manifest using `kubectl apply -f k8s/` (e.g. using [k3d.sh](k3d.sh))
7-
3. Generate traffic using [generate-traffic.sh](./generate-traffic.sh)
8-
4. Log in to [http://localhost:3000](http://localhost:3000) with user _admin_ and password _admin_.
9-
5. Go to "Explore"
10-
6. Select "Loki" as data source
3+
If you want to get logs from your Java application ingested into an
4+
OpenTelemetry-compatible logs backend, the easiest and recommended way is using
5+
an OpenTelemetry protocol (OTLP) exporter,
6+
which is explained in the [logging](../logging) example.
7+
8+
However, some scenarios require logs
9+
to be output to files or stdout due to organizational or reliability needs.
10+
Refer to [Collecting OpenTelemetry-compliant Java logs from files](https://opentelemetry.io/blog/2024/collecting-otel-compliant-java-logs-from-files/) for more details.
11+
12+
This example contains
13+
14+
- a Java application that uses the experimental
15+
[experimental-otlp/stdout](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#in-development-exporter-selection) logs exporter
16+
- a OTel collector configuration that uses the
17+
[OTLP/JSON connector](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/connector/otlpjsonconnector) to turn Pod logs into `OTLP`
18+
19+
20+
![OTLP/JSON Architecture](otlpjson-architecture.png)
21+
22+
## Getting Started
23+
24+
The k8s directory contains the Kubernetes manifests to deploy the application and the collector.
25+
26+
Ignore the `lgtm.yaml` file, which is only used for running locally and automated testing
27+
using [OATs](https://github.com/grafana/oats).
28+
29+
## Running locally
30+
31+
You can run the application locally using the following steps:
32+
33+
1. Run [k3d.sh](./k3d.sh) to start a local Kubernetes cluster with all the necessary components.
34+
2. Generate traffic using [generate-traffic.sh](./generate-traffic.sh)
35+
3. Log in to [http://localhost:3000](http://localhost:3000)
36+
4. Go to "Explore"
37+
5. Select "Loki" as data source to view the logs

logging-k8s-stdout-otlp-json/oats.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats/tree/main/yaml
1+
# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats
2+
23
kubernetes:
34
dir: k8s
45
app-service: dice
Loading
Loading

0 commit comments

Comments
 (0)