Skip to content

Commit

Permalink
Merge branch 'main' into xiang17/AddExceptionCounter
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang17 authored Jun 22, 2022
2 parents 419459a + ff1033a commit d232fa0
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 47 deletions.
1 change: 1 addition & 0 deletions build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<MicrosoftExtensionsLoggingPkgVer>[5.0,6.0)</MicrosoftExtensionsLoggingPkgVer>
<MicrosoftNETTestSdkPkgVer>[16.7.1,17.0)</MicrosoftNETTestSdkPkgVer>
<MoqPkgVer>[4.14.5,5.0)</MoqPkgVer>
<OpenTelemetryExporterInMemoryPkgVer>$(OpenTelemetryPkgVer)</OpenTelemetryExporterInMemoryPkgVer>
<XUnitRunnerVisualStudioPkgVer>[2.4.3,3.0)</XUnitRunnerVisualStudioPkgVer>
<XUnitPkgVer>[2.4.1,3.0)</XUnitPkgVer>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<MicrosoftOwinPkgVer>[4.1.1]</MicrosoftOwinPkgVer>
<MicrosoftPublicApiAnalyzersPkgVer>[3.3.2]</MicrosoftPublicApiAnalyzersPkgVer>
<MicrosoftSourceLinkGitHubPkgVer>[1.0.0,2.0)</MicrosoftSourceLinkGitHubPkgVer>
<OpenTelemetryExporterInMemoryPkgVer>1.3.0</OpenTelemetryExporterInMemoryPkgVer>
<OpenTelemetryApiPkgVer>[1.3.0,2.0)</OpenTelemetryApiPkgVer>
<OpenTelemetryPkgVer>$(OpenTelemetryApiPkgVer)</OpenTelemetryPkgVer>
<StackExchangeRedisPkgVer>[2.1.58,3.0)</StackExchangeRedisPkgVer>
<StyleCopAnalyzersPkgVer>[1.2.0-beta.354,2.0)</StyleCopAnalyzersPkgVer>
</PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions examples/redis/Examples.StackExchangeRedis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
using OpenTelemetry.Trace;
using StackExchange.Redis;

namespace GettingStartedPrometheusGrafana;

public class Program
{
public static void Main()
Expand Down
36 changes: 36 additions & 0 deletions examples/runtime-instrumentation/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <copyright file="Program.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using OpenTelemetry;
using OpenTelemetry.Metrics;

public class Program
{
public static void Main()
{
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddRuntimeMetrics()
.AddPrometheusExporter(options =>
{
options.StartHttpListener = true;
options.ScrapeResponseCacheDurationMilliseconds = 0;
})
.Build();

Console.WriteLine(".NET Runtime metrics are available at http://localhost:9464/metrics, press any key to exit...");
Console.ReadKey(false);
}
}
12 changes: 12 additions & 0 deletions examples/runtime-instrumentation/runtime-instrumentation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry.Exporter.Prometheus" Version="1.3.0-rc.2" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.Runtime\OpenTelemetry.Instrumentation.Runtime.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="OpenTelemetry" Version="1.1.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="1.3.0" />
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryPkgVer)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>;net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>;net462;netstandard2.0</TargetFrameworks>
<Description>OpenTelemetry Extensions - Container Resource Detector from Docker environment.</Description>
<MinVerTagPrefix>Extensions.Docker-</MinVerTagPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="1.2.0" />
<PackageReference Include="OpenTelemetry" Version="1.3.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Extensions.Docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var tracerProvider = Sdk.CreateTracerProviderBuilder()
The resource detectors will record the following metadata based on where
your application is running:

- **DockerResourceDetector**: container id.
- **DockerResourceDetector**: container.id.

## References

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## Unreleased

## 1.0.0-rc9.5 (source code moved to contrib repo)

Released 2022-Jun-21

* From this version onwards, the source code for this package would be hosted in
the
[contrib](/~https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule)
repo. The source code for this package before this version was hosted on the
[main](/~https://github.com/open-telemetry/opentelemetry-dotnet/tree/core-1.3.0/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule)
repo.

## 1.0.0-rc9.4

Released 2022-Jun-03
Expand All @@ -10,8 +21,9 @@ Released 2022-Jun-03

Released 2022-Apr-15

* Removes .NET Framework 4.6.1. The minimum .NET Framework
version supported is .NET 4.6.2. ([#3190](/~https://github.com/open-telemetry/opentelemetry-dotnet/issues/3190))
* Removes .NET Framework 4.6.1. The minimum .NET Framework version supported is
.NET 4.6.2.
([#3190](/~https://github.com/open-telemetry/opentelemetry-dotnet/issues/3190))

## 1.0.0-rc9.2

Expand Down
22 changes: 18 additions & 4 deletions src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## Unreleased

## 1.0.0-rc9.5 (source code moved to contrib repo)

Released 2022-Jun-21

* From this version onwards, the source code for this package would be hosted in
the
[contrib](/~https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Instrumentation.AspNet)
repo. The source code for this package before this version was hosted on the
[main](/~https://github.com/open-telemetry/opentelemetry-dotnet/tree/core-1.3.0/src/OpenTelemetry.Instrumentation.AspNet)
repo.

## 1.0.0-rc9.4

Released 2022-Jun-03
Expand All @@ -10,8 +21,9 @@ Released 2022-Jun-03

Released 2022-Apr-15

* Removes .NET Framework 4.6.1. The minimum .NET Framework
version supported is .NET 4.6.2. ([#3190](/~https://github.com/open-telemetry/opentelemetry-dotnet/issues/3190))
* Removes .NET Framework 4.6.1. The minimum .NET Framework version supported is
.NET 4.6.2.
([#3190](/~https://github.com/open-telemetry/opentelemetry-dotnet/issues/3190))

## 1.0.0-rc9.2

Expand Down Expand Up @@ -40,7 +52,8 @@ Released 2022-Feb-02
Released 2021-Oct-08

* Removes .NET Framework 4.5.2, .NET 4.6 support. The minimum .NET Framework
version supported is .NET 4.6.1. ([#2138](/~https://github.com/open-telemetry/opentelemetry-dotnet/issues/2138))
version supported is .NET 4.6.1.
([#2138](/~https://github.com/open-telemetry/opentelemetry-dotnet/issues/2138))

* Replaced `http.path` tag on activity with `http.target`.
([#2266](/~https://github.com/open-telemetry/opentelemetry-dotnet/pull/2266))
Expand Down Expand Up @@ -75,7 +88,8 @@ Released 2021-Jun-09

Released 2021-Apr-23

* Sanitize `http.url` attribute. ([#1961](/~https://github.com/open-telemetry/opentelemetry-dotnet/pull/1961))
* Sanitize `http.url` attribute.
([#1961](/~https://github.com/open-telemetry/opentelemetry-dotnet/pull/1961))

## 1.0.0-rc3

Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Instrumentation.Runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Update a few metrics to be in sync of doc updates for `gc.heap`,
`gc.fragmentation.ratio`, `time.in.jit`, `process.cpu.count` and `assembly.count`
([#430](/~https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/430))
* Add `exception.count` in Runtime metrics
([#431](/~https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/431))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462;netcoreapp3.1;net6.0</TargetFrameworks>
<Description>dotnet runtime instrumentation for OpenTelemetry .NET</Description>
<PackageTags>$(PackageTags);runtime</PackageTags>
<MinVerTagPrefix>Instrumentation.Runtime-</MinVerTagPrefix>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;netcoreapp3.1;net6.0</TargetFrameworks>
<Description>dotnet runtime instrumentation for OpenTelemetry .NET</Description>
<PackageTags>$(PackageTags);runtime</PackageTags>
<MinVerTagPrefix>Instrumentation.Runtime-</MinVerTagPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry.Api" Version="$(OpenTelemetryApiPkgVer)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry.Api" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>
</Project>
29 changes: 15 additions & 14 deletions src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ public RuntimeMetrics(RuntimeMetricsOptions options)

if (options.IsGcEnabled)
{
// TODO: Almost all the ObservableGauge should be ObservableUpDownCounter (except for CPU utilization and fragmentation.ratio.
// TODO: Almost all the ObservableGauge should be ObservableUpDownCounter (except for CPU utilization).
// Replace them once ObservableUpDownCounter is available.
this.meter.CreateObservableGauge($"{metricPrefix}gc.heap", () => GC.GetTotalMemory(false), "By", "GC Heap Size.");
this.meter.CreateObservableGauge($"{metricPrefix}gc.count", () => GetGarbageCollectionCounts(), description: "GC Count for all generations.");

#if NETCOREAPP3_1_OR_GREATER
this.meter.CreateObservableCounter($"{metricPrefix}gc.allocated.bytes", () => GC.GetTotalAllocatedBytes(), "By", "Allocation Rate.");
this.meter.CreateObservableGauge($"{metricPrefix}gc.fragmentation.ratio", GetFragmentation, description: "GC Fragmentation.");
#endif

#if NET6_0_OR_GREATER
this.meter.CreateObservableGauge($"{metricPrefix}gc.fragmentation.size", GetFragmentationSizes, description: "GC fragmentation.");
this.meter.CreateObservableGauge($"{metricPrefix}gc.committed", () => GC.GetGCMemoryInfo().TotalCommittedBytes, "By", description: "GC Committed Bytes.");
this.meter.CreateObservableGauge($"{metricPrefix}gc.heapsize", () => GetGarbageCollectionHeapSizes(), "By", "Heap size for all generations.");
#endif
Expand All @@ -70,7 +69,7 @@ public RuntimeMetrics(RuntimeMetricsOptions options)
{
this.meter.CreateObservableCounter($"{metricPrefix}il.bytes.jitted", () => System.Runtime.JitInfo.GetCompiledILBytes(), "By", description: "IL Bytes Jitted.");
this.meter.CreateObservableCounter($"{metricPrefix}methods.jitted.count", () => System.Runtime.JitInfo.GetCompiledMethodCount(), description: "Number of Methods Jitted.");
this.meter.CreateObservableGauge($"{metricPrefix}time.in.jit", () => System.Runtime.JitInfo.GetCompilationTime().Ticks * NanosecondsPerTick, "ns", description: "Time spent in JIT.");
this.meter.CreateObservableCounter($"{metricPrefix}time.in.jit", () => System.Runtime.JitInfo.GetCompilationTime().Ticks * NanosecondsPerTick, "ns", description: "Time spent in JIT.");
}
#endif

Expand All @@ -88,16 +87,13 @@ public RuntimeMetrics(RuntimeMetricsOptions options)
if (options.IsProcessEnabled)
{
this.meter.CreateObservableCounter("process.cpu.time", GetProcessorTimes, "s", "Processor time of this process.");

// Not yet official: /~https://github.com/open-telemetry/opentelemetry-specification/pull/2392
this.meter.CreateObservableGauge("process.cpu.count", () => (long)Environment.ProcessorCount, description: "The number of available logical CPUs.");
this.meter.CreateObservableGauge("process.memory.usage", () => Process.GetCurrentProcess().WorkingSet64, "By", "The amount of physical memory in use.");
this.meter.CreateObservableGauge("process.memory.virtual", () => Process.GetCurrentProcess().VirtualMemorySize64, "By", "The amount of committed virtual memory.");
}

if (options.IsAssembliesEnabled)
{
this.meter.CreateObservableCounter($"{metricPrefix}assembly.count", () => (long)AppDomain.CurrentDomain.GetAssemblies().Length, description: "Number of Assemblies Loaded.");
this.meter.CreateObservableGauge($"{metricPrefix}assembly.count", () => (long)AppDomain.CurrentDomain.GetAssemblies().Length, description: "Number of Assemblies Loaded.");
}

if (options.IsExceptionCountEnabled)
Expand All @@ -124,15 +120,20 @@ private static IEnumerable<Measurement<long>> GetGarbageCollectionCounts()
}
}

#if NETCOREAPP3_1_OR_GREATER
private static double GetFragmentation()
#if NET6_0_OR_GREATER
private static IEnumerable<Measurement<long>> GetFragmentationSizes()
{
var gcInfo = GC.GetGCMemoryInfo();
return gcInfo.HeapSizeBytes != 0 ? gcInfo.FragmentedBytes * 1.0d / gcInfo.HeapSizeBytes : 0;
var generationInfo = GC.GetGCMemoryInfo().GenerationInfo;
Measurement<long>[] measurements = new Measurement<long>[generationInfo.Length];
int maxSupportedLength = Math.Min(generationInfo.Length, GenNames.Length);
for (int i = 0; i < maxSupportedLength; ++i)
{
measurements[i] = new(generationInfo[i].FragmentationAfterBytes, new KeyValuePair<string, object>("gen", GenNames[i]));
}

return measurements;
}
#endif

#if NET6_0_OR_GREATER
private static IEnumerable<Measurement<long>> GetGarbageCollectionHeapSizes()
{
var generationInfo = GC.GetGCMemoryInfo().GenerationInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<Description>Unit test project for Docker Detector for OpenTelemetry</Description>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);net461</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);net462</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,12 @@ public void ProcessMetricsAreCaptured()

meterProvider.ForceFlush(MaxTimeToAllowForFlush);

Assert.Equal(4, exportedItems.Count);
Assert.Equal(3, exportedItems.Count);

var cpuTimeMetric = exportedItems.First(i => i.Name == "process.cpu.time");
var sumReceived = GetDoubleSum(cpuTimeMetric);
Assert.True(sumReceived > 0);

var cpuCountMetric = exportedItems.First(i => i.Name == "process.cpu.count");
Assert.Equal(Environment.ProcessorCount, (int)GetLongSum(cpuCountMetric));

var memoryMetric = exportedItems.First(i => i.Name == "process.memory.usage");
Assert.True(GetLongSum(memoryMetric) > 0);

Expand Down

0 comments on commit d232fa0

Please sign in to comment.