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

otelmongo: set attribute based on hostname or IP address #2182

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

DiptoChakrabarty
Copy link

@DiptoChakrabarty DiptoChakrabarty commented Apr 13, 2022

Fixes #2165

Set the appropriate attribute based on whether hostname is an Ip address or not

@codecov
Copy link

codecov bot commented Apr 14, 2022

Codecov Report

Merging #2182 (336e6bf) into main (3d29139) will increase coverage by 1.5%.
The diff coverage is 57.1%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #2182     +/-   ##
=======================================
+ Coverage   74.2%   75.7%   +1.5%     
=======================================
  Files        144     145      +1     
  Lines       6556    6567     +11     
=======================================
+ Hits        4867    4977    +110     
+ Misses      1546    1442    -104     
- Partials     143     148      +5     
Impacted Files Coverage Δ
....mongodb.org/mongo-driver/mongo/otelmongo/mongo.go 84.5% <57.1%> (+84.5%) ⬆️
...b.org/mongo-driver/mongo/otelmongo/test/version.go 0.0% <0.0%> (ø)
...mongodb.org/mongo-driver/mongo/otelmongo/config.go 100.0% <0.0%> (+100.0%) ⬆️
...ongodb.org/mongo-driver/mongo/otelmongo/version.go 100.0% <0.0%> (+100.0%) ⬆️

@@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixed

- Set attributes based on whether hostname provided is an IP Address or hostname (#2182)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please reference the full package name that this change is related to.

@MrAlias MrAlias requested a review from dmathieu as a code owner May 24, 2022 18:01
semconv.NetPeerPortKey.Int(port),
semconv.NetTransportTCP,
}

addr := net.ParseIP(hostname)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this wouldn't be more efficient with a regex?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer net.ParseIP especially that it is already used in other places like here: https://github.com/open-telemetry/opentelemetry-go/blob/db7fd1bb51ce6ed1171cac15eeecb6871dbbb80a/semconv/internal/http.go#L123


addr := net.ParseIP(hostname)
if addr != nil {
attrs = append(attrs, semconv.NetPeerIPKey.String(hostname))
Copy link
Member

Choose a reason for hiding this comment

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

Can you please cover this scenario in the unit tests? It would be good to cover both IPv4 and IPv6.

@pellared pellared changed the title set attribute based on hostname or ip address otelmongo: set attribute based on hostname or ip address Jun 8, 2022
@pellared pellared changed the title otelmongo: set attribute based on hostname or ip address otelmongo: set attribute based on hostname or IP address Jun 8, 2022
@MrAlias
Copy link
Contributor

MrAlias commented Nov 3, 2022

@DiptoChakrabarty are you still able to work on this? It looks abandoned. If so, please address the feedback that has been given. If not, please close the PR.

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

Successfully merging this pull request may close these issues.

[otelmongo] should use AttributeNetPeerIP when hostname is a IP
5 participants