-
Notifications
You must be signed in to change notification settings - Fork 6
Process logs before sending them to loki #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
ddf6fbf
40da8ce
381aad4
0066ab5
895d2d9
80ae5f2
9fbd977
ea19265
48a9ec4
b849a6b
1c9774b
f1b9628
ea15372
d7f6faf
abd215e
9e6e4d2
a68ac63
2339d46
2a17bd5
a542433
ca1d01e
31afb5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,31 @@ transforms: | |
| .message = .short_message | ||
| } | ||
|
|
||
| # Extract structured log fields from message using regex pattern | ||
| if exists(.message) { | ||
| parsed_fields, err = parse_regex(.message, r'log_level=(?P<log_level>[^|]*) \| log_timestamp=(?P<log_timestamp>[^|]*) \| log_source=(?P<log_source>[^|]*) \| log_uid=(?P<log_uid>[^|]*) \| log_oec=(?P<log_oec>[^|]*) \| log_trace_id=(?P<log_trace_id>[^|]*) \| log_span_id=(?P<log_span_id>[^|]*) \| log_msg=(?P<log_msg>.*)$') | ||
| if err == null { | ||
| .log_level = parsed_fields.log_level | ||
| .log_timestamp = parsed_fields.log_timestamp | ||
| .log_source = parsed_fields.log_source | ||
| .log_uid = parsed_fields.log_uid | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this becomes a label in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are not labels, because labels should have low cardinality (https://grafana.com/docs/loki/latest/get-started/labels/bp-labels/). Instead this adds them as keys in the log json. Then there is a json parser directly in loki and after applying that one can filter on these fields.
|
||
| .log_oec = parsed_fields.log_oec | ||
| .log_trace_id = parsed_fields.log_trace_id | ||
| .log_span_id = parsed_fields.log_span_id | ||
| .log_msg = parsed_fields.log_msg | ||
| } | ||
| } | ||
|
|
||
| # Handle container name - GELF uses _container_name (with underscore prefix) | ||
| if exists(._container_name) { | ||
| .container_name = ._container_name | ||
|
|
||
| # Extract Docker service name from container name (everything before first dot) | ||
| match = parse_regex!(.container_name, r'^(?P<service_name>[^.]+)') | ||
| .service_name = match.service_name | ||
| } else { | ||
| .container_name = "unknown" | ||
| .service_name = "unknown" | ||
| } | ||
|
|
||
| # Handle container ID | ||
|
|
@@ -58,13 +78,13 @@ sinks: | |
| encoding: | ||
| codec: json | ||
| labels: | ||
| job: "docker" | ||
| source: "vector" | ||
| # Pass through the GELF 'host' field from the original log event | ||
| host: "{{ host }}" | ||
| container_name: "{{ container_name }}" | ||
| # Remove label fields from the log line to avoid duplication | ||
| remove_label_fields: true | ||
| service_name: "{{ service_name }}" | ||
| # Override level label with extracted log_level from structured logs. This ensures correct color coding in Loki/Grafana | ||
| level: "{{ log_level }}" | ||
|
|
||
| healthcheck: | ||
| enabled: true | ||
|
|
||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this won't parse traefik logs.
We did fix this in Graylog #293
Might be interesting if you want to include traefik log level