From 9afda7b080214b4658e4bd32ce1f2842a461685d Mon Sep 17 00:00:00 2001 From: Lalit Date: Thu, 24 Oct 2024 23:36:13 -0700 Subject: [PATCH 1/6] initial commit --- opentelemetry-sdk/src/metrics/view.rs | 31 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/view.rs b/opentelemetry-sdk/src/metrics/view.rs index d9f256bd2b..8602769357 100644 --- a/opentelemetry-sdk/src/metrics/view.rs +++ b/opentelemetry-sdk/src/metrics/view.rs @@ -1,8 +1,8 @@ use super::instrument::{Instrument, Stream}; use glob::Pattern; use opentelemetry::{ - global, metrics::{MetricsError, Result}, + otel_warn, }; fn empty_view(_inst: &Instrument) -> Option { @@ -102,9 +102,12 @@ impl View for Box { /// ``` pub fn new_view(criteria: Instrument, mask: Stream) -> Result> { if criteria.is_empty() { - global::handle_error(MetricsError::Config(format!( - "no criteria provided, dropping view. mask: {mask:?}" - ))); + otel_warn!( + name: "View.ConfigError.NoCriteriaProvided", + message= "no criteria provided, dropping view", + criteria = format!("{:?}", criteria), + mask = format!("{:?}", mask), + ); return Ok(Box::new(empty_view)); } let contains_wildcard = criteria.name.contains(['*', '?']); @@ -112,9 +115,12 @@ pub fn new_view(criteria: Instrument, mask: Stream) -> Result> { let match_fn: Box bool + Send + Sync> = if contains_wildcard { if mask.name != "" { - global::handle_error(MetricsError::Config(format!( - "name replacement for multiple instruments, dropping view, criteria: {criteria:?}, mask: {mask:?}" - ))); + otel_warn!( + name: "View.ConfigError.NameReplacementMultipleInstruments", + message = "name replacement for multiple instruments, dropping view", + criteria = format!("{:?}", criteria), + mask = format!("{:?}", mask), + ); return Ok(Box::new(empty_view)); } @@ -138,10 +144,13 @@ pub fn new_view(criteria: Instrument, mask: Stream) -> Result> { match ma.validate() { Ok(_) => agg = Some(ma.clone()), Err(err) => { - global::handle_error(MetricsError::Other(format!( - "{}, proceeding as if view did not exist. criteria: {:?}, mask: {:?}", - err, err_msg_criteria, mask - ))); + otel_warn!( + name: "View.AggregationValidationFailed", + message = "failed to validate aggregation, proceeding as if view did not exist", + criteria = format!("{:?}", err_msg_criteria), + mask = format!("{:?}", mask), + reason = format!("{:?}", err), + ); return Ok(Box::new(empty_view)); } } From 595181cb818f0f53a5b142438970e456da92e4c7 Mon Sep 17 00:00:00 2001 From: Lalit Date: Thu, 24 Oct 2024 23:38:45 -0700 Subject: [PATCH 2/6] fix --- opentelemetry-sdk/src/metrics/view.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/view.rs b/opentelemetry-sdk/src/metrics/view.rs index 8602769357..ef279dc63b 100644 --- a/opentelemetry-sdk/src/metrics/view.rs +++ b/opentelemetry-sdk/src/metrics/view.rs @@ -103,7 +103,7 @@ impl View for Box { pub fn new_view(criteria: Instrument, mask: Stream) -> Result> { if criteria.is_empty() { otel_warn!( - name: "View.ConfigError.NoCriteriaProvided", + name: "View.NoCriteriaProvided", message= "no criteria provided, dropping view", criteria = format!("{:?}", criteria), mask = format!("{:?}", mask), @@ -116,7 +116,7 @@ pub fn new_view(criteria: Instrument, mask: Stream) -> Result> { let match_fn: Box bool + Send + Sync> = if contains_wildcard { if mask.name != "" { otel_warn!( - name: "View.ConfigError.NameReplacementMultipleInstruments", + name: "View.NameReplacementMultipleInstruments", message = "name replacement for multiple instruments, dropping view", criteria = format!("{:?}", criteria), mask = format!("{:?}", mask), From 70ab68041697c3412068e82160c0f12a6936562b Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 25 Oct 2024 22:34:50 -0700 Subject: [PATCH 3/6] Update view.rs --- opentelemetry-sdk/src/metrics/view.rs | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/view.rs b/opentelemetry-sdk/src/metrics/view.rs index ef279dc63b..a08b156f0f 100644 --- a/opentelemetry-sdk/src/metrics/view.rs +++ b/opentelemetry-sdk/src/metrics/view.rs @@ -102,25 +102,15 @@ impl View for Box { /// ``` pub fn new_view(criteria: Instrument, mask: Stream) -> Result> { if criteria.is_empty() { - otel_warn!( - name: "View.NoCriteriaProvided", - message= "no criteria provided, dropping view", - criteria = format!("{:?}", criteria), - mask = format!("{:?}", mask), - ); - return Ok(Box::new(empty_view)); + // TODO - The error is getting lost here. Need to return or log. + return Ok(Box::new(empty_view)); } let contains_wildcard = criteria.name.contains(['*', '?']); let err_msg_criteria = criteria.clone(); let match_fn: Box bool + Send + Sync> = if contains_wildcard { if mask.name != "" { - otel_warn!( - name: "View.NameReplacementMultipleInstruments", - message = "name replacement for multiple instruments, dropping view", - criteria = format!("{:?}", criteria), - mask = format!("{:?}", mask), - ); + // TODO - The error is getting lost here. Need to return or log. return Ok(Box::new(empty_view)); } @@ -144,13 +134,7 @@ pub fn new_view(criteria: Instrument, mask: Stream) -> Result> { match ma.validate() { Ok(_) => agg = Some(ma.clone()), Err(err) => { - otel_warn!( - name: "View.AggregationValidationFailed", - message = "failed to validate aggregation, proceeding as if view did not exist", - criteria = format!("{:?}", err_msg_criteria), - mask = format!("{:?}", mask), - reason = format!("{:?}", err), - ); + // TODO - The error is getting lost here. Need to return or log. return Ok(Box::new(empty_view)); } } From f112259e0fdbe484ff4fdc68b1d72f28ae685f56 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 25 Oct 2024 22:35:22 -0700 Subject: [PATCH 4/6] Update view.rs --- opentelemetry-sdk/src/metrics/view.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/opentelemetry-sdk/src/metrics/view.rs b/opentelemetry-sdk/src/metrics/view.rs index a08b156f0f..24eb1d15fc 100644 --- a/opentelemetry-sdk/src/metrics/view.rs +++ b/opentelemetry-sdk/src/metrics/view.rs @@ -2,7 +2,6 @@ use super::instrument::{Instrument, Stream}; use glob::Pattern; use opentelemetry::{ metrics::{MetricsError, Result}, - otel_warn, }; fn empty_view(_inst: &Instrument) -> Option { From 707a34efca7cec5da456624524803dc69f0792f1 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 25 Oct 2024 22:43:23 -0700 Subject: [PATCH 5/6] Update view.rs --- opentelemetry-sdk/src/metrics/view.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/metrics/view.rs b/opentelemetry-sdk/src/metrics/view.rs index f512f1cdad..1608b4e2fe 100644 --- a/opentelemetry-sdk/src/metrics/view.rs +++ b/opentelemetry-sdk/src/metrics/view.rs @@ -1,6 +1,6 @@ use super::instrument::{Instrument, Stream}; use glob::Pattern; -use opentelemetry::metrics::{MetricError, MetricResult}, +use opentelemetry::metrics::{MetricError, MetricResult}; fn empty_view(_inst: &Instrument) -> Option { None From cd57696c51afb8b0f09fd85ad6835db30bf3fa58 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 25 Oct 2024 22:47:18 -0700 Subject: [PATCH 6/6] lint error --- opentelemetry-sdk/src/metrics/view.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/view.rs b/opentelemetry-sdk/src/metrics/view.rs index 1608b4e2fe..3913412cb7 100644 --- a/opentelemetry-sdk/src/metrics/view.rs +++ b/opentelemetry-sdk/src/metrics/view.rs @@ -103,7 +103,6 @@ pub fn new_view(criteria: Instrument, mask: Stream) -> MetricResult bool + Send + Sync> = if contains_wildcard { if mask.name != "" { @@ -130,7 +129,7 @@ pub fn new_view(criteria: Instrument, mask: Stream) -> MetricResult agg = Some(ma.clone()), - Err(err) => { + Err(_) => { // TODO - The error is getting lost here. Need to return or log. return Ok(Box::new(empty_view)); }