Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

* Add instrumentation scope version and schema URL to metrics.
([#4088](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4088))

* Removed the `process.cpu.count` metric as it is not part of
the semantic conventions. Use the
[`dotnet.process.cpu.count`](https://github.com/open-telemetry/semantic-conventions/blob/v1.41.0/docs/runtime/dotnet-metrics.md#metric-dotnetprocesscpucount)
metric as an alternative.
([#4088](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4088))

## 1.15.1-beta.1

Released 2026-Apr-21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static MeterProviderBuilder AddProcessInstrumentation(
{
Guard.ThrowIfNull(builder);

builder.AddMeter(ProcessMetrics.MeterName);
builder.AddMeter(ProcessMetrics.MeterInstance.Name);
return builder.AddInstrumentation(() => new ProcessMetrics());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\AssemblyVersionExtensions.cs" Link="Includes\AssemblyVersionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\Shared\MeterFactory.cs" Link="Includes\MeterFactory.cs" />
</ItemGroup>

</Project>
20 changes: 2 additions & 18 deletions src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics.Metrics;
using System.Reflection;
using OpenTelemetry.Internal;
using Diagnostics = System.Diagnostics;

namespace OpenTelemetry.Instrumentation.Process;

internal sealed class ProcessMetrics
{
internal static readonly Assembly Assembly = typeof(ProcessMetrics).Assembly;
internal static readonly AssemblyName AssemblyName = Assembly.GetName();
#pragma warning disable IDE0370 // Suppression is unnecessary
internal static readonly string MeterName = AssemblyName.Name!;
#pragma warning restore IDE0370 // Suppression is unnecessary

private static readonly Meter MeterInstance = new(MeterName, Assembly.GetPackageVersion());
internal static readonly Version SemanticConventionsVersion = new(1, 25, 0);
internal static readonly Meter MeterInstance = Metrics.MeterFactory.Create<ProcessMetrics>(SemanticConventionsVersion);

static ProcessMetrics()
{
Expand Down Expand Up @@ -54,15 +47,6 @@ static ProcessMetrics()
unit: "s",
description: "Total CPU seconds broken down by different states.");

MeterInstance.CreateObservableUpDownCounter(
"process.cpu.count",
() =>
{
return Environment.ProcessorCount;
},
unit: "{processors}",
description: "The number of processors (CPU cores) available to the current process.");

MeterInstance.CreateObservableUpDownCounter(
"process.thread.count",
() =>
Expand Down
18 changes: 0 additions & 18 deletions src/OpenTelemetry.Instrumentation.Process/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,6 @@ Gets the user processor time for this process.
* [Process.PrivilegedProcessorTime](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.privilegedprocessortime):
Gets the privileged processor time for this process.

### process.cpu.count

The number of processors (CPU cores) available to the current process.

| Units | Instrument Type | Value Type |
| ------------- | ----------------------- | ---------- |
| `{processors}`| ObservableUpDownCounter | `Int32` |

The API used to retrieve the value is
[System.Environment.ProcessorCount](https://learn.microsoft.com/dotnet/api/system.environment.processorcount).

> [!NOTE]
> This metric is under
> [discussion](https://github.com/open-telemetry/opentelemetry-specification/issues/3200)
and not part of the [Process Metrics
Spec](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/process-metrics.md)
at this time.

### process.thread.count

Process threads count.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ public void ProcessMetricsAreCaptured()

meterProviderA.ForceFlush(MaxTimeToAllowForFlush);

Assert.Equal(5, exportedItemsA.Count);
var physicalMemoryMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.usage");
Assert.NotNull(physicalMemoryMetric);
var virtualMemoryMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.virtual");
Assert.NotNull(virtualMemoryMetric);
var cpuTimeMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.time");
Assert.NotNull(cpuTimeMetric);
var processorCountMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.count");
Assert.NotNull(processorCountMetric);
var threadMetric = exportedItemsA.FirstOrDefault(i => i.Name == "process.thread.count");
Assert.NotNull(threadMetric);
Assert.Equal(4, exportedItemsA.Count);

exportedItemsA.Clear();

Expand All @@ -51,8 +49,11 @@ public void ProcessMetricsAreCaptured()

meterProviderB.ForceFlush(MaxTimeToAllowForFlush);

Assert.Equal(5, exportedItemsA.Count);
Assert.Equal(5, exportedItemsB.Count);
Assert.Equal(4, exportedItemsA.Count);
Assert.Equal(4, exportedItemsB.Count);

AssertMetrics(exportedItemsA);
AssertMetrics(exportedItemsB);
}

[Fact]
Expand Down Expand Up @@ -129,29 +130,28 @@ public async Task ProcessMetricsAreCapturedWhenTasksOverlap()

await Task.WhenAll(tasks);

Assert.Equal(5, exportedItemsA.Count);
var physicalMemoryMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.usage");
Assert.NotNull(physicalMemoryMetricA);
var virtualMemoryMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.virtual");
Assert.NotNull(virtualMemoryMetricA);
var cpuTimeMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.time");
Assert.NotNull(cpuTimeMetricA);
var processorCountMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.cpu.count");
Assert.NotNull(processorCountMetricA);
var threadMetricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.thread.count");
Assert.NotNull(threadMetricA);
Assert.Equal(4, exportedItemsA.Count);

Assert.Equal(5, exportedItemsB.Count);
var physicalMemoryMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.memory.usage");
Assert.NotNull(physicalMemoryMetricB);
var virtualMemoryMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.memory.virtual");
Assert.NotNull(virtualMemoryMetricB);
var cpuTimeMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.cpu.time");
Assert.NotNull(cpuTimeMetricB);
var processorCountMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.cpu.count");
Assert.NotNull(processorCountMetricB);
var threadMetricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.thread.count");
Assert.NotNull(threadMetricB);
Assert.Equal(4, exportedItemsB.Count);

AssertMetrics(exportedItemsA);
AssertMetrics(exportedItemsB);
}

[Fact]
Expand Down Expand Up @@ -221,4 +221,14 @@ private static double GetValue(Metric metric)

return sum;
}

private static void AssertMetrics(IEnumerable<Metric> metrics)
{
foreach (var metric in metrics)
{
Assert.NotNull(metric.MeterVersion);
Assert.NotEmpty(metric.MeterVersion);
Assert.StartsWith("https://opentelemetry.io/schemas/", metric.MeterSchemaUrl);
}
}
}
Loading