Class: Datadog::Annotation::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/annotation/tracer.rb

Overview

Datadog::Annotation::Tracer is responsible for setting up the trace for the annotated method

Class Method Summary collapse

Class Method Details

.trace(method:, trace_info:, args:, &block) ⇒ Object

Parameters:

  • method (Method)
  • trace_info (Hash)

    Ex: trace_info:

    service: "web",
    resource: "Users#create"
    

    @option service: [String] the service name for span @option resource: [String || Proc] the resource in which the current span refers

    If by any reason you need to use some information that your method receives as a parameter, you can set a Proc as a resource.

    Ex:
      __trace(
        method: :test,
        service: "web"
        resource: Proc.new { |_, type| "test##{type}"}
      )
      def test(name, type); end
    

    @option metadata_proc: [Proc] Block which sets tags into current trace. It receives original args, result of the traced method and span

    Ex:
      __trace(
        method: :test,
        service: "web"
        metadata_proc: Proc.new do |args, result, span|
          span.set_tag("name", args[:name])
          span.set_tag("type", args[:type])
          span.set_tag("result", result)
        end
      )
      def test(name, type); end
    
  • args (Array)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ddtrace/annotation/tracer.rb', line 44

def self.trace(method:, trace_info:, args:, &block)
  resource = resolve_resource!(trace_info[:resource], args)
   = trace_info[:metadata_proc]

  Datadog.tracer.trace(resource, service: trace_info[:service]) do |span|
    result = method.call(*args, &block)

    resolve_metadata!(
      metadata_proc: ,
      method: method,
      args: args,
      result: result,
      span: span
    )

    result
  end
end