Skip to content

Commit 9e821be

Browse files
[Resources.Process] Remove process.command
`process.command` isn't reliable with the different modes of executing modern .NET processes.
1 parent bda2f4c commit 9e821be

3 files changed

Lines changed: 6 additions & 19 deletions

File tree

src/OpenTelemetry.Resources.Process/CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
([#4080](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4080))
77

88
* Add new process resource attributes: `process.args_count`,
9-
`process.command`, `process.creation.time`,
10-
`process.executable.path`, `process.title` and
11-
`process.working_directory`.
9+
`process.creation.time`, `process.executable.path`,
10+
`process.title` and `process.working_directory`.
1211
([#4036](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4036))
1312

1413
## 1.15.0-beta.1

src/OpenTelemetry.Resources.Process/ProcessDetector.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,9 @@ public Resource Detect()
4848
// See https://github.com/open-telemetry/semantic-conventions/blob/v1.40.0/docs/resource/process.md#selecting-process-attributes.
4949
var commandArgs = GetCommandLineArgs();
5050

51-
if (commandArgs.Length > 0)
51+
if (commandArgs is not null)
5252
{
53-
#if NET
54-
processPath ??= commandArgs[0];
55-
#else
56-
processPath = commandArgs[0];
57-
#endif
58-
59-
attributes.Add(new(ProcessSemanticConventions.AttributeProcessCommand, commandArgs[0]));
60-
61-
// Do not count the executable path as an argument
62-
int count = commandArgs.Length - 1;
63-
64-
attributes.Add(new(ProcessSemanticConventions.AttributeProcessArgsCount, count));
53+
attributes.Add(new(ProcessSemanticConventions.AttributeProcessArgsCount, commandArgs.Length));
6554
}
6655

6756
if (!string.IsNullOrEmpty(processPath))
@@ -71,15 +60,15 @@ public Resource Detect()
7160

7261
return new Resource(attributes);
7362

74-
static string[] GetCommandLineArgs()
63+
static string[]? GetCommandLineArgs()
7564
{
7665
try
7766
{
7867
return Environment.GetCommandLineArgs();
7968
}
8069
catch (NotSupportedException)
8170
{
82-
return [];
71+
return null;
8372
}
8473
}
8574

test/OpenTelemetry.Resources.Process.Tests/ProcessDetectorTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public void TestProcessAttributes()
1515
var resourceAttributes = resource.Attributes.ToDictionary(x => x.Key, x => x.Value);
1616

1717
Assert.IsType<long>(resourceAttributes[ProcessSemanticConventions.AttributeProcessArgsCount]);
18-
Assert.IsType<string>(resourceAttributes[ProcessSemanticConventions.AttributeProcessCommand]);
1918
Assert.IsType<string>(resourceAttributes[ProcessSemanticConventions.AttributeProcessCreationTime]);
2019
Assert.IsType<string>(resourceAttributes[ProcessSemanticConventions.AttributeProcessExecutablePath]);
2120
Assert.IsType<string>(resourceAttributes[ProcessSemanticConventions.AttributeProcessOwner]);

0 commit comments

Comments
 (0)