Skip to content

Commit c184492

Browse files
committed
OBSDOCS-2819: Document how to scrape a custom log file from a pod filesystem
1 parent f3c6298 commit c184492

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * observability/otel/otel-sending-traces-logs-and-metrics-to-otel-collector.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="collecting-container-logs-with-filelog-sidecar_{context}"]
7+
= Collecting container logs with the Filelog Receiver and sidecar injection
8+
9+
Collect logs from application containers by using the Filelog Receiver with sidecar injection. This approach is useful when your application writes logs to files within the container filesystem.
10+
11+
The {OTELOperator} allows to inject an OpenTelemetry Collector as a sidecar container into a application pod. While to access generated files both pods need to share a volume between
12+
the application container and the sidecar collector. Afterwards the Filelog Receiver can tail log files and apply operators to parse and transform the logs.
13+
14+
.Prerequisites
15+
16+
* You have access to the cluster as a cluster administrator with the `cluster-admin` role.
17+
18+
. Create an OpenTelemetry Collector instance configured with the filelog Receiver in sidecar mode. Ensure a matching `volumeMounts` entry is set to grant the sidecar access to your targeted files.
19+
+
20+
[source,yaml]
21+
----
22+
apiVersion: opentelemetry.io/v1beta1
23+
kind: OpenTelemetryCollector
24+
metadata:
25+
name: filelog
26+
namespace: otel-logging
27+
spec:
28+
mode: sidecar
29+
volumeMounts: # <1>
30+
- name: logs
31+
mountPath: /var/log/app
32+
config:
33+
receivers:
34+
filelog:
35+
include: # <2>
36+
- /var/log/app/*.log
37+
operators:
38+
- type: regex_parser
39+
regex: '^(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) \[(?P<level>\w+)\] (?P<message>.*)$'
40+
timestamp:
41+
parse_from: attributes.timestamp
42+
layout: '%Y-%m-%d %H:%M:%S'
43+
processors: {}
44+
exporters:
45+
debug:
46+
verbosity: detailed
47+
service:
48+
pipelines:
49+
logs:
50+
receivers: [filelog]
51+
processors: []
52+
exporters: [debug]
53+
----
54+
<1> Defines the volume mount that the sidecar collector will use to access the log files. This volume must match the volume name defined in the application deployment.
55+
<2> File glob patterns matching the log files to tail. The Filelog Receiver watches these paths for new log entries.
56+
+
57+
[IMPORTANT]
58+
====
59+
The `volumeMounts` field in the `OpenTelemetryCollector` custom resource is critical for the sidecar to access log files. The volume specified here must be defined in the application's `Deployment` or `Pod` specification, and both the application container and the sidecar collector must mount the same volume.
60+
====
61+
62+
[role="_additional-resources"]
63+
.Additional resources
64+
* xref:../../../observability/otel/otel-collector/otel-collector-receivers.adoc#filelog-receiver_otel-collector-receivers[Filelog Receiver]
65+
* xref:../../../observability/otel/otel-collector/otel-collector-receivers.adoc#otel-collector-receivers[Receivers]

modules/otel-receivers-filelog-receiver.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ include::snippets/technology-preview.adoc[]
3232
----
3333
<1> A list of file glob patterns that match the file paths to be read.
3434
<2> An array of Operators. Each Operator performs a simple task such as parsing a timestamp or JSON. To process logs into a desired format, chain the Operators together.
35+
36+
When using the Filelog Receiver in sidecar mode to collect logs from application containers, you must configure volume mounts in the `OpenTelemetryCollector` custom resource. The collector requires access to the log files through a shared volume, such as `emptyDir`, that is mounted in both the application container and the sidecar collector container. For a complete example, see "Collecting container logs with the Filelog Receiver and sidecar injection".

observability/otel/otel-sending-traces-logs-and-metrics-to-otel-collector.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Sending traces and metrics to the OpenTelemetry Collector is possible with or wi
1313
include::modules/otel-send-traces-and-metrics-to-otel-collector-with-sidecar.adoc[leveloffset=+1]
1414

1515
include::modules/otel-send-traces-and-metrics-to-otel-collector-without-sidecar.adoc[leveloffset=+1]
16+
17+
include::modules/otel-collecting-container-logs-with-filelog-sidecar.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)