-
Notifications
You must be signed in to change notification settings - Fork 582
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
base: main
Are you sure you want to change the base?
Changes from all commits
33fd87f
eb3ede4
2b2f4dd
f87a638
fd7041f
336e6bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package otelmongo // import "go.opentelemetry.io/contrib/instrumentation/go.mong | |
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this wouldn't be more efficient with a regex? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer |
||
if addr != nil { | ||
attrs = append(attrs, semconv.NetPeerIPKey.String(hostname)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))) | ||
} | ||
|
There was a problem hiding this comment.
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.