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: 2 additions & 2 deletions api/include/opentelemetry/plugin/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Span final : public trace::Span
{}

// trace::Span
void SetAttribute(nostd::string_view name, const common::AttributeValue &&value) noexcept override
void SetAttribute(nostd::string_view name, const common::AttributeValue &value) noexcept override
{
span_->SetAttribute(name, std::move(value));
span_->SetAttribute(name, value);
}

void AddEvent(nostd::string_view name) noexcept override { span_->AddEvent(name); }
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NoopSpan final : public Span
explicit NoopSpan(const std::shared_ptr<Tracer> &tracer) noexcept : tracer_{tracer} {}

void SetAttribute(nostd::string_view /*key*/,
const common::AttributeValue && /*value*/) noexcept override
const common::AttributeValue & /*value*/) noexcept override
{}

void AddEvent(nostd::string_view /*name*/) noexcept override {}
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Span
// Sets an attribute on the Span. If the Span previously contained a mapping for
// the key, the old value is replaced.
virtual void SetAttribute(nostd::string_view key,
const common::AttributeValue &&value) noexcept = 0;
const common::AttributeValue &value) noexcept = 0;

// Adds an event to the Span.
virtual void AddEvent(nostd::string_view name) noexcept = 0;
Expand Down
2 changes: 2 additions & 0 deletions api/test/trace/noop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ TEST(NoopTest, UseNoopTracers)

std::vector<std::pair<std::string, std::vector<int>>> attributes3;
s1->AddEvent("abc", attributes3);

s1->SetAttribute("abc", 4);
}
2 changes: 1 addition & 1 deletion examples/plugin/plugin/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Span final : public trace::Span

// opentelemetry::trace::Span
void SetAttribute(nostd::string_view /*name*/,
const common::AttributeValue && /*value*/) noexcept override
const common::AttributeValue & /*value*/) noexcept override
{}

void AddEvent(nostd::string_view /*name*/) noexcept override {}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Recordable::SetIds(trace::TraceId trace_id,
}

void Recordable::SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &&value) noexcept
const opentelemetry::common::AttributeValue &value) noexcept
{
(void)key;
(void)value;
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/recordable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Recordable final : public sdk::trace::Recordable
trace::SpanId parent_span_id) noexcept override;

void SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &&value) noexcept override;
const opentelemetry::common::AttributeValue &value) noexcept override;

void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override;

Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/recordable.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Recordable
* @param value the attribute value
*/
virtual void SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &&value) noexcept = 0;
const opentelemetry::common::AttributeValue &value) noexcept = 0;

/**
* Add an event to a span.
Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/span_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SpanData final : public Recordable
parent_span_id_ = parent_span_id;
}

void SetAttribute(nostd::string_view key, const common::AttributeValue &&value) noexcept override
void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept override
{
attributes_[std::string(key)] = value;
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/trace/span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Span::Span(std::shared_ptr<Tracer> &&tracer,
recordable_->SetName(name);

attributes.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept {
recordable_->SetAttribute(key, std::move(value));
recordable_->SetAttribute(key, value);
return true;
});

Expand All @@ -70,11 +70,11 @@ Span::~Span()
End();
}

void Span::SetAttribute(nostd::string_view key, const common::AttributeValue &&value) noexcept
void Span::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept
{
std::lock_guard<std::mutex> lock_guard{mu_};

recordable_->SetAttribute(key, std::move(value));
recordable_->SetAttribute(key, value);
}

void Span::AddEvent(nostd::string_view name) noexcept
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/trace/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Span final : public trace_api::Span
~Span() override;

// trace_api::Span
void SetAttribute(nostd::string_view key, const common::AttributeValue &&value) noexcept override;
void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept override;

void AddEvent(nostd::string_view name) noexcept override;

Expand Down
24 changes: 20 additions & 4 deletions sdk/test/trace/tracer_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "opentelemetry/sdk/trace/tracer.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/samplers/always_on.h"
#include "opentelemetry/sdk/trace/samplers/always_off.h"
#include "opentelemetry/sdk/trace/samplers/always_on.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/span_data.h"

#include <gtest/gtest.h>
Expand Down Expand Up @@ -142,7 +142,6 @@ TEST(Tracer, StartSpanWithAttributes)
ASSERT_EQ(3.0, nostd::get<double>(span_data2->GetAttributes().at("attr3")));
}


TEST(Tracer, GetSampler)
{
// Create a Tracer with a default AlwaysOnSampler
Expand All @@ -154,8 +153,25 @@ TEST(Tracer, GetSampler)

// Create a Tracer with a AlwaysOffSampler
std::shared_ptr<SpanProcessor> processor_2(new SimpleSpanProcessor(nullptr));
std::shared_ptr<Tracer> tracer_off(new Tracer(std::move(processor_2), std::make_shared<AlwaysOffSampler>()));
std::shared_ptr<Tracer> tracer_off(
new Tracer(std::move(processor_2), std::make_shared<AlwaysOffSampler>()));

auto t2 = tracer_off->GetSampler();
ASSERT_EQ("AlwaysOffSampler", t2->GetDescription());
}

TEST(Tracer, SpanSetAttribute)
{
std::shared_ptr<std::vector<std::unique_ptr<SpanData>>> spans_received(
new std::vector<std::unique_ptr<SpanData>>);
auto tracer = initTracer(spans_received);

auto span = tracer->StartSpan("span 1");

span->SetAttribute("abc", 3.1);

span->End();
ASSERT_EQ(1, spans_received->size());
auto &span_data = spans_received->at(0);
ASSERT_EQ(3.1, nostd::get<double>(span_data->GetAttributes().at("abc")));
}