Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Increment the:
`std::mutex` blocks the waiter instead. Only this one contended lock changes;
the API `SpinLockMutex` and all other SDK locks are unchanged.
[#4245](https://github.com/open-telemetry/opentelemetry-cpp/pull/4245)

* [CONFIGURATION] Update ViewSelector to comply with schema v1.1.0
[#4384](https://github.com/open-telemetry/opentelemetry-cpp/pull/4384)

* [CONFIGURATION] Add the probability sampler to file configuration
[#4334](https://github.com/open-telemetry/opentelemetry-cpp/pull/4334)

Expand Down
114 changes: 114 additions & 0 deletions examples/configuration/kitchen-sink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,25 @@ meter_provider:
exporter:
# Configure exporter to be console.
console:
# Configure temporality preference.
# Values include: cumulative, delta, low_memory.
# If omitted or null, cumulative is used.
temporality_preference: delta
# Configure default histogram aggregation.
# Values include: explicit_bucket_histogram, base2_exponential_bucket_histogram.
# If omitted or null, explicit_bucket_histogram is used.
default_histogram_aggregation: base2_exponential_bucket_histogram
# Configure views.
# Each view has a selector which determines the instrument(s) it applies to, and a configuration for the resulting stream(s).
views:
- # Configure a catch-all view. An empty selector matches all instruments from all meters.
selector: {}
# Configure the resulting stream for every matched instrument.
stream:
# Retain all attributes except the explicitly excluded sensitive or high-cardinality keys.
attribute_keys:
excluded:
- request.id
- # Configure view selector.
# Selection criteria is additive as described in https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#instrument-selection-criteria.
selector:
Expand Down Expand Up @@ -543,6 +559,104 @@ meter_provider:
# If omitted, .attribute_keys.included are included.
excluded:
- key3
- selector:
instrument_name: exponential-histogram-instrument
instrument_type: histogram
stream:
# Configure aggregation to be base2 exponential bucket histogram.
aggregation:
base2_exponential_bucket_histogram:
# Configure the max scale factor. Value must be in range [-10, 20].
# If omitted or null, 20 is used.
max_scale: 20
# Configure the maximum number of positive and negative buckets.
# If omitted or null, 160 is used.
max_size: 160
# Configure whether or not to record min and max.
# If omitted or null, true is used.
record_min_max: true
- selector:
instrument_name: default-aggregation-instrument
stream:
# Configure aggregation based on the selected instrument kind.
aggregation:
default:
- selector:
instrument_name: dropped-instrument
stream:
# Configure aggregation to drop all measurements.
aggregation:
drop:
# Gauge instruments are only supported in opentelemetry-cpp ABIv2
# - selector:
# instrument_name: last-value-instrument
# instrument_type: gauge
# stream:
# # Configure aggregation to retain the last measurement.
# aggregation:
# last_value:
- selector:
instrument_name: summed-instrument
instrument_type: counter
stream:
# Configure aggregation to sum measurements.
aggregation:
sum:
- # Configure a view selecting observable counter instruments.
selector:
# Configure instrument name selection criteria.
instrument_name: observable-counter-instrument
# Configure instrument type selection criteria.
instrument_type: observable_counter
# Configure the resulting view stream.
stream:
# Configure aggregation based on the selected instrument kind.
aggregation:
default:
- # Configure a view selecting observable gauge instruments.
selector:
# Configure instrument name selection criteria.
instrument_name: observable-gauge-instrument
# Configure instrument type selection criteria.
instrument_type: observable_gauge
# Configure the resulting view stream.
stream:
# Configure aggregation based on the selected instrument kind.
aggregation:
default:
- # Configure a view selecting observable up down counter instruments.
selector:
# Configure instrument name selection criteria.
instrument_name: observable-up-down-counter-instrument
# Configure instrument type selection criteria.
instrument_type: observable_up_down_counter
# Configure the resulting view stream.
stream:
# Configure aggregation based on the selected instrument kind.
aggregation:
default:
- # Configure a view selecting up down counter instruments.
selector:
# Configure instrument name selection criteria.
instrument_name: up-down-counter-instrument
# Configure instrument type selection criteria.
instrument_type: up_down_counter
# Configure the resulting view stream.
stream:
# Configure aggregation based on the selected instrument kind.
aggregation:
default:
- # Configure a view selecting a histogram instrument.
selector:
# Configure instrument name selection criteria.
instrument_name: cardinality-limited-instrument
# Configure instrument type selection criteria.
instrument_type: histogram
# Configure the resulting view stream.
stream:
# Configure the aggregation cardinality limit while retaining the instrument's default aggregation.
# If omitted or null, the metric reader's default cardinality limit is used.
aggregation_cardinality_limit: 1000
# Configure the exemplar filter.
# Values include: trace_based, always_on, always_off. For behavior of values see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#metrics-sdk-configuration.
# If omitted or null, trace_based is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum class InstrumentType : std::uint8_t
{
none, /* Represents a null entry */
counter,
gauge,
histogram,
observable_counter,
observable_gauge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ViewSelectorConfiguration
{
public:
std::string instrument_name;
InstrumentType instrument_type{InstrumentType::counter};
InstrumentType instrument_type{InstrumentType::none};
std::string unit;
std::string meter_name;
std::string meter_version;
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/configuration/configuration_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,11 @@ InstrumentType ConfigurationParser::ParseInstrumentType(const std::unique_ptr<Do
return InstrumentType::counter;
}

if (name == "gauge")
{
return InstrumentType::gauge;
}

if (name == "histogram")
{
return InstrumentType::histogram;
Expand Down
161 changes: 97 additions & 64 deletions sdk/src/configuration/sdk_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,9 @@ static opentelemetry::sdk::metrics::InstrumentType ConvertInstrumentType(
case opentelemetry::sdk::configuration::InstrumentType::counter:
sdk = opentelemetry::sdk::metrics::InstrumentType::kCounter;
break;
case opentelemetry::sdk::configuration::InstrumentType::gauge:
sdk = opentelemetry::sdk::metrics::InstrumentType::kGauge;
break;
case opentelemetry::sdk::configuration::InstrumentType::histogram:
sdk = opentelemetry::sdk::metrics::InstrumentType::kHistogram;
break;
Expand Down Expand Up @@ -1909,94 +1912,124 @@ void SdkBuilder::AddView(
{
auto *selector = model->selector.get();

if (selector->instrument_type == opentelemetry::sdk::configuration::InstrumentType::none)
// Synchronous gauge instruments are not supported in ABIv1
#if OPENTELEMETRY_ABI_VERSION_NO < 2
if (selector->instrument_type == opentelemetry::sdk::configuration::InstrumentType::gauge)
{
std::string die("Runtime does not support instrument_type: null");
std::string die("Runtime does not support instrument_type: gauge with ABI version 1");
throw UnsupportedException(die);
}
#endif

auto sdk_instrument_type = ConvertInstrumentType(selector->instrument_type);
auto add_view = [&](opentelemetry::sdk::metrics::InstrumentType sdk_instrument_type) {
// If the instrument name is empty, use "*" to match all instruments of the given type.
const std::string instrument_name =
selector->instrument_name.empty() ? "*" : selector->instrument_name;

auto sdk_instrument_selector = std::make_unique<opentelemetry::sdk::metrics::InstrumentSelector>(
sdk_instrument_type, selector->instrument_name, selector->unit);
auto sdk_instrument_selector =
std::make_unique<opentelemetry::sdk::metrics::InstrumentSelector>(
sdk_instrument_type, instrument_name, selector->unit);

auto sdk_meter_selector = std::make_unique<opentelemetry::sdk::metrics::MeterSelector>(
selector->meter_name, selector->meter_version, selector->meter_schema_url);
auto sdk_meter_selector = std::make_unique<opentelemetry::sdk::metrics::MeterSelector>(
selector->meter_name, selector->meter_version, selector->meter_schema_url);

auto *stream = model->stream.get();
auto *stream = model->stream.get();

opentelemetry::sdk::metrics::AggregationType sdk_aggregation_type =
opentelemetry::sdk::metrics::AggregationType::kDefault;
opentelemetry::sdk::metrics::AggregationType sdk_aggregation_type =
opentelemetry::sdk::metrics::AggregationType::kDefault;

std::shared_ptr<opentelemetry::sdk::metrics::AggregationConfig> sdk_aggregation_config;
std::shared_ptr<opentelemetry::sdk::metrics::AggregationConfig> sdk_aggregation_config;

if (stream->aggregation)
{
sdk_aggregation_config = CreateAggregationConfig(stream->aggregation, sdk_aggregation_type);
}

// Apply aggregation_cardinality_limit from the view stream configuration
if (stream->aggregation_cardinality_limit != 0)
{
if (sdk_aggregation_config)
if (stream->aggregation)
{
sdk_aggregation_config->cardinality_limit_ = stream->aggregation_cardinality_limit;
sdk_aggregation_config = CreateAggregationConfig(stream->aggregation, sdk_aggregation_type);
}
else

// Apply aggregation_cardinality_limit from the view stream configuration
if (stream->aggregation_cardinality_limit != 0)
{
// No explicit `aggregation` block was configured, so the view falls back to the
// instrument's default aggregation. ViewRegistry::AddView() rejects a view whose
// AggregationConfig type does not match the (possibly instrument-derived) aggregation
// type, so the config created here must match that same default rather than always
// being a plain AggregationConfig (which only satisfies kSum/kLastValue/kDrop).
auto effective_aggregation_type = sdk_aggregation_type;
if (effective_aggregation_type == opentelemetry::sdk::metrics::AggregationType::kDefault)
if (sdk_aggregation_config)
{
bool is_monotonic{false};
effective_aggregation_type =
opentelemetry::sdk::metrics::DefaultAggregation::GetDefaultAggregationType(
sdk_instrument_type, is_monotonic);
sdk_aggregation_config->cardinality_limit_ = stream->aggregation_cardinality_limit;
}

switch (effective_aggregation_type)
else
{
case opentelemetry::sdk::metrics::AggregationType::kHistogram: {
auto histogram_config =
std::make_shared<opentelemetry::sdk::metrics::HistogramAggregationConfig>(
stream->aggregation_cardinality_limit);
// A default-constructed HistogramAggregationConfig has empty boundaries_, which
// LongHistogramAggregation/DoubleHistogramAggregation interpret as "use these zero
// boundaries" rather than "no boundaries configured" (that distinction only exists
// when the config pointer itself is null). Since this config is synthesized here
// rather than coming from an explicit `aggregation` block, it must carry the SDK's
// default boundaries to preserve the instrument's default histogram shape.
histogram_config->boundaries_ =
opentelemetry::sdk::metrics::HistogramAggregationConfig::DefaultBoundaries();
sdk_aggregation_config = histogram_config;
break;
// No explicit `aggregation` block was configured, so the view falls back to the
// instrument's default aggregation. ViewRegistry::AddView() rejects a view whose
// AggregationConfig type does not match the (possibly instrument-derived) aggregation
// type, so the config created here must match that same default rather than always
// being a plain AggregationConfig (which only satisfies kSum/kLastValue/kDrop).
auto effective_aggregation_type = sdk_aggregation_type;
if (effective_aggregation_type == opentelemetry::sdk::metrics::AggregationType::kDefault)
{
bool is_monotonic{false};
effective_aggregation_type =
opentelemetry::sdk::metrics::DefaultAggregation::GetDefaultAggregationType(
sdk_instrument_type, is_monotonic);
}

default:
sdk_aggregation_config = std::make_shared<opentelemetry::sdk::metrics::AggregationConfig>(
stream->aggregation_cardinality_limit);
break;
switch (effective_aggregation_type)
{
case opentelemetry::sdk::metrics::AggregationType::kHistogram: {
auto histogram_config =
std::make_shared<opentelemetry::sdk::metrics::HistogramAggregationConfig>(
stream->aggregation_cardinality_limit);
// A default-constructed HistogramAggregationConfig has empty boundaries_, which
// LongHistogramAggregation/DoubleHistogramAggregation interpret as "use these zero
// boundaries" rather than "no boundaries configured" (that distinction only exists
// when the config pointer itself is null). Since this config is synthesized here
// rather than coming from an explicit `aggregation` block, it must carry the SDK's
// default boundaries to preserve the instrument's default histogram shape.
histogram_config->boundaries_ =
opentelemetry::sdk::metrics::HistogramAggregationConfig::DefaultBoundaries();
sdk_aggregation_config = histogram_config;
break;
}

default:
sdk_aggregation_config =
std::make_shared<opentelemetry::sdk::metrics::AggregationConfig>(
stream->aggregation_cardinality_limit);
break;
}
}
}
}

std::unique_ptr<opentelemetry::sdk::metrics::AttributesProcessor> sdk_attribute_processor;
std::unique_ptr<opentelemetry::sdk::metrics::AttributesProcessor> sdk_attribute_processor;

if (stream->attribute_keys != nullptr)
{
sdk_attribute_processor = CreateAttributesProcessor(stream->attribute_keys);
}
// FIXME-SDK: The CreateAttributesProcessor method is not implemented yet.
if (stream->attribute_keys != nullptr)
{
sdk_attribute_processor = CreateAttributesProcessor(stream->attribute_keys);
}

auto sdk_view = std::make_unique<opentelemetry::sdk::metrics::View>(
stream->name, stream->description, sdk_aggregation_type, sdk_aggregation_config,
std::move(sdk_attribute_processor));

auto sdk_view = std::make_unique<opentelemetry::sdk::metrics::View>(
stream->name, stream->description, sdk_aggregation_type, sdk_aggregation_config,
std::move(sdk_attribute_processor));
view_registry->AddView(std::move(sdk_instrument_selector), std::move(sdk_meter_selector),
std::move(sdk_view));
}; // add_view

view_registry->AddView(std::move(sdk_instrument_selector), std::move(sdk_meter_selector),
std::move(sdk_view));
// If the instrument type is "none", add views to select all instrument types.
// FIXME-SDK: register a single view instead. InstrumentSelector must support an optional
// instrument type (a "match all types" value honored by ViewRegistry::MatchInstrument).
if (selector->instrument_type == opentelemetry::sdk::configuration::InstrumentType::none)
{
add_view(opentelemetry::sdk::metrics::InstrumentType::kCounter);
add_view(opentelemetry::sdk::metrics::InstrumentType::kHistogram);
add_view(opentelemetry::sdk::metrics::InstrumentType::kUpDownCounter);
add_view(opentelemetry::sdk::metrics::InstrumentType::kObservableCounter);
add_view(opentelemetry::sdk::metrics::InstrumentType::kObservableGauge);
add_view(opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter);
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
add_view(opentelemetry::sdk::metrics::InstrumentType::kGauge);
#endif
}
else
{
add_view(ConvertInstrumentType(selector->instrument_type));
}
}

std::unique_ptr<opentelemetry::sdk::instrumentationscope::ScopeConfigurator<
Expand Down
Loading
Loading