Structured Logging with Datadog #5142
Unanswered
speedyturkey
asked this question in
Show and tell
Replies: 1 comment 3 replies
-
Thanks for sharing! I'll keep this in mind while I work on logging in Orion. I've already got a stub for a JSON logger that you could turn on with an environment variable. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted to share some basic information about how I am sending structured logs from prefect flows to Datadog, prompted by @kvnkho's request in the Prefect Slack community. I am happy to share how my organization does this, but I am not an expert on either Kubernetes or Datadog and I'm sure there are other good ways to accomplish this. I am still developing this solution, so it is likely that there are improvements to be made.
Background
I am running Prefect on Kubernetes (EKS). When a running pod logs to stdout, the logs are processed by fluentbit, which is running as a daemonset in each of our clusters. We use labels to tell fluentbit which Cloudwatch log group to send logs to:
cloudwatch/log_group_name
. We then use a Kinesis firehose to copy the logs from Cloudwatch to Datadog. I believe this is accomplished using an account-wide subscription filter (I'm not clear on the details).Prefect
Given the above infrastructure, this part is easy. The goal is to send structured logs as json, because Datadog knows how to ingest these and will allow you to create facets based on flow name, task name, etc for easy search and filtering.
We have a shared Python library which is installed in the base image used for all Prefect flows, which contains a number of common utility functions. The Prefect logging file looks like this:
Sample usage is as follows. Note that because we are adding the json handler, the output does mix standard output with json output - I like this because I can choose to view logs in Prefect Cloud directly, or in Datadog. Note that Prefect's default logger adds
flow_name
,task_name
, etc automatically which is very useful.I'm sure I will come to refine this setup over time but hopefully this is helpful to someone.
Beta Was this translation helpful? Give feedback.
All reactions