feat: add generic WebhookChannel notification channel - #3
Merged
Merged
Conversation
Add WebhookChannel/WebhookConfig: posts a service-agnostic JSON failure payload via urllib (stdlib only), with optional X-Signature-SHA256 header when a shared secret is configured. Add manual_webhook_inspect.py as the webhook counterpart to manual_pipeline_inspect.py.
_build_traced_vars (formerly _build_traced_vars_html) no longer HTML-escapes results, so _ErrorData.traced_vars / task_context["traced_vars"] is now a presentation-agnostic dict. _HTMLEmailFormatter does the HTML escaping when rendering, and the webhook payload now emits structured JSON instead of an HTML-escaped string.
_TaskLogfileFormatter now appends a "Traced vars:" block listing each traced local variable's repr, now that traced_vars is a plain dict rather than a pre-escaped HTML string.
… keys Lets callers merge static top-level keys (e.g. Telegram chat_id, Slack channel/username) into the JSON body without subclassing the formatter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Adds a generic
WebhookChannelnotification channel alongside the existingEmailChannel/FileChannel, so task failures can be POSTed as JSON to anywebhook endpoint (Slack/Discord/Telegram/custom relays, etc.) without coupling
the library to a specific service.
WebhookConfig(url, headers, timeout, optional HMAC-SHA256secret,and
extra_payloadfor service-specific routing keys like a Telegramchat_idor Slackchannel)._webhook_internals.py:_WebhookFormatter(JSON payload built from_ErrorData, with an overridable_build_payloadextension point forfuture service-specific subclasses) and
_WebhookHandler(POST viaurllib.request, optional HMAC body signing,extra_payloadmerge)._build_traced_vars_html→_build_traced_vars, now returninga plain
dict[str, str]({name: repr(value)}) instead of pre-escapedHTML, so non-HTML consumers (webhook JSON, plain-text logfiles) get clean
data.
_HTMLEmailFormatternow does its own HTML escaping oftraced_vars._TaskLogfileFormatternow appends a "Traced vars" section to plain-texttask logfiles on failure.
tests/manual_tests/manual_webhook_inspect.py) spins up alocal HTTP server and verifies the JSON payload and HMAC signature
end-to-end, without touching the existing
manual_pipeline_inspect.py.WebhookChannel/WebhookConfig.Type of change
feat— new featurefix— bug fixrefactor— no behavior changedocs— documentation onlytest— tests onlychore/ci/build