Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Instrumentation.Process] Implement threadSafe Refresh() #664
[Instrumentation.Process] Implement threadSafe Refresh() #664
Changes from 2 commits
d451059
5d688f1
b429d16
13434f5
b97401f
7646e7e
2c71223
6bfac03
c27b0d9
ec9a430
c11bf2d
ea77d50
6a90e75
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work with multiple
MeterProvider
setup?In the scenario where you have multiple meterProviders and all of them add Process instrumentation, this would create the same set of instruments for each
MeterProvider
since they are all using the sameMeter
instance.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure for what intent would the user want to do
.AddProcessInstrumentation()
for multiple meterProviders to a given application/process. Everything in ProcessMetrics should ideally be static in the scope of a Process.Could you share with me the use case you have in mind that ProcessMetrics was being added to more than one meterProvider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One use case could be where the user wants to send data from different meters to different exporters along with the process metrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there will not be a problem if we mark the ctor of ProcessMetrics as static.
I still don't quite get why would the user want to monitor a static object via different exporters?
One case I could think of now is role-based access control - authorized users of the application can see a certain field like for example process.disk.io while non-authorized users cannot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use instance members for meter and InstrumentValues with this commit 13434f5.
One caveat with this implementation is in
Snapshot()
, threadA calls Process.Refresh(), and before threadA does the assignment to this.memoryUsage, threadB calls Process.Refresh(). The odds are small as assignments should be very fast.Even if we hit this situation, it should not be a big deal because the time difference between these 2 refreshes is tiny.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this happen? Is there a concrete example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case I have in mind is:
At t3, the value got assigned to
this.virtualMemoryUsage
for threadA is from this.currentProcessRefresh() from t2 by threadB;because GetCurrentProcess() is a static method that returns "A new Process component associated with the process resource that is running the calling application."
Even though we maintain different copies for currentProcess here:
opentelemetry-dotnet-contrib/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs
Line 51 in 13434f5
Those are referencing the same object.
But again, I don't think this is a case that could be hit frequently. And even it did occur, the time difference between the 2 snapshots are negligible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snapshot
is an instance method, under which condition would the same instance see concurrent calls?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah....
Snapshot()
will not be accessed concurrently because it is an instance method.What I was worried about is that whether those 2 instances are refreshing on the same object.
After further investigation, that is not the case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look:
https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/664/files#r989475625