Skip to content

[db] Add context propagation for PostgreSQL via SET application_name#3581

Open
mhennoch wants to merge 5 commits intoopen-telemetry:mainfrom
mhennoch:pg-set-app-name
Open

[db] Add context propagation for PostgreSQL via SET application_name#3581
mhennoch wants to merge 5 commits intoopen-telemetry:mainfrom
mhennoch:pg-set-app-name

Conversation

@mhennoch
Copy link
Copy Markdown

Add context propagation for PostgreSQL via SET application_name

Part of #2162

Adds SET application_name as a context propagation mechanism for PostgreSQL, following the pattern established for SQL Server (SET CONTEXT_INFO) and Oracle (V$SESSION.ACTION).

Why SET application_name?
PostgreSQL instrumentation already supports SQL Commenter, but it has limitations:

  • Prepared statements — SQL Commenter cannot be used with named/prepared queries, as the comment is baked into the statement text and every subsequent execution carries stale trace context.
  • Stored procedures — SQL comments on the outer CALL statement are not visible to queries executed inside the procedure body.

SET application_name operates at the session level and avoids all of these issues. The value is visible in pg_stat_activity and the OpenTelemetry Collector PostgreSQL receiver already parses it to extract trace context from query samples.

Note on application_name

There is ongoing discussion about whether application_name is the ideal long-term mechanism — a protocol-level approach would be better but doesn't exist today. An imperfect convention behind an opt-in flag is still useful: it unblocks users now and can help motivate database-native solutions over time.

Existing implementations

@github-actions github-actions bot added enhancement New feature or request area:db labels Mar 26, 2026
Copy link
Copy Markdown
Member

@XSAM XSAM left a comment

Choose a reason for hiding this comment

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

👍

@mhennoch mhennoch marked this pull request as ready for review March 30, 2026 11:40
@mhennoch mhennoch requested review from a team as code owners March 30, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:db enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants