Module: OpenCensus::Context

Defined in:
lib/opencensus/context.rb

Overview

The Context module provides per-thread storage.

Class Method Summary collapse

Class Method Details

.get(key) ⇒ Object?

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

Parameters:

  • key (String, Symbol)

    The name of the context value to fetch.

Returns:

  • (Object, nil)

    The fetched value.



45
46
47
# File 'lib/opencensus/context.rb', line 45

def get key
  storage[key]
end

.reset!Object

Clears all values from the context.



62
63
64
# File 'lib/opencensus/context.rb', line 62

def reset!
  Thread.current[THREAD_KEY] = {}
end

.set(key, value) ⇒ Object

Store a value in the context.

Parameters:

  • key (String, Symbol)

    The name of the context value to store.

  • value (Object)

    The value associated with the key.



35
36
37
# File 'lib/opencensus/context.rb', line 35

def set key, value
  storage[key] = value
end

.unset(key) ⇒ Object?

Unsets a value from the context.

Parameters:

  • key (String, Symbol)

    The name of the context value to unset.

Returns:

  • (Object, nil)

    The value of the context value just unset.



55
56
57
# File 'lib/opencensus/context.rb', line 55

def unset key
  storage.delete key
end