Skip to content

Instantly share code, notes, and snippets.

@kevbook
Last active October 29, 2025 13:47
Show Gist options
  • Save kevbook/2bbaf3a43702f2529071ae9b2290b832 to your computer and use it in GitHub Desktop.
Save kevbook/2bbaf3a43702f2529071ae9b2290b832 to your computer and use it in GitHub Desktop.
# https://axiom.co/docs/send-data/vector
# https://hub.docker.com/r/koyeb/log-exporter/tags
# https://www.koyeb.com/docs/run-and-scale/log-exporter#custom-export-locations
# https://gist.github.com/kevbook/2bbaf3a43702f2529071ae9b2290b832
# @example [input = pipe] (Koyeb log message)
# {
# "host": "5b9b9c2f",
# "message": "{\"date\":\"2025-10-29T11:28:48.868657Z\",\"stream\":\"koyeb\",\"msg\":\"Instance is healthy. All health checks are passing.\",\"error\":null,\"labels\":{\"type\":\"runtime\",\"stream\":\"koyeb\",\"organization_id\":\"555f1666-c4e4-478a-8642-e9a0e5a2861e\",\"app_id\":\"040ff415-74f2-4622-8f5b-b385aa940b2a\",\"service_id\":\"a1754cb3-bb41-473a-9469-546c049c76d6\",\"instance_id\":\"52fed237-2ccb-a6c4-778e-7611ca8ff8bc\"}}",
# "source_type": "stdin",
# "timestamp": "2025-10-27T15:00:12.569488344Z"
# }
# @example [input = pipe] (service log message)
# {
# "host": "5b9b9c2f",
# "message": "{\"date\":\"2025-10-27T15:00:11.555670313Z\",\"stream\":\"stdout\",\"msg\":\"{\\\"level\\\":\\\"error\\\",\\\"timestamp\\\":1761577211518,\\\"trace_id\\\":\\\"019a262f-167d-731e-9ad9-8c29f1ea3bae\\\",\\\"attributes\\\":{\\\"request\\\":{\\\"id\\\":\\\"019a262f-167d-731e-9ad9-8c29f1ea3bae\\\",\\\"ip\\\":\\\"2a02:587:b29:6800:3d87:a58d:85d:add2\\\",\\\"method\\\":\\\"POST\\\",\\\"host\\\":\\\"beta.score-services.scoretravel.ai\\\",\\\"path\\\":\\\"/example/testFunction\\\"},\\\"error\\\":{\\\"code\\\":\\\"UNAUTHORIZED\\\",\\\"status\\\":401,\\\"name\\\":\\\"Error\\\",\\\"message\\\":\\\"Invalid authentication\\\",\\\"stack\\\":\\\"\\\"},\\\"status\\\":401},\\\"body\\\":\\\"Invalid authentication\\\"}\",\"error\":null,\"labels\":{\"type\":\"runtime\",\"stream\":\"stdout\",\"organization_id\":\"555f1666-c4e4-478a-8642-e9a0e5a2861e\",\"app_id\":\"040ff415-74f2-4622-8f5b-b385aa940b2a\",\"service_id\":\"a1754cb3-bb41-473a-9469-546c049c76d6\",\"instance_id\":\"6ff5449b-0275-4953-60ab-1a34e73fe39d\"}}",
# "source_type": "stdin",
# "timestamp": "2025-10-27T15:00:12.569488344Z"
# }
# For debugging
# [sinks.console]
# type = "console"
# inputs = ["pipe"]
# encoding.codec = "json"
# Axiom sink
[sinks.axiom]
type = "axiom"
inputs = ["flatten_message"]
dataset = "koyeb"
token = "${AXIOM_TOKEN}"
# Flatten the "message.msg" field (Koyeb format)
[transforms.flatten_message]
type = "remap"
inputs = ["pipe"]
source = '''
# Parse and flatten the "message" field
if is_string(.message) {
parsed_message, err = parse_json(.message)
if err == null && is_object(parsed_message) {
# Parse the "msg" field (if it exists)
if exists(parsed_message.msg) && is_string(parsed_message.msg) {
# Parse service log message
inner_msg, inner_err = parse_json(parsed_message.msg)
if inner_err == null && is_object(inner_msg) {
. = inner_msg
} else {
# Koyeb log message
.body = parsed_message.msg
.timestamp = parsed_message.date
del(.message)
del(.date)
del(.labels)
del(.source_type)
}
}
if exists(parsed_message.labels) {
# Use set() function to assign to fields with dots in the name
. = set!(., ["service.instance.id"], parsed_message.labels.instance_id)
}
}
}
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment