Skip to content
Open
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
10 changes: 5 additions & 5 deletions api/include/opentelemetry/metrics/multi_observer_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ class MultiObserverResult
* @return An ObserverResultT<T> for the given instrument.
*/
template <typename T>
ObserverResultT<T> &ForInstrument(const ObservableInstrument *instrument) = delete;
ObserverResultT<T> &ForInstrument(ObservableInstrument *instrument) = delete;

protected:
// You can't have a virtual template, and you can't overload on return type, so we need to
// enumerate the options for the observer result type as separate methods to override.
virtual ObserverResultT<double> &ForInstrumentDouble(const ObservableInstrument *instrument) = 0;
virtual ObserverResultT<int64_t> &ForInstrumentInt64(const ObservableInstrument *instrument) = 0;
virtual ObserverResultT<double> &ForInstrumentDouble(ObservableInstrument *instrument) = 0;
virtual ObserverResultT<int64_t> &ForInstrumentInt64(ObservableInstrument *instrument) = 0;
};

template <>
inline ObserverResultT<double> &MultiObserverResult::ForInstrument<double>(
const ObservableInstrument *instrument)
ObservableInstrument *instrument)
{
return ForInstrumentDouble(instrument);
}

template <>
inline ObserverResultT<int64_t> &MultiObserverResult::ForInstrument<int64_t>(
const ObservableInstrument *instrument)
ObservableInstrument *instrument)
{
return ForInstrumentInt64(instrument);
}
Expand Down
4 changes: 1 addition & 3 deletions examples/http/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback
std::string span_name = request.uri;

// extract context from http header
std::map<std::string, std::string> &request_headers =
const_cast<std::map<std::string, std::string> &>(request.headers);
const HttpTextMapCarrier<std::map<std::string, std::string>> carrier(request_headers);
const HttpTextMapCarrier<std::map<std::string, std::string>> carrier(request.headers);
auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator();
auto current_ctx = context::RuntimeContext::GetCurrent();
auto new_context = prop->Extract(carrier, current_ctx);
Expand Down
2 changes: 1 addition & 1 deletion examples/http/tracer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ template <typename T>
class HttpTextMapCarrier : public opentelemetry::context::propagation::TextMapCarrier
{
public:
HttpTextMapCarrier(T &headers) : headers_(headers) {}
HttpTextMapCarrier(const T &headers) : headers_(headers) {}
HttpTextMapCarrier() = default;
opentelemetry::nostd::string_view Get(
opentelemetry::nostd::string_view key) const noexcept override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,11 @@ class HttpOperation
inline CURL *GetCurlEasyHandle() noexcept { return curl_resource_.easy_handle; }

private:
CURLcode SetCurlPtrOption(CURLoption option, void *value);
CURLcode SetCurlPtrOption(CURLoption option, const void *value);

CURLcode SetCurlStrOption(CURLoption option, const char *str)
{
void *ptr = const_cast<char *>(str);
return SetCurlPtrOption(option, ptr);
return SetCurlPtrOption(option, str);
}

CURLcode SetCurlBlobOption(CURLoption option, struct curl_blob *blob)
Expand Down
26 changes: 13 additions & 13 deletions ext/src/http/client/curl/http_operation_curl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ const char *HttpOperation::GetCurlErrorMessage(CURLcode code)
return message;
}

