Skip to content

Commit

Permalink
Merge pull request #58 from plantfansam/with_span
Browse files Browse the repository at this point in the history
Copy current context entries in with_span
  • Loading branch information
yangxikun authored Jan 16, 2023
2 parents 07d9da3 + 2c7942c commit 8d9e5f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/opentelemetry/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function _M.extract_baggage(self)
end

function _M.with_span(self, span)
return self.new({}, span)
return self.new(util.shallow_copy_table(self.entries or {}), span)
end

function _M.with_span_context(self, span_context)
Expand Down
16 changes: 16 additions & 0 deletions spec/context_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ describe("current", function()
end)
end)

describe("with_span", function()
it("sets supplied entries on new context", function()
otel_global.set_context_storage({})
local original_entries = { foo = "bar" }
local old_ctx = context.new(original_entries, "oldspan")
local ctx = old_ctx:with_span("myspan")
assert.are.same(ctx.entries, original_entries)
end)

it("handles absence of entries arg gracefully", function()
local fake_span = "hi"
local ctx = context:with_span(fake_span)
assert.are.same(ctx.entries, {})
end)
end)

describe("attach", function()
it("creates new table at context_key if no table present and returns token matching length of stack after adding element", function()
local ctx_storage = {}
Expand Down

0 comments on commit 8d9e5f2

Please sign in to comment.