Skip to content

Conversation

@arielvalentin
Copy link
Contributor

Faraday uses a base URL to derive the host name which is used by the tracer middleware as the span attribute value for net.peer.name.

Although it seems incorrect, Faraday does not require a base URL when it is initialized and is a commonly used when using Faraday test stubs.

When the base URL is absent, the net.peer.name is set to nil triggering and invalid attribute error report and creates a bit of noise for test cases.

This change omits the net.peer.name attribute when it is nil to suppress error reporting when the host is absent.

Faraday uses a base URL to derive the host name which is used by the tracer middleware as the span attribute value for `net.peer.name`.

Although it seems incorrect, Faraday does not require a base URL when it is initialized and is a commonly used when using Faraday test stubs.

When the base URL is absent, the `net.peer.name` is set to `nil` triggering and invalid attribute error report and creates a bit of noise for test cases.

This change omits the `net.peer.name` attribute when it is `nil` to suppress error reporting when the host is absent.
@arielvalentin
Copy link
Contributor Author

Going to add additional tests where net.peer.name should be omitted if the URL contains an IP address instead of a hostname. Per our discussion during the SIG today

Copy link
Contributor

@plantfansam plantfansam left a comment

Choose a reason for hiding this comment

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

Looks great! Very excited about the tests for when url is an IP address 😄

'net.peer.name' => url.host
'http.url' => url.to_s
}
instrumentation_attrs['net.peer.name'] = url.host unless url.host.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

IDK which Rubocop prefers but I believe we can do= url.host if url.host

_(span.attributes['http.method']).must_equal 'GET'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.url']).must_equal 'http:/success'
_(span.attributes).wont_include('net.peer.name')
Copy link
Contributor

Choose a reason for hiding this comment

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

span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER)

OpenTelemetry::SDK.configure do |c|
c.error_handler = ->(exception:, message:) { raise(exception || message) }
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏

@arielvalentin
Copy link
Contributor Author

Turns out Ruby stdlib URI will return the IP Addr as the host value so it won't be as simple as I thought.

I am going to table this PR and come back to it later.

Copy link
Contributor

@plantfansam plantfansam left a comment

Choose a reason for hiding this comment

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

👍

@arielvalentin arielvalentin marked this pull request as draft June 4, 2022 20:49
@plantfansam
Copy link
Contributor

Hello, and thank you for your contribution!

We recently split Ruby instrumentation out into the opentelemetry-ruby-contrib repo.

This PR is related to instrumentation, so we'll need you to re-open it against opentelemetry-ruby-contrib. Sorry for the inconvenience!

To do that, you can:

  1. Create a fork of opentelemetry-ruby-contrib and copy the git url
  2. In your opentelemetry-ruby repo, run git remote add tmp-contrib <your-fork-git-url>
  3. git push tmp-contrib your-branch-name
  4. Open a new PR in contrib (feel free to just copy/paste your original PR description there)
  5. Close your open PR in this repo with a comment that links to your new PR in contrib
  6. Delete your tmp-contrib remote from opentelemetry-ruby (git remote rm tmp-contrib)
  7. git clone your opentelemetry-ruby-contrib fork, check out your branch, and make all changes in that repo from now on!

Sorry again for the inconvenience, and thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants