Skip to content

Incorrect resource is set when wrapping multiple methods in a single call #6

@joshuay03

Description

@joshuay03

The issue stems from the resource being set for the first method if the passed in value is falsey, and then the value being used in subsequent methods due to the memoisation:

resource ||= "#{self.class.name}##{m}"

I've got a branch with a reproducing spec: master...joshuay03:ddtrace-rb-method-wrapper:multi-wrapped-resources

Failure
Failures:

  1) DdtraceWrapper wrap multiple :methods wraps with all the available args applicable to each method
     Failure/Error: expect(Datadog::Tracing).to receive(:trace).with('multi_span', service: ENV['DD_TRACE_METHOD_WRAPPER_SERVICE'], resource: 'DatadogTraceWrapperSpec#multi_wrapped_value_1')

       (Datadog::Tracing).trace("multi_span", {:resource=>"DatadogTraceWrapperSpec#multi_wrapped_value_1", :service=>"rspec"})
           expected: 1 time with arguments: ("multi_span", {:resource=>"DatadogTraceWrapperSpec#multi_wrapped_value_1", :service=>"rspec"})
           received: 2 times with arguments: ("multi_span", {:resource=>"DatadogTraceWrapperSpec#multi_wrapped_value_1", :service=>"rspec"})
     # ./spec/datadog_trace_wrapper_spec.rb:65:in `block (3 levels) in <top (required)>'

Finished in 0.01564 seconds (files took 0.33626 seconds to load)
5 examples, 1 failure

Failed examples:

rspec ./spec/datadog_trace_wrapper_spec.rb:64 # DdtraceWrapper wrap multiple :methods wraps with all the available args applicable to each method

Note that I had to update some of the API usage to get the specs to run with the latest 1.x version of ddtrace.

While I'm here, are there any plans to support ddtrace v2 (renamed to datadog)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions