[receiver/sqlserver] Add session attributes to query sample event#48401
[receiver/sqlserver] Add session attributes to query sample event#48401gdivya-nr wants to merge 1 commit into
Conversation
Add session-level attributes to the db.server.query_sample log event, sourced from sys.dm_exec_sessions
|
|
|
Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib. Important reminders:
|
| description: Timestamp when the session was established (ISO 8601 format). | ||
| type: string | ||
| requirement_level: recommended | ||
| sqlserver.session.total_elapsed_time: |
There was a problem hiding this comment.
| sqlserver.session.total_elapsed_time: | |
| sqlserver.session.duration: |
| @@ -348,6 +360,10 @@ events: | |||
| - sqlserver.wait.resource.id | |||
| - sqlserver.wait.resource.type | |||
| - sqlserver.row_count | |||
| - sqlserver.session.total_elapsed_time | |||
There was a problem hiding this comment.
| - sqlserver.session.total_elapsed_time | |
| - sqlserver.session.duration |
| description: Process ID of the client application on the host system. | ||
| type: int | ||
| requirement_level: recommended | ||
| sqlserver.session.program_name: |
There was a problem hiding this comment.
| sqlserver.session.program_name: | |
| sqlserver.client.app.name: |
| sqlserver.session.host_process_id: | ||
| description: Process ID of the client application on the host system. | ||
| type: int | ||
| requirement_level: recommended |
There was a problem hiding this comment.
Not sure that this brings any benefit so would remove iy
| sqlserver.session.host_process_id: | |
| description: Process ID of the client application on the host system. | |
| type: int | |
| requirement_level: recommended |
But if it did it bring value it should be & opt-in
| sqlserver.session.host_process_id: | |
| description: Process ID of the client application on the host system. | |
| type: int | |
| requirement_level: recommended | |
| sqlserver.client.process_0.id: | |
| description: Process ID of the client application on the host system. | |
| type: int | |
| requirement_level: opt-in |
There was a problem hiding this comment.
Hi @thompson-tomo ,
During blocking or deadlock incidents, the host_process_id helps quickly correlate a SQL Server session back to the specific OS process on the client host. This is valuable for reducing MTTR, especially when multiple application instances are running on the same host.
It also helps identify misbehaving app instances — for example, if one PID holds 100+ sessions while others have 5, we can immediately tell which specific instance is leaking connections
There was a problem hiding this comment.
Shouldn't the client metrics be used to see when it is misbehaving ie too many connections? You already know which host to look at
There was a problem hiding this comment.
Thank you @thompson-tomo , for the comments and perspective!
host_name and client_address identify the machine, but not the specific process on that machine.
When multiple instances of the same application run on the same host, they share the same host_name, client_address, and program_name. host_process_id is the only way to distinguish between them.
client_tcp_port is too volatile: it captures the random, ephemeral outbound port assigned per socket at the network layer, so a single application instance running a connection pool of 100 connections will show up as 100 entirely unique ports.
There was a problem hiding this comment.
I understand that but what I actually mean is that the client should be reporting the client metrics as described in https://opentelemetry.io/docs/specs/semconv/db/database-metrics/#connection-pools.
When the client reports those metrics it enables more efficient troubleshooting for the use case you mentioned.
This PR enriches the db.server.query_sample log event emitted by the SQL Server receiver with additional session-level attributes, providing more context about the client connection associated with each query.
New Attributes added:-
sqlserver.session.host_process_id- Process ID of the client application on the host systemsqlserver.session.started- Timestamp of when the session logged in (ISO 8601 format)sqlserver.session.total_elapsed_time- Total elapsed time in seconds the session has been actively executing requests.sqlserver.session.program_name- Name of the client application that initiated the sessionUse cases:-
sqlserver.session.startedandsqlserver.session.total_elapsed_timetogether enable detection of problematic session patterns: a session that connected hours ago (session.started) but has accumulated very little active time (total_elapsed_time) is likely idle or leaked — still holding locks or resources without doing meaningful work. Conversely, a session with high total_elapsed_time relative to its age indicates a long-running or repeatedly executing workload.sqlserver.session.program_nameandsqlserver.host.process_idallow DBAs to trace problematic queries back to the specific application or process that initiated them, making it easier to correlate database-level issues with application behavior across services.Fixes:- 48346
Documentation
Added attribute definitions in metadata.yaml for:
sqlserver.host.process_id: Process ID of the client application on the host systemsqlserver.session.started: ISO 8601 timestamp of when the session logged in (also captured for idle blocker sessions)sqlserver.session.total_elapsed_time: Total elapsed time in seconds the session has been actively executing requests.sqlserver.session.program_name: Name of the client application that initiated the sessionTesting
Verified collector starts and connects to SQL Server successfully
Confirmed queries execute without errors in logs