Skip to content

Conversation

@gaantunes
Copy link
Contributor

@gaantunes gaantunes commented Dec 12, 2025

PR Description

Implementing a Postgres logs parser focused on error collection, with the following capabilities:

  • Extracts insights from log messages, like affected tables, columns, blocker and blocked pids, among others
  • Generates metrics from the error lines, categorizing errors by sqlstate_code, user, queryid, auth failures and more
  • Accepts the JSON format only, given its the recommended format for parsing Postgres logs

Which issue(s) this PR fixes

Notes to the Reviewer

PR Checklist

  • Documentation added
  • Tests updated

@gaantunes gaantunes requested a review from a team as a code owner December 12, 2025 18:09
@gaantunes gaantunes marked this pull request as draft December 12, 2025 21:30
@gaantunes gaantunes changed the title database_observability: postgres logs error collector add postgres logs error collector to database_observability.postgres component Dec 16, 2025
@gaantunes gaantunes changed the title add postgres logs error collector to database_observability.postgres component feat: add postgres logs error collector to database_observability.postgres component Dec 16, 2025
@gaantunes gaantunes changed the title feat: add postgres logs error collector to database_observability.postgres component feat: Add postgres logs error collector to database_observability.postgres component Jan 6, 2026
Comment on lines +149 to +150
Targets []discovery.Target `alloy:"targets,attr"`
ErrorLogsReceiver loki.LogsReceiver `alloy:"error_logs_receiver,attr,optional"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaantunes I've done a first pass, my feeling is that we're doing more than needed at this stage, I'll explain:

  • I'd focus on producing one single metric, postgres_errors_total, but change the labels from "severity", "database", "instance" to "database", "instance", "queryid". This seems to be the core of what we'd need to show an error rate (global and per-query).
  • ignore anything else for now, e.g. no need to parse anything other than query error messages, no need for other metrics IMO. We also don't need to write back to EntryHandler a custom log line, we just need the metric really.

So my ask is to basically to trim it down dramatically and keep it very, very simple as first pass. We can still re-introduce later anything else that seems useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cristiangreco.
Customers have showed interest in knowing what is the exact error in previous feedbacks. If we are already going to parse the logs to have metrics, why not provide this information already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in our 1:1 this will be split into different PRs to approach the problem iteratively.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

💻 Deploy preview available (feat: Add postgres logs error collector to database_observability.postgres component):

@gaantunes gaantunes marked this pull request as ready for review January 7, 2026 21:07

### `error_logs`

The `error_logs` collector is always active and processes PostgreSQL error logs in JSON format (requires `log_destination = 'jsonlog'` in PostgreSQL configuration).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `error_logs` collector is always active and processes PostgreSQL error logs in JSON format (requires `log_destination = 'jsonlog'` in PostgreSQL configuration).
The `error_logs` collector is always active and processes PostgreSQL error logs in JSON format.
This requires `log_destination = 'jsonlog'` in your PostgreSQL configuration.

The `error_logs` collector is always active and processes PostgreSQL error logs in JSON format (requires `log_destination = 'jsonlog'` in PostgreSQL configuration).
It receives log entries through the component's `forward_to` parameter, extracts error information, maps SQLSTATE codes to human-readable error names, and tracks metrics by error type and severity.

Unlike other collectors, `error_logs` does not need to be enabled via `enable_collectors` - it automatically processes any PostgreSQL JSON logs that are forwarded to the component.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Unlike other collectors, `error_logs` does not need to be enabled via `enable_collectors` - it automatically processes any PostgreSQL JSON logs that are forwarded to the component.
Unlike other collectors, `error_logs` does not need to be enabled via `enable_collectors`.
It automatically processes any PostgreSQL JSON logs that are forwarded to the component.

By default, SQL statements and Personally Identifiable Information (PII) in error log fields are redacted to protect sensitive data.
This includes:
- SQL literals in `statement` and `internal_query` fields
- Data values in `detail` and `context` fields (such as constraint violations, key values, and row data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Data values in `detail` and `context` fields (such as constraint violations, key values, and row data)
- Data values in `detail` and `context` fields such as constraint violations, key values, and row data

This includes:
- SQL literals in `statement` and `internal_query` fields
- Data values in `detail` and `context` fields (such as constraint violations, key values, and row data)
- Parenthesized values in error messages (e.g., `Key (id)=(123)` becomes `Key (id)=(?)`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Parenthesized values in error messages (e.g., `Key (id)=(123)` becomes `Key (id)=(?)`)
- Parenthesized values in error messages, for example, `Key (id)=(123)` becomes `Key (id)=(?)`

| `disable_query_redaction` | `bool` | Disable redaction of SQL queries and PII in error logs. Use with caution in production environments. | `false` | no |

{{< admonition type="warning" >}}
Setting `disable_query_redaction` to `true` will expose SQL query parameters, constraint values, and other potentially sensitive information in error logs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Setting `disable_query_redaction` to `true` will expose SQL query parameters, constraint values, and other potentially sensitive information in error logs.
If you set `disable_query_redaction` to `true`, it will expose SQL query parameters, constraint values, and other potentially sensitive information in error logs.

@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/docs Docs Squad label across all Grafana Labs repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants