|
1 | 1 | # Exporting Application logs using JSON logging in Kubernetes
|
2 | 2 |
|
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 | + |
| 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 |
0 commit comments