Thread
#prefect-community
    d

    David Beck

    4 months ago
    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?
    Kevin Kho

    Kevin Kho

    4 months ago
    Aren’t they already prefixed by
    prefect.context
    ? You don’t like that and want to prefix with
    prefect
    instead?
    d

    David Beck

    4 months ago
    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:
    Kevin Kho

    Kevin Kho

    4 months ago
    I am personally not seeing an easy way to do this
    d

    David Beck

    4 months ago
    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
    Kevin Kho

    Kevin Kho

    4 months ago
    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

    4 months ago
    Okay thank you anyways. I will see to finding some kind of work around on another end