CURLcode HttpOperation::SetCurlPtrOption(CURLoption option, void *value)
CURLcode HttpOperation::SetCurlPtrOption(CURLoption option, const void *value)
{
/*
curl_easy_setopt() is a macro with variadic arguments, type unsafe.
Expand Down Expand Up @@ -907,13 +907,13 @@ CURLcode HttpOperation::Setup()
else if (!ssl_options_.ssl_ca_cert_string.empty())
{
#if LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(7, 77, 0)
const char *data = ssl_options_.ssl_ca_cert_string.c_str();
size_t data_len = ssl_options_.ssl_ca_cert_string.length();
std::vector<char> blob_data(ssl_options_.ssl_ca_cert_string.begin(),
ssl_options_.ssl_ca_cert_string.end());

struct curl_blob stblob
{};
stblob.data = const_cast<char *>(data);
stblob.len = data_len;
stblob.data = blob_data.data();
stblob.len = blob_data.size();
stblob.flags = CURL_BLOB_COPY;

rc = SetCurlBlobOption(CURLOPT_CAINFO_BLOB, &stblob);
Expand Down Expand Up @@ -949,13 +949,13 @@ CURLcode HttpOperation::Setup()
else if (!ssl_options_.ssl_client_key_string.empty())
{
#if LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(7, 71, 0)
const char *data = ssl_options_.ssl_client_key_string.c_str();
size_t data_len = ssl_options_.ssl_client_key_string.length();
std::vector<char> blob_data(ssl_options_.ssl_client_key_string.begin(),
ssl_options_.ssl_client_key_string.end());

struct curl_blob stblob
{};
stblob.data = const_cast<char *>(data);
stblob.len = data_len;
stblob.data = blob_data.data();
stblob.len = blob_data.size();
stblob.flags = CURL_BLOB_COPY;

rc = SetCurlBlobOption(CURLOPT_SSLKEY_BLOB, &stblob);
Expand Down Expand Up @@ -997,13 +997,13 @@ CURLcode HttpOperation::Setup()
else if (!ssl_options_.ssl_client_cert_string.empty())
{
#if LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(7, 71, 0)
const char *data = ssl_options_.ssl_client_cert_string.c_str();
size_t data_len = ssl_options_.ssl_client_cert_string.length();
std::vector<char> blob_data(ssl_options_.ssl_client_cert_string.begin(),
ssl_options_.ssl_client_cert_string.end());

struct curl_blob stblob
{};
stblob.data = const_cast<char *>(data);
stblob.len = data_len;
stblob.data = blob_data.data();
stblob.len = blob_data.size();
stblob.flags = CURL_BLOB_COPY;

rc = SetCurlBlobOption(CURLOPT_SSLCERT_BLOB, &stblob);
Expand Down
2 changes: 1 addition & 1 deletion ext/test/w3c_tracecontext_http_test_server/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int main(int argc, char *argv[])

for (auto &part : body)
{
auto headers_2 = const_cast<std::map<std::string, std::string> &>(req.headers);
auto headers_2 = req.headers;

const TextMapCarrierTest carrier(headers_2);
auto current_ctx = context::RuntimeContext::GetCurrent();
Expand Down
7 changes: 2 additions & 5 deletions sdk/include/opentelemetry/sdk/common/circular_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ class CircularBuffer
*
* Note: This method must only be called from the consumer thread.
*/
CircularBufferRange<const AtomicUniquePtr<T>> Peek() const noexcept
{
return const_cast<CircularBuffer *>(this)->PeekImpl();
}
CircularBufferRange<const AtomicUniquePtr<T>> Peek() const noexcept { return PeekImpl(); }

/**
* Consume elements from the circular buffer's tail.
Expand Down Expand Up @@ -172,7 +169,7 @@ class CircularBuffer
std::atomic<uint64_t> head_{0};
std::atomic<uint64_t> tail_{0};

CircularBufferRange<AtomicUniquePtr<T>> PeekImpl() noexcept
CircularBufferRange<AtomicUniquePtr<T>> PeekImpl() const noexcept
{
uint64_t tail_index = tail_ % capacity_;
uint64_t head_index = head_ % capacity_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class OPENTELEMETRY_EXPORT MultiObserverResult final
void RegisterInstrument(opentelemetry::metrics::ObservableInstrument *instrument);
void DeregisterInstrument(opentelemetry::metrics::ObservableInstrument *instrument);
size_t InstrumentCount() const;
bool HasInstrument(const opentelemetry::metrics::ObservableInstrument *instrument) const;
bool HasInstrument(opentelemetry::metrics::ObservableInstrument *instrument) const;
void GetInstruments(
nostd::function_ref<void(opentelemetry::metrics::ObservableInstrument *)> callback);
void Reset();
void StoreResults(opentelemetry::common::SystemTimestamp collection_ts);

protected:
opentelemetry::metrics::ObserverResultT<double> &ForInstrumentDouble(
const opentelemetry::metrics::ObservableInstrument *instrument) override;
opentelemetry::metrics::ObservableInstrument *instrument) override;
opentelemetry::metrics::ObserverResultT<int64_t> &ForInstrumentInt64(
const opentelemetry::metrics::ObservableInstrument *instrument) override;
opentelemetry::metrics::ObservableInstrument *instrument) override;

private:
// This is _different_ to opentelemetry::metrics::ObserverResult because this variant is
Expand Down
17 changes: 6 additions & 11 deletions sdk/src/metrics/multi_observer_result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ size_t MultiObserverResult::InstrumentCount() const
}

bool MultiObserverResult::HasInstrument(
const opentelemetry::metrics::ObservableInstrument *instrument) const
opentelemetry::metrics::ObservableInstrument *instrument) const
{
return observer_results_.find(const_cast<opentelemetry::metrics::ObservableInstrument *>(
instrument)) != observer_results_.end();
return observer_results_.find(instrument) != observer_results_.end();
}

void MultiObserverResult::GetInstruments(
Expand Down Expand Up @@ -100,13 +99,10 @@ void MultiObserverResult::StoreResults(opentelemetry::common::SystemTimestamp co
}

opentelemetry::metrics::ObserverResultT<double> &MultiObserverResult::ForInstrumentDouble(
const opentelemetry::metrics::ObservableInstrument *instrument)
opentelemetry::metrics::ObservableInstrument *instrument)
{
static opentelemetry::sdk::metrics::ObserverResultT<double> null_result;
// const_cast is appropriate here, because we're _not_ modifying the passed-in pointer;
// we just need to make it non-const to be able to look it up in our map.
auto it = observer_results_.find(
const_cast<opentelemetry::metrics::ObservableInstrument *>(instrument));
auto it = observer_results_.find(instrument);
if (it == observer_results_.end())
{
OTEL_INTERNAL_LOG_ERROR("[MultiObserverResult::ForInstrumentDouble]"
Expand All @@ -125,11 +121,10 @@ opentelemetry::metrics::ObserverResultT<double> &MultiObserverResult::ForInstrum
}

opentelemetry::metrics::ObserverResultT<int64_t> &MultiObserverResult::ForInstrumentInt64(
const opentelemetry::metrics::ObservableInstrument *instrument)
opentelemetry::metrics::ObservableInstrument *instrument)
{
static opentelemetry::sdk::metrics::ObserverResultT<int64_t> null_result;
auto it = observer_results_.find(
const_cast<opentelemetry::metrics::ObservableInstrument *>(instrument));
auto it = observer_results_.find(instrument);
if (it == observer_results_.end())
{
OTEL_INTERNAL_LOG_ERROR("[MultiObserverResult::ForInstrumentInt64]"
Expand Down
Loading