Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/Updated for slack alerts. #1042

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/website/docs/examples/chess_production/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ def load_data_with_retry(pipeline, data):
```
<!--@@@DLT_SNIPPET_END ./code/chess-snippets.py::markdown_retry_cm-->

:::warning
To run this example you need to provide Slack incoming hook in `.dlt/secrets.toml`:
```python
[runtime]
slack_incoming_hook="https://hooks.slack.com/services/***"
```
Read [Using Slack to send messages.](https://dlthub.com/docs/running-in-production/running#using-slack-to-send-messages)
:::

### Run the pipeline

<!--@@@DLT_SNIPPET_START ./code/chess-snippets.py::markdown_pipeline-->
Expand Down
32 changes: 30 additions & 2 deletions docs/website/docs/running-in-production/alerting.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,33 @@ receiving rich information on executed pipelines, including encountered errors a

## Slack

Read [here](./running#using-slack-to-send-messages) about how to send
messages to Slack.
Alerts can be sent to a Slack channel via Slack's incoming webhook URL. The code snippet below demonstrates automated Slack notifications for database table updates using the `send_slack_message` function.

```python
# Import the send_slack_message function from the dlt library
from dlt.common.runtime.slack import send_slack_message

# Define the URL for your Slack webhook
hook = "https://hooks.slack.com/services/xxx/xxx/xxx"

# Iterate over each package in the load_info object
for package in info.load_packages:
# Iterate over each table in the schema_update of the current package
for table_name, table in package.schema_update.items():
# Iterate over each column in the current table
for column_name, column in table["columns"].items():
# Send a message to the Slack channel with the table
# and column update information
send_slack_message(
hook,
message=(
f"\tTable updated: {table_name}: "
f"Column changed: {column_name}: "
f"{column['data_type']}"
)
)
```
Refer to this [example](../../docs/examples/chess_production/) for a practical application of the method in a production environment.

Similarly, Slack notifications can be extended to include information on pipeline execution times, loading durations, schema modifications, and more. For comprehensive details on configuring and sending messages to Slack, please read [here](./running#using-slack-to-send-messages).

Loading