Splunk Cloud Platform

Formatting container logs from non structured json to json

vamsikrishna-l
New Member

Hi Team,

I am using splunk otel collector daemonset to collect logs from containers and send them to splunk with some transformations. I am trying to achieve converting following log entry which is in string format

Body: Str(2025-03-05T22:46:16.526842773Z stdout F {"workspace":"#1234","service":{"updated_at":1700246094,"log_type":"kong-apilog"}}

 

Next I need to parse log entry as
{"timestamp": 2025-03-05T22:46:16.526842773Z, "log_entry": "stdout", "log_type": "F", "log": {"workspace":"#1234","service":{"updated_at":1700246094,"log_type":"kong-apilog"}} }
Following is my config

 

filelog/kong-logs:
include:
- /var/log/containers/kong-*.log
- type: regex_parser
regex: ^(?P<time>[^ ]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$
parse_from: body
storage: file_storage
 
transform:
error_mode: ignore
log_statements:
- context: log
statements:
- set(attributes["log"], ParseJSON(attributes["log"]))

So far I am able to parse log attribute alone to json but not able to construct full json structure as mentioned above and I am also facing error converting time attribute which is in string format to timestamp field  using following transformer
- set(time, Time(attributes["time"], "%Y-%m-%dT%H:%M:%S.%9N%Z"))

Since my timestamp is in nanoseconds I need to parse it in nano seconds
Can someone please help me in achieving the desired output
Thanks,
Vamsi




Labels (1)
0 Karma
Get Updates on the Splunk Community!

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Splunk App for Anomaly Detection End of Life Announcement

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...