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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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.

- Fix the `otelmux` middleware by using `SpanKindServer` when deciding the `SpanStatus`.
This makes `4xx` response codes to not be an error anymore. (#1973)
- Fixed jaegerremote sampler not behaving properly with per operation strategy set. (#2137)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package otelmongo // import "go.opentelemetry.io/contrib/instrumentation/go.mong
import (
"context"
"fmt"
"net"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -51,10 +52,17 @@ func (m *monitor) Started(ctx context.Context, evt *event.CommandStartedEvent) {
semconv.DBSystemMongoDB,
semconv.DBOperationKey.String(evt.CommandName),
semconv.DBNameKey.String(evt.DatabaseName),
semconv.NetPeerNameKey.String(hostname),
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

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.

} else {
attrs = append(attrs, semconv.NetPeerNameKey.String(hostname))
}

if !m.cfg.CommandAttributeDisabled {
attrs = append(attrs, semconv.DBStatementKey.String(sanitizeCommand(evt.Command)))
}
Expand Down