Skip to content

Commit

Permalink
Set ExemplarFilter in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan committed Oct 16, 2023
1 parent e918960 commit a9c4e76
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/metrics/exemplar/filter.h"
#include "opentelemetry/sdk/metrics/view/view_registry.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -107,6 +108,9 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>
std::unique_ptr<MeterSelector> meter_selector,
std::unique_ptr<View> view) noexcept;

void SetExemplarFilter(
std::unique_ptr<metrics::ExemplarFilter> exemplar_filter) noexcept;

/**
* NOTE - INTERNAL method, can change in future.
* Adds a meter to the list of configured meters in thread safe manner.
Expand Down Expand Up @@ -135,6 +139,7 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>
opentelemetry::sdk::resource::Resource resource_;
std::vector<std::shared_ptr<CollectorHandle>> collectors_;
std::unique_ptr<ViewRegistry> views_;
std::unique_ptr<metrics::ExemplarFilter> exemplar_filter_;
opentelemetry::common::SystemTimestamp sdk_start_ts_;
std::vector<std::shared_ptr<Meter>> meters_;

Expand Down
4 changes: 4 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/metrics/exemplar/filter.h"
#include "opentelemetry/sdk/metrics/view/view_registry.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -100,6 +101,9 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider
std::unique_ptr<MeterSelector> meter_selector,
std::unique_ptr<View> view) noexcept;

void SetExemplarFilter(
std::unique_ptr<metrics::ExemplarFilter> exemplar_filter) noexcept;

/**
* Shutdown the meter provider.
*/
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/metrics/meter_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ void MeterContext::AddView(std::unique_ptr<InstrumentSelector> instrument_select
views_->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view));
}

void MeterContext::SetExemplarFilter(
std::unique_ptr<metrics::ExemplarFilter> exemplar_filter) noexcept
{
exemplar_filter_ = std::move(exemplar_filter);
}

void MeterContext::AddMeter(std::shared_ptr<Meter> meter)
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(meter_lock_);
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/metrics/meter_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ void MeterProvider::AddView(std::unique_ptr<InstrumentSelector> instrument_selec
std::move(view));
}

void MeterProvider::SetExemplarFilter(
std::unique_ptr<metrics::ExemplarFilter> exemplar_filter) noexcept
{
return context_->SetExemplarFilter(std::move(exemplar_filter));
}

/**
* Shutdown the meter provider.
*/
Expand Down

0 comments on commit a9c4e76

Please sign in to comment.