Skip to content

Commit

Permalink
validate double value
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Sep 29, 2023
1 parent 6ac46fb commit b6909af
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions sdk/src/metrics/sync_instruments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,32 @@ DoubleCounter::DoubleCounter(InstrumentDescriptor instrument_descriptor,
void DoubleCounter::Add(double value,
const opentelemetry::common::KeyValueIterable &attributes) noexcept
{
auto context = opentelemetry::context::Context{};
if (double < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A)] Value not recorded - invalid storage for: "
<< instrument_descriptor_.name_);
return;
}
auto context = opentelemetry::context::Context{};
return storage_->RecordDouble(value, attributes, context);
}

void DoubleCounter::Add(double value,
const opentelemetry::common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept
{
if (double < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A,C)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,A,C)] Value not recorded - invalid storage for: "
Expand All @@ -110,18 +122,30 @@ void DoubleCounter::Add(double value,

void DoubleCounter::Add(double value) noexcept
{
auto context = opentelemetry::context::Context{};
if (double < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V)] Value not recorded - invalid storage for: "
<< instrument_descriptor_.name_);
return;
}
auto context = opentelemetry::context::Context{};
return storage_->RecordDouble(value, context);
}

void DoubleCounter::Add(double value, const opentelemetry::context::Context &context) noexcept
{
if (double < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleCounter::Add(V,C)] Value not recorded - invalid storage for: "
Expand Down Expand Up @@ -338,6 +362,13 @@ void DoubleHistogram::Record(double value,
const opentelemetry::common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN(
"[DoubleHistogram::Record(V,A,C)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN(
Expand All @@ -350,6 +381,13 @@ void DoubleHistogram::Record(double value,

void DoubleHistogram::Record(double value, const opentelemetry::context::Context &context) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN(
"[DoubleHistogram::Record(V,C)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN(
Expand All @@ -364,6 +402,13 @@ void DoubleHistogram::Record(double value, const opentelemetry::context::Context
void DoubleHistogram::Record(double value,
const opentelemetry::common::KeyValueIterable &attributes) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN(
"[DoubleHistogram::Record(V,A)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN(
Expand All @@ -377,6 +422,12 @@ void DoubleHistogram::Record(double value,

void DoubleHistogram::Record(double value) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleHistogram::Record(V)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleHistogram::Record(V)] Value not recorded - invalid storage for: "
Expand Down Expand Up @@ -466,6 +517,12 @@ void DoubleGauge::Record(double value,
const opentelemetry::common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,A,C)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,A,C)] Value not recorded - invalid storage for: "
Expand All @@ -477,6 +534,12 @@ void DoubleGauge::Record(double value,

void DoubleGauge::Record(double value, const opentelemetry::context::Context &context) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,C)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,C)] Value not recorded - invalid storage for: "
Expand All @@ -489,6 +552,12 @@ void DoubleGauge::Record(double value, const opentelemetry::context::Context &co
void DoubleGauge::Record(double value,
const opentelemetry::common::KeyValueIterable &attributes) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,A)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,A)] Value not recorded - invalid storage for: "
Expand All @@ -501,6 +570,12 @@ void DoubleGauge::Record(double value,

void DoubleGauge::Record(double value) noexcept
{
if (value < 0)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V)] Value not recorded - negative value for: "
<< instrument_descriptor_.name_);
return;
}
if (!storage_)
{
OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V)] Value not recorded - invalid storage for: "
Expand Down

0 comments on commit b6909af

Please sign in to comment.