Skip to content

Commit

Permalink
[Instrumentation.Process] Enable nullable (#892)
Browse files Browse the repository at this point in the history
* [Instrumentation.Process] Enable nullable

* PR feedback - avoid default parameter values

Co-authored-by: Alan West <[email protected]>
  • Loading branch information
Kielek and alanwest authored Jan 20, 2023
1 parent 68f3f90 commit 7e28bdf
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions
OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions.ProcessInstrumentationOptions() -> void
OpenTelemetry.Metrics.MeterProviderBuilderExtensions
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddProcessInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions> configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddProcessInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddProcessInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, System.Action<OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions!>! configure) -> OpenTelemetry.Metrics.MeterProviderBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ namespace OpenTelemetry.Metrics;
/// </summary>
public static class MeterProviderBuilderExtensions
{
/// <summary>
/// Enables runtime instrumentation.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddProcessInstrumentation(this MeterProviderBuilder builder) => AddProcessInstrumentationImplementation(builder, configure: null);

/// <summary>
/// Enables runtime instrumentation.
/// </summary>
Expand All @@ -33,7 +40,10 @@ public static class MeterProviderBuilderExtensions
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddProcessInstrumentation(
this MeterProviderBuilder builder,
Action<ProcessInstrumentationOptions> configure = null)
Action<ProcessInstrumentationOptions> configure) =>
AddProcessInstrumentationImplementation(builder, configure);

private static MeterProviderBuilder AddProcessInstrumentationImplementation(MeterProviderBuilder builder, Action<ProcessInstrumentationOptions>? configure)
{
Guard.ThrowIfNull(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PackageTags>$(PackageTags);process</PackageTags>
<MinVerTagPrefix>Instrumentation.Process-</MinVerTagPrefix>
<EnableAnalysis>true</EnableAnalysis>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);net462</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public void CheckValidGaugeValueWhen2MeterProviderInstancesHaveTheSameMeterName(
var metricA = exportedItemsA.FirstOrDefault(i => i.Name == "process.memory.usage");
var metricB = exportedItemsB.FirstOrDefault(i => i.Name == "process.memory.usage");

Assert.NotNull(metricA);
Assert.NotNull(metricB);

Assert.True(GetValue(metricA) > 0);
Assert.True(GetValue(metricB) > 0);
}
Expand Down Expand Up @@ -178,7 +181,6 @@ public void CheckValidGaugeValueWhen2MeterProviderInstancesHaveTheSameMeterName(

private static double GetValue(Metric metric)
{
Assert.NotNull(metric);
double sum = 0;

foreach (ref readonly var metricPoint in metric.GetMetricPoints())
Expand Down

0 comments on commit 7e28bdf

Please sign in to comment.