Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `traces' for #<Datadog::Transport::HTTP::Client ... when using SyncWriter #903

Closed
Yurokle opened this issue Dec 30, 2019 · 7 comments · Fixed by #904
Closed
Assignees
Labels
bug Involves a bug community Was opened by a community member core Involves Datadog core libraries
Projects
Milestone

Comments

@Yurokle
Copy link

Yurokle commented Dec 30, 2019

Hello folks. I'm seeing the following error when trying to use SyncWriter in my specs:

#<Thread:0x00007ffb036a0c60@/Users/ynaidyon/.rvm/gems/ruby-2.6.5/gems/ddtrace-0.30.1/lib/ddtrace/sync_writer.rb:38 run> terminated with exception (report_on_exception is true):
/Users/ynaidyon/.rvm/gems/ruby-2.6.5/gems/ddtrace-0.30.1/lib/ddtrace/sync_writer.rb:53:in `flush_trace': 
undefined method `traces' for #<Datadog::Transport::HTTP::Client:0x00007ffb02b02c50> (NoMethodError)

I think it was broken around here: 46b685b#diff-34a63124ba72d0f43c54ea1cb77f78e5

@delner
Copy link
Contributor

delner commented Dec 31, 2019

Thanks for the report! I think #904 should fix this; feel free to try it out.

@delner delner self-assigned this Dec 31, 2019
@delner delner added bug Involves a bug community Was opened by a community member core Involves Datadog core libraries labels Dec 31, 2019
@Yurokle
Copy link
Author

Yurokle commented Jan 6, 2020

Hello! I've been testing this, and I'm not sure if it actually fixes the problem, or maybe it just introduces another issue.
So what I'm doing in my code in test environment is something like this:

::Datadog.configure do |config|
  config.tracer(
    # ...
    transport_options: proc { |t| t.adapter(:test, TestBuffer) },
    writer: Datadog::SyncWriter.new,
  )

Unfortunately, it looks like when I'm running my specs it still tries to make calls via the Net::HTTP adapter and not the Test one. I think following line is the reason for this:
https://github.com/DataDog/dd-trace-rb/blob/master/lib/ddtrace/tracer.rb#L401

I think the problem here is more in my code, rather than in yours - I'm using both custom writer and transport adapter, but maybe it would make sense to make those things mutually exclusive? Or like raise an error of you pass both, since transport_options: won't be applied to a custom writer since those are just arguments for a writer constructor.

@Yurokle
Copy link
Author

Yurokle commented Jan 6, 2020

Actually, it looks like transport_options: aren't just raw arguments to a writer constructor, but rather a hash with :priority_sampler, :transport_options arguments which is being constructed in the #configure_writer method of the Datadog::Tracer

@Yurokle
Copy link
Author

Yurokle commented Jan 6, 2020

I don't know if people actually want to be able to pass a custom writer object or they just want to be able to pick from sync and async writers, if the latter is the case, mb it would make sense to use a symbol / class name to distinguish between the two, and keep the initialization logic in one place (#configure_writer method)
Just a thought.

@delner
Copy link
Contributor

delner commented Jan 6, 2020

Yeah I think these are good suggestions: we want to minimize configuration whenever possible, so we've been looking at ways to implement some designs to our components that will help us improve on this e.g. #879

In the mean time, there's a couple of ways to configure SyncWriter with a test adapter:

Datadog.configure do |config|
  config.tracer(
    writer: Datadog::SyncWriter.new(
      transport: Datadog::Transport::HTTP.default { |t| t.adapter :test, [] }
    )
  )
end

Or

Datadog.configure do |config|
  config.tracer(
    writer: Datadog::SyncWriter.new(
      transport_options: { on_build: proc { |t| t.adapter(:test, []) } }
    )
  )
end

Both should work, but I'm working on plans that will hopefully make this less complicated in the near future.

@delner
Copy link
Contributor

delner commented Jan 7, 2020

Merged to master to be released with 0.31.0.

@delner delner added this to the 0.31.0 milestone Jan 7, 2020
@Yurokle
Copy link
Author

Yurokle commented Jan 7, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug community Was opened by a community member core Involves Datadog core libraries
Projects
Active work
  
Resolved/Closed
Development

Successfully merging a pull request may close this issue.

2 participants