Module: OpenCensus::Context

Defined in:
lib/opencensus/context.rb

Overview

The Context module provides per-thread storage.

Constant Summary collapse

THREAD_KEY =

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

:__opencensus_context__

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.



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

def get key
  storage[key]
end

.reset!Object

Clears all values from the context.



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

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.



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

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.



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

def unset key
  storage.delete key
end