Tony Lim
02/20/2025, 1:05 AMMarvin
02/20/2025, 1:06 AMlogging.yml
) to exclude sensitive data.
2. Custom Log Messages: Use Prefect's get_run_logger
to emit custom log messages that exclude sensitive information. This allows you to control the content of logs that are emitted during flow execution.
Here's a basic example of using `get_run_logger`:
python
from prefect import flow
from prefect.logging import get_run_logger
@flow
def my_flow(sensitive_data):
logger = get_run_logger()
# Log non-sensitive information
<http://logger.info|logger.info>("Flow started without logging sensitive data.")
# Use sensitive_data without logging it
my_flow("my_secret_password")
For more detailed configuration, you might need to dive into Prefect's logging documentation: Prefect Logging.Tony Lim
02/20/2025, 1:22 AMMarvin
02/20/2025, 1:22 AMprefect.yaml
file that includes dynamic content like timestamps, usernames, and commit messages from bash command outputs, you can utilize environment variables or templating features. Here's a basic approach to achieve this:
1. Define Environment Variables: Use bash commands to set environment variables before deploying. You can then reference these variables in your prefect.yaml
.
2. Use Templating: Prefect supports templating within the prefect.yaml
file, allowing you to insert dynamic values.
Here's an example of how you might structure your `prefect.yaml`:
yaml
description: |
Date deployed: {{ $DATE_DEPLOYED }}
Deployment Owner: {{ $DEPLOYMENT_OWNER }}
Commit message: {{ $COMMIT_MESSAGE }}
Before running your deployment, set the environment variables using bash commands:
bash
export DATE_DEPLOYED=$(date)
export DEPLOYMENT_OWNER=$(whoami)
export COMMIT_MESSAGE=$(git log -1 --pretty=%B)
Then, when you deploy using Prefect, these variables will be interpolated into the description field. Make sure your deployment process correctly sources these environment variables.
For more details on templating and environment variables in prefect.yaml
, you can refer to the Prefect YAML Documentation.Tony Lim
02/20/2025, 1:23 AM.run_shell_script
to obtain these valuesMarvin
02/20/2025, 1:23 AMrun_shell_script
step in your prefect.yaml
to execute shell commands and use their output in subsequent steps. This can be particularly useful for gathering dynamic information such as deployment timestamps, usernames, and commit messages.
Here's a basic example of how you might structure your prefect.yaml
to achieve this:
yaml
build:
steps:
- id: get_deployment_info
run_shell_script:
script: |
echo "Date deployed: $(date)"
echo "Deployment Owner: $(whoami)"
echo "Commit message: $(git log -1 --pretty=%B)"
- id: build_docker_image
build_docker_image:
image_name: my-image
tag: "{{ get_deployment_info.stdout }}"
In this example, the run_shell_script
step executes a shell script that outputs the desired information. The id
of the step (get_deployment_info
) allows you to reference its output in subsequent steps. The stdout
of the script can be used in other parts of your deployment configuration, such as in building a Docker image or setting metadata.
For more detailed information on using shell scripts within Prefect deployments, you can refer to the Prefect YAML Documentation and the Prefect Shell Integration.