https://prefect.io logo
Title
d

David Beck

05/03/2022, 5:29 PM
Hi all! I'm looking for some guidance on handling logging of context attributes. To best organize our events/metrics within out internal systems, I'm looking to prefix all Prefect context attributes with
prefect.
, e.g.
prefect.flow_name
. Given the documentations cautioning of renaming context attributes, I'm trying to brainstorm the simplest and most effective way of doing this across all our flows. Do you have suggestions?
k

Kevin Kho

05/03/2022, 5:33 PM
Aren’t they already prefixed by
prefect.context
? You don’t like that and want to prefix with
prefect
instead?
d

David Beck

05/03/2022, 5:41 PM
Perhaps I was unclear. So as shown here, the logger is configured to output those attributes with log records. These directly look up those attributes from the context via
context.get("attr")
. What I want is to change the attributes output for logs to include the prefix
prefect.
. Does that make sense?
Here's what's currently output by the logger:
k

Kevin Kho

05/03/2022, 5:44 PM
I am personally not seeing an easy way to do this
d

David Beck

05/03/2022, 5:45 PM
That's what I was fearing. I presume the only way would be to create a custom handler for logging and register it with Prefect somehow
k

Kevin Kho

05/03/2022, 5:48 PM
I think you’d have to maintain a fork because this is done here and there’s just no way to edit this behavior. If it were attached to a class, it might be doable but this is just a function called to instantiate it.
Your best bet, which I am unsure if it will work, is to pull the logger inside your flow and try to override/manipulate those. I think the UI logging format is hardcoded though so your can’t change it there.
d

David Beck

05/03/2022, 5:53 PM
Okay thank you anyways. I will see to finding some kind of work around on another end