pydantic / logfire

Uncomplicated Observability for Python and beyond! 🪵🔥
https://logfire.pydantic.dev/docs/
MIT License
2.13k stars 63 forks source link

Enable webhook data "styling" #383

Open mmzeynalli opened 2 months ago

mmzeynalli commented 2 months ago

Description

I think it would be better for anyone to style their own webhook message format: some would like to want to highlight special parts, or would want text in different format (HTML, Markdown etc.). As of today, I was able to get messages to Slack, but I do not like the formatting:

The data comes like this:

+---------+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|   level | message           | attributes                                                                                                                                                                                                       | otel_events                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|---------+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|      17 | FastAPI arguments | {'code.lineno': 1, 'code.filepath': '<string>', 'logfire.scrubbed': [{'path': ['otel_events', 0, 'attributes', 'exception.message'], 'matched_substring': 'auth'}], 'logfire.msg_template': 'FastAPI arguments'} | [{'attributes': {'exception.type': 'fastapi.exceptions.HTTPException', 'exception.escaped': 'True', 'exception.message': "[Scrubbed due to 'auth']", 'exception.stacktrace': 'Traceback (most recent call last):\n  File "/usr/local/lib/python3.11/site-packages/logfire/_internal/integrations/fastapi.py", line 176, in solve_dependencies\n    result = await original\n             ^^^^^^^^^^^^^^\n  File "/usr/local/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 598, in solve_dependencies\n    solved = await call(**sub_values)\n             ^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/fromfolio/fromfolio/utils/auth.py", line 39, in __call__\n    raise HTTPException(\nfastapi.exceptions.HTTPException: [Scrubbed due to \'auth\']'}, 'event_name': 'exception', 'event_timestamp': '2024-08-19T08:56:27.276392Z'}] |
+---------+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

What I see is:

image

For example, I would like to get JSON formatted data for attributes/otel_events, but all I get is raw text like format.

alexmojaki commented 2 months ago

For full customization, you can set the channel format to "Raw Data" and the URL to an integrator such as Zapier or a custom endpoint of your own.

For sending directly to slack, I suggest selecting only the columns otel_status_message (for the exception message, assuming you're filtering for exceptions) and trace_id. You can then either (1) manually copy the trace_id and query for trace_id = '<paste value here>' in the live view, or (2) open the alert, find a match in the run history, expand results, and click on a trace ID. I know that's not great, we want to make this easier by making the trace ID clickable in slack messages and/or linking directly to an alert result.

mmzeynalli commented 2 months ago

With current setup, I have no problem reading the error message and understanding what happening, however, it would really be great to format it for your needs.

alexmojaki commented 2 months ago

Oh yes, I'm not denying there's a lot to improve here, just offering suggestions in the meantime.