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!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...