TracesSourceTracesBackendTestInterface

module Interface

The test backend interface.

Definitions

def trace(name, resource: nil, attributes: nil, &block)

Trace the given block of code and validate the interface usage.

Signature

parameter name String

A useful name/annotation for the recorded span.

parameter resource String

The context in which the trace operation is occuring.

parameter attributes Hash

Metadata for the recorded span.

Implementation

def trace(name, resource: nil, 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
	
	# It should be convertable:
	resource &&= resource.to_s
	
	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

def trace_context= context

Assign a trace context to the current execution scope.

Implementation

def trace_context= context
	Fiber.current.traces_backend_context = context
end

def trace_context

Get a trace context from the current execution scope.

Implementation

def trace_context
	Fiber.current.traces_backend_context
end