Replies: 2 comments 3 replies
-
@rajkumar-rangaraj @vishweshbankwar Could you help? |
Beta Was this translation helpful? Give feedback.
-
@vishweshbankwar thanks for the answer! I thought there is one ExecutionContext during http request. That's why I thought there will be the same instance of ExecutionContext inside both these calls From your answer I understood that inside I looked to AsyncTaskMethodBuilder and all I saw is how current ExecutionContext is captured and passed on. I didn't find where new instances of ExecutionContext can be created.
I don't know why it happened so. Maybe I messed something and copied wrong peace of output from console. I have checked few times today and today it seems all is correct:
|
Beta Was this translation helpful? Give feedback.
-
Hi!
I'm trying to understand how open telemetry works.
I have this configuration of open telemetry
And I have controller with this action:
"exec Delay" - it's a call to stored procedure which is executed 3 seconds.
As a result I see correct activities in console:
*with correct duration of each
How it works on my opinion.
In SqlCommand there is SqlDiagnosticListener through which it writes its diagnostic events.
SqlClientDiagnosticListener is listening to these events and calls appropriate handler which is SqlClientDiagnosticListener in current case.
In case of
SqlMicrosoftBeforeExecuteCommand/SqlDataBeforeExecuteCommand
events it creates new activity (which is set as Current under the hood), in cases when command is finished it stops activity which is passed as Activity.Current from SqlClientDiagnosticListener.When activity is stopped, ConsoleActivityExporter is notified about that and writes activity data to Console.
Knowing all that, I assumed there can be wrong result in case when we start second query while first isn't finished yet. I imagined something like this will happen:
var t1 = db1.Database.ExecuteSqlRawAsync("exec Delay");
this creates new activity (A1) and sets it as Current
var t2 = db2.Database.ExecuteSqlRawAsync("exec Delay");
this creates new activity (A2) and sets it as Current; probably, A1 will be parent activity for this one.
when t1 will be finished it takes A2 activity (as it's current) and stops it
when t2 will be finished it takes A1 activity (because A2 already is stopped and current is A1) and stops it
I thought it would lead to the fact when A1 will have duration more than 3 seconds, A2 will have duration less than 3 seconds.
But both activities have duration equal 3 seconds as they should.
I've spent a lot of time trying to figure out how it works, but I haven't been able to figure it out.
Could someone explain to me how it works?
Beta Was this translation helpful? Give feedback.
All reactions