-
Notifications
You must be signed in to change notification settings - Fork 358
[Resources.Process] implement latest semantic convention spec #3347
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
base: main
Are you sure you want to change the base?
Changes from 13 commits
5bfc0cf
6316cca
ae97c1c
44d0dd8
4fede6b
36b62f4
6d77f69
415c7dc
c714d56
74eabc0
ae2e468
7fb1252
c8d5ee1
5bef668
247870d
f42b41e
bf8cbcf
e72dae1
e885a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,20 +14,26 @@ internal sealed class ProcessDetector : IResourceDetector | |
| /// <returns>Resource with key-value pairs of resource attributes.</returns> | ||
| public Resource Detect() | ||
| { | ||
| return new Resource(new List<KeyValuePair<string, object>>(2) | ||
| using var currentProcess = System.Diagnostics.Process.GetCurrentProcess(); | ||
| var attributes = new List<KeyValuePair<string, object>>(9) | ||
| { | ||
| new(ProcessSemanticConventions.AttributeProcessOwner, Environment.UserName), | ||
| new(ProcessSemanticConventions.AttributeProcessArgsCount, Environment.GetCommandLineArgs().Length), | ||
| new(ProcessSemanticConventions.AttributeProcessStartTime, currentProcess.StartTime.ToString("O") ?? string.Empty), | ||
| new(ProcessSemanticConventions.AttributeProcessTitle, currentProcess.MainWindowTitle), | ||
|
||
| new(ProcessSemanticConventions.AttributeProcessWorkingDir, Environment.CurrentDirectory), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based what on I see is not reliable and might change in time. As it is conditionally required and we have AttributeProcessArgsCount, I would drop this attribute.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works for me in my testing. Resource attributes are allowed to change, they just need to be a descriptive attribute which this is. The description of the property mentions that this is the working directory. |
||
|
|
||
| new(ProcessSemanticConventions.AttributeProcessExecName, currentProcess.ProcessName), | ||
thompson-tomo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new(ProcessSemanticConventions.AttributeProcessInteractive, Environment.UserInteractive), | ||
|
||
| #if NET | ||
| new(ProcessSemanticConventions.AttributeProcessPid, Environment.ProcessId), | ||
|
||
| }); | ||
| new(ProcessSemanticConventions.AttributeProcessExecPath, Environment.ProcessPath ?? string.Empty), | ||
| }; | ||
| #else | ||
| new(ProcessSemanticConventions.AttributeProcessPid, GetProcessPid()), | ||
| }); | ||
| static int GetProcessPid() | ||
| { | ||
| using var process = System.Diagnostics.Process.GetCurrentProcess(); | ||
| return process.Id; | ||
| } | ||
| new(ProcessSemanticConventions.AttributeProcessPid, currentProcess.Id), | ||
| }; | ||
| #endif | ||
|
|
||
| return new Resource(attributes); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.