opserver / Opserver

Stack Exchange's Monitoring System
https://opserver.github.io/Opserver/
MIT License
4.5k stars 827 forks source link

Is it possible to get the application name which query run in which application? #335

Closed dharmenbavaria closed 5 years ago

dharmenbavaria commented 5 years ago

We use opserver for our test environment in SQL server to find top queries and many other features of opserver. but the same database is used by a number of application. So sometimes while seeing the top queries we cant really find out which query was executed by which application. We probably get application name in sql server profiler, so was checking if there was some kind of configuration which needs to be changed for that in opserver to get that details.

elvishfiend commented 5 years ago

It should be possible to get it to show in the Active page, because that's based on current activity.

It's not possible to get it for the Top Queries page, because it's based on Query Execution statistics which don't persist application information.

Something I've heard @NickCraver/Stack Overflow have used in the past was an extension method on the application's ORM that appended application and callsite information to the query as a comment. Pretty much the only way you can get that info into the Query Stats it by including in the query string itself.

dharmenbavaria commented 5 years ago

@NickCraver/Stack Overflow do you have any example for this? I would really appreciate a help.

NickCraver commented 5 years ago

Yeah sure - here's a gist of how we do this with Dapper today - this is marking for file path and line number instead of app, but you could easily add app in there too: https://gist.github.com/NickCraver/c6f371bf8df37e05c4f09fd3c02ef6a2

NickCraver commented 5 years ago

I'm going to close this out as the answer is above :)