Skip to content

Conversation

@thompson-tomo
Copy link
Contributor

@thompson-tomo thompson-tomo commented Oct 28, 2025

Fixes #2892
Design discussion issue #

Changes

This adds in additional recommend attributes to describe process. Implementation has been based on latest spec https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/process.md

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions bot added the comp:resources.process Things related to OpenTelemetry.Resources.Process label Oct 28, 2025
@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 86.36364% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.30%. Comparing base (0809a6a) to head (e885a7e).
⚠️ Report is 13 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...OpenTelemetry.Resources.Process/ProcessDetector.cs 86.36% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3347      +/-   ##
==========================================
+ Coverage   71.16%   71.30%   +0.14%     
==========================================
  Files         452      442      -10     
  Lines       17567    17530      -37     
==========================================
- Hits        12501    12500       -1     
+ Misses       5066     5030      -36     
Flag Coverage Δ
unittests-Instrumentation.Cassandra ?
unittests-Resources.Process 89.28% <86.36%> (-10.72%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...OpenTelemetry.Resources.Process/ProcessDetector.cs 88.46% <86.36%> (-11.54%) ⬇️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thompson-tomo thompson-tomo changed the title Feature/#2892 implement recomended process attr implement latest semconv spec for process resource #2892 Oct 28, 2025
@thompson-tomo thompson-tomo marked this pull request as ready for review October 28, 2025 10:23
@thompson-tomo thompson-tomo requested a review from a team as a code owner October 28, 2025 10:23
Comment on lines 46 to 51
attributes.Add(new(ProcessSemanticConventions.AttributeProcessStartTime, currentProcess.StartTime.ToString("O") ?? DateTime.Now.ToString("O")));
}
#endif
catch (Win32Exception)
{
attributes.Add(new(ProcessSemanticConventions.AttributeProcessStartTime, DateTime.Now.ToString("O")));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallbacks here are not true IMO. If you are not detect attributes, just omit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but in the case here creation time is an identifying attribute and all identifying should actually be required hence open-telemetry/weaver#986 to address it.

Also Using The current time enables the functionality of distinguishing between telemetry from process starts, leaving it out you lose that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack of the data is better than the wrong data.

Copy link
Contributor Author

@thompson-tomo thompson-tomo Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying that all the process entity attributes should be omitted if the creation time can not be set given it is an identifying attribute?

For me the exact value of the atrribute is not as meaningful as having a value there which can then be used to achieve the use case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not against keeping part of the attributes. Part of data seems to be fine. I am against putting obviously wrong data in the attributes/any other signal.

In this case, add this attribute conditionally if it is available. You can document it properly in the README. Small deviations from the semantics should be allowed if we have technical blockers for implementation.

Comment on lines 46 to 51
attributes.Add(new(ProcessSemanticConventions.AttributeProcessStartTime, currentProcess.StartTime.ToString("O") ?? DateTime.Now.ToString("O")));
}
#endif
catch (Win32Exception)
{
attributes.Add(new(ProcessSemanticConventions.AttributeProcessStartTime, DateTime.Now.ToString("O")));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack of the data is better than the wrong data.

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 12, 2025
@github-actions github-actions bot removed the Stale label Nov 13, 2025
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added Stale and removed Stale labels Nov 21, 2025
@Kielek Kielek changed the title implement latest semconv spec for process resource #2892 [Resources.Process] implement latest semantic convention spec Nov 28, 2025
new(ProcessSemanticConventions.AttributeProcessExecName, currentProcess.ProcessName),
new(ProcessSemanticConventions.AttributeProcessInteractive, Environment.UserInteractive),
#if NET
new(ProcessSemanticConventions.AttributeProcessPid, Environment.ProcessId),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have currentProcess.Id here. Is there any reason to go through Environment and potentially fetching process data from the scratch?

What is more, there will be common scenario both for .NET/non .NET

{
new(ProcessSemanticConventions.AttributeProcessOwner, Environment.UserName),
new(ProcessSemanticConventions.AttributeProcessArgsCount, Environment.GetCommandLineArgs().Length),
new(ProcessSemanticConventions.AttributeProcessTitle, currentProcess.MainWindowTitle),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it should be used here. Main windows title is not the process title. Check https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.mainwindowtitle?view=net-10.0

It is recommended attribute, so it can be omitted in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot have corrected how this is sourced.

new(ProcessSemanticConventions.AttributeProcessOwner, Environment.UserName),
new(ProcessSemanticConventions.AttributeProcessArgsCount, Environment.GetCommandLineArgs().Length),
new(ProcessSemanticConventions.AttributeProcessTitle, currentProcess.MainWindowTitle),
new(ProcessSemanticConventions.AttributeProcessWorkingDir, Environment.CurrentDirectory),
Copy link
Member

Choose a reason for hiding this comment

The 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.
alternative approach currentProcess.StartInfo.WorkingDirectory is not working while I was testing.

As it is conditionally required and we have AttributeProcessArgsCount, I would drop this attribute.

Copy link
Contributor Author

@thompson-tomo thompson-tomo Dec 4, 2025

Choose a reason for hiding this comment

The 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.AttributeProcessTitle, currentProcess.MainWindowTitle),
new(ProcessSemanticConventions.AttributeProcessWorkingDir, Environment.CurrentDirectory),

new(ProcessSemanticConventions.AttributeProcessExecName, currentProcess.ProcessName),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that it met SHOULD criteria from OTel sem. conv?
The name of the process executable. On Linux based systems, this SHOULD be set to the base name of the target of /proc/[pid]/exe. On Windows, this SHOULD be set to the base name of GetProcessImageFileNameW.

If not, it is conditionally required, and we have non-controversial in place AttributeProcessArgsCount. Potentially, it can be removed from this PR.

Copy link
Contributor Author

@thompson-tomo thompson-tomo Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have updated it to use the main module name.

new(ProcessSemanticConventions.AttributeProcessWorkingDir, Environment.CurrentDirectory),

new(ProcessSemanticConventions.AttributeProcessExecName, currentProcess.ProcessName),
new(ProcessSemanticConventions.AttributeProcessInteractive, Environment.UserInteractive),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that
https://learn.microsoft.com/en-us/dotnet/api/system.environment.userinteractive?view=net-10.0
is compliant with sem conf description: Whether the process is connected to an interactive shell.?

It can be omitted, as it is recommended attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but to further increase the checks, I now check if stdio is connected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:resources.process Things related to OpenTelemetry.Resources.Process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature request] update process resource detectors

4 participants