Module: Datadog::Annotation::Decorator

Defined in:
lib/ddtrace/annotation/decorator.rb

Overview

Adds tracer to annotated methods

Instance Method Summary collapse

Instance Method Details

#__trace(method:, service:, resource: "#{self}##{method}", metadata_proc: nil) ⇒ Object

Adds method to list of traced methods

Parameters:

  • method (Symbol)

    name of the method to be traced

  • service (String)

    the service name for span

  • resource (String || Proc) (defaults to: "#{self}##{method}")

    the resource in which the current span refers

  • metadata_proc (Proc) (defaults to: nil)

    Block which sets tags into current trace. It receives original args, result of the traced method and span

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ddtrace/annotation/decorator.rb', line 17

def __trace(method:, service:, resource: "#{self}##{method}", metadata_proc: nil)
  return unless datadog_enabled?

  ()

  @traced_methods[method.to_sym] = {
    service: service,
    resource: resource,
    metadata_proc: ,
    defined?: false
  }
end

#method_added(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ddtrace/annotation/decorator.rb', line 30

def method_added(name)
  super

  return if !@traced_methods.key?(name) || @traced_methods.dig(name, :defined?)

  @traced_methods[name][:defined?] = true

  method = instance_method(name)
  trace_info = @traced_methods[name]

  define_method(name) do |*args, &block|
    Annotation::Tracer.trace(
      method: method.bind(self),
      trace_info: trace_info,
      args: args,
      &block
    )
  end
end