logfire icon indicating copy to clipboard operation
logfire copied to clipboard

How to restrict alerts to a specific environment

Open dhimmel opened this issue 6 months ago • 4 comments

I've set up alerts with a slack webhook, but I cannot figure out how to restrict them to a specific environment.

For example here is my alert query:

SELECT
  created_at,
  attributes->>'deployment_environment',
  http_response_status_code,
  trace_id
FROM records
WHERE
  level = 'error'

And attributes->>'deployment_environment' always comes back null on alerts. If it had a value, I could add a WHERE clause, e.g. to filter to production.

The issue might be more general. Does this SQL filter ever work:

attributes->>'deployment_environment' = 'production'

dhimmel avatar Jun 18 '25 21:06 dhimmel

deployment_environment is a column, just use that instead of attributes->>'deployment_environment'

alexmojaki avatar Jun 18 '25 21:06 alexmojaki

deployment_environment is a column, just use that instead of attributes->>'deployment_environment'

In the SQL Search UI, when I add a WHERE condition for deployment_environment="development", I get

Error: invalid query: No column named `development`.

With an AI suggested fix:

Image


Assuming deployment_environment does exist, then it could be good to include at:

https://github.com/pydantic/logfire/blob/e9c13335653db54adcc83d0832df63db0823dfd7/docs/guides/web-ui/explore.md?plain=1#L29-L62

And in the field guide (although it might be in the part of the hidden menu, note separate UI bug):

Image

dhimmel avatar Jun 19 '25 12:06 dhimmel

These are all good points, thank you.

Try: deployment_environment = 'development'

alexmojaki avatar Jun 19 '25 12:06 alexmojaki

Okay both of the following work, so the double quotes were the issue:

deployment_environment = 'development'
deployment_environment='development'

Also noting deployment_environment doesn't show up in the SQL editor autocomplete:

Image

All good on my end regarding the SQL condition upon environment. I will let the team decide whether to close this issue now or use it to track the ancillary issues.

dhimmel avatar Jun 19 '25 13:06 dhimmel