class OpenTracing::Instrumentation::Mongo::TraceSubscriber
TraceSubscriber
trace mongo requests
Constants
- ERROR_TAG
Attributes
monitor[R]
operation_name_builder[R]
sanitazer[R]
scope_store[R]
tracer[R]
Public Class Methods
new( tracer: OpenTracing.global_tracer, scope_store: {}, operation_name_builder: OperationNameBuilder.new, sanitazer: QuerySanitazer.new )
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 13 def initialize( tracer: OpenTracing.global_tracer, scope_store: {}, operation_name_builder: OperationNameBuilder.new, sanitazer: QuerySanitazer.new ) @tracer = tracer @monitor = Monitor.new @scope_store = scope_store @operation_name_builder = operation_name_builder @sanitazer = sanitazer end
Public Instance Methods
failed(event)
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 39 def failed(event) tag_error(event.operation_id, event.message, event.failure) clean_scope(event.operation_id) end
started(event)
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 26 def started(event) scope = tracer.start_active_span( build_operation_name(event), tags: base_tags(event).merge(mongo_tags(event)), ) store_scope(event.operation_id, scope) end
succeeded(event)
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 35 def succeeded(event) clean_scope(event.operation_id) end
Private Instance Methods
build_operation_name(event)
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 52 def build_operation_name(event) operation_name_builder.build_operation_name(event) end
clean_scope(operation_id)
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 85 def clean_scope(operation_id) monitor.synchronize do scope_store .delete(operation_id) .close end end
store_scope(operation_id, scope)
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 79 def store_scope(operation_id, scope) monitor.synchronize do scope_store[operation_id] = scope end end
tag_error(operation_id, message, object)
click to toggle source
# File lib/opentracing/instrumentation/mongo/trace_subscriber.rb, line 95 def tag_error(operation_id, message, object) monitor.synchronize do scope_store[operation_id] .span .set_tag(ERROR_TAG, true) .log_kv( 'error.kind': message, 'error.object': JSON.dump(object), ) end end