module OpenCensus::Context

The Context module provides per-thread storage.

Constants

THREAD_KEY

Thread local storage key under which all OpenCensus context data is stored.

@private

Public Class Methods

get(key) click to toggle source

Return a value from the context. Returns nil if no value is set.

@param [String, Symbol] key The name of the context value to fetch. @return [Object, nil] The fetched value.

# File lib/opencensus/context.rb, line 45
def get key
  storage[key]
end
reset!() click to toggle source

Clears all values from the context.

# File lib/opencensus/context.rb, line 62
def reset!
  Thread.current[THREAD_KEY] = {}
end
set(key, value) click to toggle source

Store a value in the context.

@param [String, Symbol] key The name of the context value to store. @param [Object] value The value associated with the key.

# File lib/opencensus/context.rb, line 35
def set key, value
  storage[key] = value
end
unset(key) click to toggle source

Unsets a value from the context.

@param [String, Symbol] key The name of the context value to unset. @return [Object, nil] The value of the context value just unset.

# File lib/opencensus/context.rb, line 55
def unset key
  storage.delete key
end

Private Class Methods

storage() click to toggle source
# File lib/opencensus/context.rb, line 68
def storage
  Thread.current[THREAD_KEY] ||= {}
end