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
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
5 changes: 4 additions & 1 deletion 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 @@ -912,6 +912,7 @@ CURLcode HttpOperation::Setup()

struct curl_blob stblob
{};
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
stblob.data = const_cast<char *>(data);
stblob.len = data_len;
stblob.flags = CURL_BLOB_COPY;
Expand Down Expand Up @@ -954,6 +955,7 @@ CURLcode HttpOperation::Setup()

struct curl_blob stblob
{};
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
stblob.data = const_cast<char *>(data);
stblob.len = data_len;
stblob.flags = CURL_BLOB_COPY;
Expand Down Expand Up @@ -1002,6 +1004,7 @@ CURLcode HttpOperation::Setup()

struct curl_blob stblob
{};
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
stblob.data = const_cast<char *>(data);
stblob.len = data_len;
stblob.flags = CURL_BLOB_COPY;
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