Skip to content

Instantly share code, notes, and snippets.

@jsvd
Last active January 30, 2026 16:43
Show Gist options
  • Select an option

  • Save jsvd/a3d31f5bea1b497428dcaf65ec75180f to your computer and use it in GitHub Desktop.

Select an option

Save jsvd/a3d31f5bea1b497428dcaf65ec75180f to your computer and use it in GitHub Desktop.
# Create an OpenTelemetry Collector configuration that processes log signals and performs the following 4 alterations:
#
# 1. Add a new attribute called env with the value production, but only if it doesn't already exist.
# 2. Remove the attribute internal.debug_id.
# 3. Change the value of the log.level attribute to "INFO" on records where it already exists.
# 4. Copy the value of the host.name attribute into a new attribute called hostname.
receivers:
otlp:
protocols:
grpc:
http:
processors:
attributes/logs:
actions:
# 1. Add env=production only if it doesn't already exist
- key: env
value: production
action: insert
# 2. Remove internal.debug_id
- key: internal.debug_id
action: delete
# 3. Change log.level to "INFO" if it already exists
- key: log.level
value: INFO
action: update
# 4. Copy host.name into hostname
- key: hostname
from_attribute: host.name
action: insert
exporters:
logging:
loglevel: info
service:
pipelines:
logs:
receivers: [otlp]
processors: [attributes/logs]
exporters: [logging]
# Create an OpenTelemetry Collector configuration that processes log signals and performs the following 4 transformations:
# 1. Add a new attribute called env with the value production, but only if it doesn't already exist.
# 2. Remove the attribute internal.debug_id.
# 3. Change the value of the log.level attribute to "INFO" on records where it already exists.
# 4. Copy the value of the host.name attribute into a new attribute called hostname.
receivers:
otlp:
protocols:
grpc:
http:
processors:
transform/logs:
log_statements:
- context: log
statements:
# 1. Add env=production only if it doesn't already exist
- set(attributes["env"], "production") where attributes["env"] == nil
# 2. Remove the attribute internal.debug_id
- delete_key(attributes, "internal.debug_id")
# 3. Change log.level to "INFO" only when it already exists
- set(attributes["log.level"], "INFO") where attributes["log.level"] != nil
# 4. Copy host.name into hostname (only if host.name exists)
- set(attributes["hostname"], attributes["host.name"]) where attributes["host.name"] != nil
exporters:
logging:
loglevel: info
service:
pipelines:
logs:
receivers: [otlp]
processors: [transform/logs]
exporters: [logging]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment