From 087a6ab7bebefc636e68f0a39a4b75c4bc28b99b Mon Sep 17 00:00:00 2001 From: Mahesh Kumar Raju Date: Tue, 21 Jul 2026 23:22:45 -0600 Subject: [PATCH] Add staging OTel log synthesis rule for POSTGRESQLINSTANCE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds definition.stg.yml with a new synthesis rule that associates OTel log events (db.server.top_query, db.server.query_sample) with the existing POSTGRESQLINSTANCE entity. Uses db.system.name: postgresql as the discriminator — receiver-agnostic and always present when log events are enabled. Identifier is service.instance.id (host:port) to match the existing OTel metric rule, ensuring logs resolve to the same entity GUID. Also adds tests/Log.json covering both log event types for CI validation. --- .../definition.stg.yml | 92 +++++++++++++++++++ .../infra-postgresqlinstance/tests/Log.json | 35 +++++++ 2 files changed, 127 insertions(+) create mode 100644 entity-types/infra-postgresqlinstance/definition.stg.yml create mode 100644 entity-types/infra-postgresqlinstance/tests/Log.json diff --git a/entity-types/infra-postgresqlinstance/definition.stg.yml b/entity-types/infra-postgresqlinstance/definition.stg.yml new file mode 100644 index 000000000..cb2acc287 --- /dev/null +++ b/entity-types/infra-postgresqlinstance/definition.stg.yml @@ -0,0 +1,92 @@ +domain: INFRA +type: POSTGRESQLINSTANCE + +synthesis: + rules: + # opentelemetry (postgresqlreceiver); service.instance.id is host:port, enabled by default + - ruleName: infra_postgresqlinstance_service_instance_id + identifier: service.instance.id # host:port + name: service.instance.id + encodeIdentifierInGUID: true + conditions: + - attribute: eventType + value: Metric + - attribute: metricName + prefix: postgresql. + - attribute: instrumentation.provider + value: opentelemetry + tags: + # Environment resource attributes + host.type: + cloud.provider: + cloud.account.id: + cloud.region: + otel.library.name: + entityTagName: instrumentation.name + + # opentelemetry logs (db.server.top_query / db.server.query_sample); + # db.system.name is always present on these log events when enabled. + # Using service.instance.id (host:port) to match the metric rule above. + - ruleName: infra_postgresqlinstance_otel_logs + identifier: service.instance.id # host:port + name: service.instance.id + encodeIdentifierInGUID: true + conditions: + - attribute: eventType + value: Log + - attribute: instrumentation.provider + value: opentelemetry + - attribute: db.system.name + value: postgresql + tags: + host.type: + cloud.provider: + cloud.account.id: + cloud.region: + otel.library.name: + entityTagName: instrumentation.name + + # nri-postgresql / PostgresqlInstanceSample + - ruleName: infra_postgresqlinstance_entityId + identifier: entityId + name: entityKey + legacyFeatures: + useNonStandardAttributes: true + overrideGuidType: true + prefixedTags: + label.: + ttl: PT4H + conditions: + - attribute: eventType + value: 'PostgresqlInstanceSample' + tags: + integrationName: + ttl: P1D + integrationVersion: + ttl: P1D + reportingAgent: + ttl: P1D + reportingEndpoint: + ttl: P1D + + tags: + # For OpenTelemetry + telemetry.sdk.name: + entityTagName: instrumentation.provider + +goldenTags: +- postgres.host +configuration: + entityExpirationTime: DAILY + alertable: true + +dashboardTemplates: + # This should match the entity created from the ohi in the infra pipeline + newRelic: + template: newrelic_dashboard.json + opentelemetry: + template: opentelemetry_dashboard.json + +ownership: + primaryOwner: + teamName: "Database Integrations" diff --git a/entity-types/infra-postgresqlinstance/tests/Log.json b/entity-types/infra-postgresqlinstance/tests/Log.json new file mode 100644 index 000000000..5f45aded3 --- /dev/null +++ b/entity-types/infra-postgresqlinstance/tests/Log.json @@ -0,0 +1,35 @@ +[ + { + "eventType": "Log", + "instrumentation.provider": "opentelemetry", + "db.system.name": "postgresql", + "db.namespace": "testdb", + "db.query.text": "SELECT 1", + "event.name": "db.server.top_query", + "service.instance.id": "localhost:5432", + "newrelic.source": "api.logs.otlp", + "otel.library.name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver", + "postgresql.calls": 10, + "postgresql.queryid": "12345", + "postgresql.rolname": "app_user", + "postgresql.rows": 100, + "postgresql.total_exec_time": 5.2, + "timestamp": 1784408557426 + }, + { + "eventType": "Log", + "instrumentation.provider": "opentelemetry", + "db.system.name": "postgresql", + "db.namespace": "testdb", + "db.query.text": "SELECT id FROM users WHERE active = $1", + "event.name": "db.server.query_sample", + "service.instance.id": "localhost:5432", + "newrelic.source": "api.logs.otlp", + "otel.library.name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver", + "postgresql.state": "active", + "postgresql.pid": 1234, + "postgresql.rolname": "app_user", + "postgresql.total_exec_time": 1.5, + "timestamp": 1784408557426 + } +]