Skip to content

Commit

Permalink
fix: restore context value class method
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlaurin committed Jun 9, 2021
1 parent 3c440ed commit 0a34c74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/lib/opentelemetry/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module OpenTelemetry
class Context
KEY = :__opentelemetry_context__
EMPTY_ENTRIES = {}.freeze
private_constant :KEY, :EMPTY_ENTRIES

class << self
# Returns a key used to index a value in a Context
Expand Down Expand Up @@ -102,6 +103,13 @@ def with_values(values)
detach(prev)
end

# Returns the value associated with key in the current context
#
# @param [String] key The lookup key
def value(key)
current.value(key)
end

def clear
self.current = ROOT
end
Expand Down
11 changes: 11 additions & 0 deletions api/test/opentelemetry/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@
end
end

describe '.value' do
it 'returns the value from the current context' do
Context.attach(new_context)
_(Context.value(foo_key)).must_equal('bar')

c2 = Context.current.set_value(bar_key, 'baz')
Context.attach(c2)
_(Context.value(bar_key)).must_equal('baz')
end
end

describe '.clear' do
it 'clears the context' do
Context.attach(new_context)
Expand Down

0 comments on commit 0a34c74

Please sign in to comment.