<@ULVA73B9P> on prefect3 can I add the deployment ...
# ask-marvin
a
@Marvin on prefect3 can I add the deployment name to the logs
m
User wants to log deployment names in Prefect 3. Sounds understandable enough. What's the Prefect way to log deployment names? Let's find out! Based on the available information, there isn't a direct mention of logging deployment names in the Prefect 3.0 documentation or issues. However, you can manually add the deployment name to your logs by customizing the logging within your flow or tasks. Here's a general approach: 1. Access Deployment Information: Ensure you have access to deployment information within your flow or task. 2. Custom Logs: Use the logging library or Prefect's logging capabilities to include the deployment name in log messages. Example:
Copy code
python
from prefect import flow, get_run_logger
from prefect.deployments import Deployment

@flow
def my_flow():
    logger = get_run_logger()
    deployment_name = "MyDeployment"  # Replace with a dynamic retrieval if possible
    <http://logger.info|logger.info>(f"Running flow in deployment: {deployment_name}")

    # Rest of your flow logic here

Deployment(
    name="MyDeployment",
    flow=my_flow,
)
For more specific implementations or dynamic retrievals of deployment names, you'll need to adapt based on how you structure your flows and deployments. Here are some useful references: - Deploying Flows - Automations and Triggers For more context, you might want to check this GitHub issue for related behaviors and this one for deployment-related configurations. Feel free to modify this approach to fit your specific needs.
a
But I want to set the deployment name as a property set to come through with every log, instead of expressly logging it in an info statement
n
hi @Anna you'd want to check out the logging formatting config options i dont think deployment is a standard variable you can format though
a
Hi @Nate! I apologize that I didn't see your response. Thank you for it. I did end up using a filter to add the deployment name to our logs. Something like:
Copy code
filters:

    # Add deployment name to applicable log lines
    deployment_name:
        (): custom_logging.utils.DeploymentNameFilter
I struggled to grab the deployment name from the runtime within the deployment name filter but didn't spend too much time on it because we are still running prefect2 and will re-visit when we upgrade.
👍 1
n
sounds good!