From eb8844a7ec690a4148adbdb765bad23e0c533b78 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Wed, 18 May 2022 04:58:12 -0700 Subject: [PATCH] Add null check when a view does not match an instrument (#3285) * Add null check when a view does not match an instrument * Update changelog --- src/OpenTelemetry/CHANGELOG.md | 3 +++ src/OpenTelemetry/Metrics/MeterProviderSdk.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index e8defa1924b..58f6682bb88 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Fix null reference exception when a metric view does not match an instrument. + ([#3285](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3285)) + ## 1.3.0-beta.2 Released 2022-May-16 diff --git a/src/OpenTelemetry/Metrics/MeterProviderSdk.cs b/src/OpenTelemetry/Metrics/MeterProviderSdk.cs index 7906e27e532..437685f32a4 100644 --- a/src/OpenTelemetry/Metrics/MeterProviderSdk.cs +++ b/src/OpenTelemetry/Metrics/MeterProviderSdk.cs @@ -167,7 +167,7 @@ internal MeterProviderSdk( // The SDK provides some static MetricStreamConfigurations. // For example, the Drop configuration. The static ViewId // should not be changed for these configurations. - if (!metricStreamConfig.ViewId.HasValue) + if (metricStreamConfig != null && !metricStreamConfig.ViewId.HasValue) { metricStreamConfig.ViewId = i; }