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
6 changes: 3 additions & 3 deletions api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Context
template <class T>
Context SetValues(T &values) noexcept
{
Context context = Context(values);
nostd::shared_ptr<DataList> &last = context.head_;
Context context = Context(values);
nostd::shared_ptr<DataList> last = context.head_;
while (last->next_ != nullptr)
{
last = last->next_;
Expand Down Expand Up @@ -110,7 +110,7 @@ class Context

// Builds a data list off of a key and value iterable and returns the head
template <class T>
DataList(const T &keys_and_vals) : key_{nullptr}
DataList(const T &keys_and_vals) : key_{nullptr}, next_(nostd::shared_ptr<DataList>{nullptr})
{
bool first = true;
auto *node = this;
Expand Down
11 changes: 8 additions & 3 deletions api/test/context/context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ TEST(ContextTest, ContextInheritance)
{
using M = std::map<std::string, context::ContextValue>;

M m1 = {{"test_key", (int64_t)123}, {"foo_key", (int64_t)456}};
M m2 = {{"other_key", (int64_t)789}};
M m1 = {{"test_key", (int64_t)123}, {"foo_key", (int64_t)321}};
M m2 = {{"other_key", (int64_t)789}, {"another_key", (int64_t)987}};

context::Context test_context = context::Context(m1);
context::Context foo_context = test_context.SetValues(m2);

EXPECT_EQ(nostd::get<int64_t>(foo_context.GetValue("test_key")), 123);
EXPECT_EQ(nostd::get<int64_t>(foo_context.GetValue("foo_key")), 456);
EXPECT_EQ(nostd::get<int64_t>(foo_context.GetValue("foo_key")), 321);
EXPECT_EQ(nostd::get<int64_t>(foo_context.GetValue("other_key")), 789);
EXPECT_EQ(nostd::get<int64_t>(foo_context.GetValue("another_key")), 987);

EXPECT_EQ(nostd::get<int64_t>(test_context.GetValue("other_key")), 0);
EXPECT_EQ(nostd::get<int64_t>(test_context.GetValue("another_key")), 0);
}

// Tests that copying a context copies the key value pairs as expected.
Expand Down