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

Fix agent_url in environment logger when io transport #2313

Merged
merged 3 commits into from
Oct 14, 2022

Conversation

TonyCTHsu
Copy link
Contributor

@TonyCTHsu TonyCTHsu commented Oct 13, 2022

What does this PR do?

Mitigate the error from environment logger when IO transport is configured.

The environment logger, seems to be only working for HTTP transport, the object has client attribute, and api and adapter so on…, but not for IO transport

@github-actions github-actions bot added the core Involves Datadog core libraries label Oct 13, 2022
@TonyCTHsu TonyCTHsu marked this pull request as ready for review October 13, 2022 13:26
@TonyCTHsu TonyCTHsu requested a review from a team October 13, 2022 13:26
@TonyCTHsu TonyCTHsu self-assigned this Oct 13, 2022
Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few suggestions. I don't consider them blocking, but would really like to see some or all adressed.

Comment on lines 110 to 119
def agent_url
# Retrieve the effect agent URL, regardless of how it was configured
transport = Tracing.send(:tracer).writer.transport

# return '' with IO transport
return '' unless transport.respond_to?(:client)

adapter = transport.client.api.adapter
adapter.url
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm... not the biggest of fans of this approach. The issue showed up because we reach quite deep inside the transport object to get some information, and our "reaching" ended up being problematic. Let me inline it all so we can see how deep it is:

Datadog::Tracing.send(:tracer).writer.transport.client.api.adapter.url

This code is assuming a very very specific transport object, and will break with all others.

I feel that by probing for respond_to?(:client) we're solving the symptom (oops we need to be slightly more careful when reaching) and not the cause (we're reaching quite deep).

I won't block the PR on this (so I'll approve it anyway) BUT my suggestion would be to add an #agent_url method directly on the Datadog::Transport::Traces::Transport class.

I would also suggest having a useful fallback for others. E.g., if there's no agent url, perhaps we could instead use "(custom transport: #{transport.class})" or something like that.

Since the whole objective of this block is having something useful when reporting issues, I think having a clear indication that there's a non-standard config being used is quite valuable, instead of having it blank and whoever is looking at the issue will need to hunt around for a while to understand why.

@TonyCTHsu TonyCTHsu merged commit de82d67 into master Oct 14, 2022
@TonyCTHsu TonyCTHsu deleted the bugfix/io-transport-in-environment-logger branch October 14, 2022 15:28
@github-actions github-actions bot added this to the 1.6.0 milestone Oct 14, 2022
@TonyCTHsu TonyCTHsu mentioned this pull request Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants