Skip to content

Conversation

@zzstoatzz
Copy link
Collaborator

Summary

  • Enables form_data to accept strings for raw body content, not just dicts for form-encoded data
  • Uses httpx content= for strings (raw body) and data= for dicts (form-encoded)
  • Enables forwarding pre-constructed JSON from automation bodies to external webhooks

Use case: When an automation triggers and renders JSON in the body field (using Jinja with event data), users can now forward that JSON as-is to external APIs like Datadog:

CustomWebhookNotificationBlock(
    name="datadog-events",
    url="https://api.datadoghq.com/api/v1/events",
    form_data="{{body}}",  # forwards the automation's JSON body as-is
    headers={"Content-Type": "application/json", "DD-API-KEY": "{{api_key}}"},
    secrets={"api_key": "..."},
)

Closes #19949

Test plan

  • Added test_string_form_data test
  • All existing TestCustomWebhook tests pass (11/11)
Reproduction script
from prefect.blocks.notifications import CustomWebhookNotificationBlock

# Simulate automation passing JSON as the body
automation_body = '{"flow_name": "my-etl-flow", "state": "Failed", "run_id": "abc123"}'

block = CustomWebhookNotificationBlock(
    name="datadog",
    url="https://httpbin.org/post",
    form_data="{{body}}",
    headers={"Content-Type": "application/json"},
)

args = block._build_request_args(automation_body, None)
print(args.get('content'))  # {"flow_name": "my-etl-flow", "state": "Failed", "run_id": "abc123"}

🤖 Generated with Claude Code

Enables sending raw string/bytes payloads via `form_data` field, which
is needed when forwarding pre-constructed JSON from automation bodies.

Previously `form_data` only accepted `dict[str, str]` for form-encoded
data. Now it accepts `str | dict[str, str]`:
- dict: form-encoded data (httpx `data=`)
- str: raw body content (httpx `content=`)

Closes #19949

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added the bug Something isn't working label Dec 23, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 23, 2025

CodSpeed Performance Report

Merging #19953 will not alter performance

Comparing fix-custom-webhook-string-form-data (7eff69a) with main (5f83d24)

Summary

✅ 2 untouched

@jbw-vtl
Copy link
Contributor

jbw-vtl commented Dec 24, 2025

Thank you very much for the rapid turnaround, this looks good to me.

We are fairly advanced in our prefect integrations with datadog, keen to eventually feedback things either to core or as a prefect-datadog integration.

Couple of things we have changed

  • Have prefect server, worker and jobs log json formatted logs, with us having highjacked the dictConfig, then using a sidecar container picking up logs and sending to datadog. This was very successful in copying the logging approach used for internal services to our job orchestration.
  • Tracing server, worker and job execution using ddtrace-run. So far not gone very far here, merely changing the image being run to include required dependencies and changed startup command. This lets us collect traces of e.g. web requests done within flows & debug database performance of the perfect server. We are keen to emit spans for each flow & task executions and should be able to leverage the existing otel integrations. More investigation required however

Others we are planning

  • Emit datadog events whenever a flow run changes, being able to create a central dashboard in datadog to view flow success / failure etc across all our clusters. This is what we are aiming to use the above change for
  • Integrate datadog API tests to run custom health checks against prefect, such as being able to query pending deployments etc
  • Lastly cataloging the jobs from prefect centrally, collecting metadata about each job (description, team owning and criticality as tags within a single place, likely datadog)

@zzstoatzz zzstoatzz marked this pull request as ready for review December 24, 2025 13:47
@zzstoatzz
Copy link
Collaborator Author

zzstoatzz commented Dec 24, 2025

hi @jbw-vtl - thanks for the context there! would you be willing to open a discussion where we can float different ideas for prefect/datadog integration and then break well-scoped issues out of that discussion?

@zzstoatzz zzstoatzz merged commit beef03b into main Dec 24, 2025
59 checks passed
@zzstoatzz zzstoatzz deleted the fix-custom-webhook-string-form-data branch December 24, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CustomWebhook form data not accepting string, only object

4 participants