Module: Traces::Backend::Test::Interface
- Defined in:
- lib/traces/backend/test.rb
Instance Method Summary collapse
-
#trace(name, resource: self.class.name, attributes: nil, &block) ⇒ Object
Trace the given block of code and validate the interface usage.
-
#trace_context ⇒ Object
Get a trace context from the current execution scope.
-
#trace_context=(context) ⇒ Object
Assign a trace context to the current execution scope.
Instance Method Details
#trace(name, resource: self.class.name, attributes: nil, &block) ⇒ Object
Trace the given block of code and validate the interface usage.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/traces/backend/test.rb', line 45 def trace(name, resource: self.class.name, attributes: nil, &block) unless block_given? raise ArgumentError, "No block given!" end unless name.is_a?(String) raise ArgumentError, "Invalid name (must be String): #{name.inspect}!" end if resource # It should be convertable: resource = resource.to_s end context = Context.nested(Fiber.current.traces_backend_context) span = Span.new(context) # Ensure the attributes are valid and follow the requirements: attributes&.each do |key, value| span[key] = value end Fiber.current.traces_backend_context = context if block.arity.zero? yield else yield span end end |
#trace_context ⇒ Object
Get a trace context from the current execution scope.
83 84 85 |
# File 'lib/traces/backend/test.rb', line 83 def trace_context Fiber.current.traces_backend_context end |
#trace_context=(context) ⇒ Object
Assign a trace context to the current execution scope.
78 79 80 |
# File 'lib/traces/backend/test.rb', line 78 def trace_context= context Fiber.current.traces_backend_context = context end |