Skip to content

postgresqlreceiver - client_addr in query collection is misspelled as client_addrs #42447

@sv-splunk

Description

@sv-splunk

Component(s)

receiver/postgresql

What happened?

Description

In the field mapping of query_sample attributes in client.go, we are currently mapping `currentAttributes["network.peer.address"] = row["client_addrs"], and in this line client_addrs is misspelled. Actual field name in pg_stat_activity table is client_addr.
This prevents the client_addr from being reported.

Steps to Reproduce

Run the collector for postgresql and observe the query_sample payload. The network.peer.address can be seen as empty.

Expected Result

network.peer.address should hold the client_addr

Actual Result

network.peer.address has empty value.

Collector version

v0.134.0

Environment information

Environment

OS: Mac OS
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

receivers:
  postgresql:
    endpoint: localhost:5432
    password: password123
    events:
      db.server.top_query:
        enabled: true
      db.server.query_sample:
        enabled: true
    username: admin
    tls:
      insecure: true
exporters:
  file:
    path: "out/log_postgresql.json"
service:
  telemetry:
    logs:
      level: info
  pipelines:
    logs:
      receivers:
        - postgresql
      exporters:
        - file

Log output

{
    "resourceLogs": [
        {
            "resource": {},
            "scopeLogs": [
                {
                    "scope": {
                        "name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver"
                    },
                    "logRecords": [
                        {
                            "timeUnixNano": "1756820102145037000",
                            "body": {},
                            "attributes": [
                                {
                                    "key": "db.system.name",
                                    "value": {
                                        "stringValue": "postgresql"
                                    }
                                },
                                {
                                    "key": "db.namespace",
                                    "value": {
                                        "stringValue": "postgres"
                                    }
                                },
                                {
                                    "key": "db.query.text",
                                    "value": {
                                        "stringValue": "SELECT COALESCE ( datname, ? ) AS datname, COALESCE ( usename, ? ) AS usename, COALESCE ( client_addr :: TEXT, ? ) AS client_addr, COALESCE ( client_hostname, ? ) AS client_hostname, COALESCE ( client_port :: TEXT, ? ) AS client_port, COALESCE ( query_start :: TEXT, ? ) AS query_start, COALESCE ( wait_event_type, ? ) AS wait_event_type, COALESCE ( wait_event, ? ) AS wait_event, COALESCE ( query_id :: TEXT, ? ) AS query_id, COALESCE ( pid :: TEXT, ? ) AS pid, COALESCE ( application_name :: TEXT, ? ) AS application_name, EXTRACT ( EPOCH FROM query_start ) AS _query_start_timestamp, state, query, CASE WHEN state = ? THEN EXTRACT ( EPOCH FROM ( clock_timestamp ( ) - query_start ) ) * ? WHEN state IN ( ? ) AND state_change IS NOT ? THEN EXTRACT ( EPOCH FROM ( state_change - query_start ) ) * ? ELSE ? END AS duration_ms FROM pg_stat_activity WHERE coalesce ( TRIM ( query ),"
                                    }
                                },
                                {
                                    "key": "user.name",
                                    "value": {
                                        "stringValue": "admin"
                                    }
                                },
                                {
                                    "key": "postgresql.state",
                                    "value": {
                                        "stringValue": "active"
                                    }
                                },
                                {
                                    "key": "postgresql.pid",
                                    "value": {
                                        "intValue": "226"
                                    }
                                },
                                {
                                    "key": "postgresql.application_name",
                                    "value": {
                                        "stringValue": ""
                                    }
                                },
                                {
                                    "key": "network.peer.address",
                                    "value": {
                                        "stringValue": ""
                                    }
                                },
                                {
                                    "key": "network.peer.port",
                                    "value": {
                                        "intValue": "52679"
                                    }
                                },
                                {
                                    "key": "postgresql.client_hostname",
                                    "value": {
                                        "stringValue": ""
                                    }
                                },
                                {
                                    "key": "postgresql.query_start",
                                    "value": {
                                        "stringValue": "2025-09-02 13:35:02.146195+00"
                                    }
                                },
                                {
                                    "key": "postgresql.wait_event",
                                    "value": {
                                        "stringValue": ""
                                    }
                                },
                                {
                                    "key": "postgresql.wait_event_type",
                                    "value": {
                                        "stringValue": ""
                                    }
                                },
                                {
                                    "key": "postgresql.query_id",
                                    "value": {
                                        "stringValue": "-902431181327670373"
                                    }
                                },
                                {
                                    "key": "postgresql.total_exec_time",
                                    "value": {
                                        "doubleValue": 5.917
                                    }
                                }
                            ],
                            "eventName": "db.server.query_sample"
                        }
                    ]
                }
            ]
        }
    ]
}

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions