Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The semantic conventions have been upgraded from `v1.27.0` to `v1.32.0` in `go.opentelemetry.io/contrib/bridges/otellogr`. (#7387)
- The semantic conventions have been upgraded from `v1.26.0` to `v1.32.0` in `go.opentelemetry.io/contrib/bridges/otelzap`. (#7389)
- The semantic conventions have been upgraded from `v1.26.0` to `v1.32.0` in `go.opentelemetry.io/contrib/detectors/gcp`. (#7378)
- The semantic conventions have been upgraded in `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo` to `v1.32.0`. (#7393)
- The semantic conventions have been upgraded in `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo` to `v1.32.0`. (#7393)
- The semantic conventions have been upgraded in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws` to `v1.32.0`. (#7394)
- The `messaging.system=AmazonSQS` attribute has been corrected to `messaging.system=aws.sqs`.
- The `net.peer.addr` attribute key has been upgraded to `server.address`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
// - https://github.com/DataDog/dd-trace-go/tree/v1.23.3/ddtrace/ext
//
// The "OTEL_SEMCONV_STABILITY_OPT_IN" environment variable can be used to opt
// into semconv/v1.26.0:
// - "database": emit v1.26.0 semantic conventions
// into the latest semantic conventions:
// - "database": emit the latest semantic conventions
// - "": emit v1.21.0 (default) semantic conventions
// - "database/dup": emit v1.21.0 (default) and v1.26.0
// - "database/dup": emit v1.21.0 (default) and the latest semantic
// conventions
//
// By default, otelmongo only emits v1.21.0.
package otelmongo // import "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"go.opentelemetry.io/otel/attribute"

semconv1210 "go.opentelemetry.io/otel/semconv/v1.21.0"
semconv1260 "go.opentelemetry.io/otel/semconv/v1.26.0"
semconv "go.opentelemetry.io/otel/semconv/v1.32.0"
)

// Constants for environment variable keys and versions.
Expand Down Expand Up @@ -85,14 +85,14 @@ func (m EventMonitor) CommandStartedTraceAttrs(
// Dup implies both v1.26.0 and v1.21.0
if hasOptIn(m.version, semconvOptInDup) {
return append(
commandStartedTraceAttrsV1260(evt, opts...),
commandStartedTraceAttrs(evt, opts...),
commandStartedTraceAttrsV1210(evt, opts...)...,
)
}

// Check for the 1.26.0 opt-in
if hasOptIn(m.version, semconvOptIn1260) {
return commandStartedTraceAttrsV1260(evt, opts...)
return commandStartedTraceAttrs(evt, opts...)
}

// Fallback to v1.21.0
Expand Down Expand Up @@ -127,30 +127,30 @@ func sanitizeCommand(command bson.Raw) string {
return string(b)
}

// commandStartedTraceAttrsV1260 generates trace attributes for semantic version
// 1.26.0.
func commandStartedTraceAttrsV1260(evt *event.CommandStartedEvent, setters ...AttributeOption) []attribute.KeyValue {
// commandStartedTraceAttrs generates trace attributes for the latest semantic
// version.
func commandStartedTraceAttrs(evt *event.CommandStartedEvent, setters ...AttributeOption) []attribute.KeyValue {
opts := &AttributeOptions{}
for _, set := range setters {
set(opts)
}

attrs := []attribute.KeyValue{semconv1260.DBSystemMongoDB}
attrs := []attribute.KeyValue{semconv.DBSystemNameMongoDB}

attrs = append(attrs, semconv1260.DBOperationName(evt.CommandName))
attrs = append(attrs, semconv1260.DBNamespace(evt.DatabaseName))
attrs = append(attrs, semconv1260.NetworkTransportTCP)
attrs = append(attrs, semconv.DBOperationName(evt.CommandName))
attrs = append(attrs, semconv.DBNamespace(evt.DatabaseName))
attrs = append(attrs, semconv.NetworkTransportTCP)

hostname, port := peerInfo(evt)
attrs = append(attrs, semconv1260.NetworkPeerPort(port))
attrs = append(attrs, semconv1260.NetworkPeerAddress(net.JoinHostPort(hostname, strconv.Itoa(port))))
attrs = append(attrs, semconv.NetworkPeerPort(port))
attrs = append(attrs, semconv.NetworkPeerAddress(net.JoinHostPort(hostname, strconv.Itoa(port))))

if !opts.commandAttributeDisabled {
attrs = append(attrs, semconv1260.DBQueryText(sanitizeCommand(evt.Command)))
attrs = append(attrs, semconv.DBQueryText(sanitizeCommand(evt.Command)))
}

if opts.collectionName != "" {
attrs = append(attrs, semconv1260.DBCollectionName(opts.collectionName))
attrs = append(attrs, semconv.DBCollectionName(opts.collectionName))
}

return attrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"go.opentelemetry.io/otel/attribute"
semconv1210 "go.opentelemetry.io/otel/semconv/v1.21.0"
semconv1260 "go.opentelemetry.io/otel/semconv/v1.26.0"
semconv "go.opentelemetry.io/otel/semconv/v1.32.0"
)

func TestNewEventMonitor(t *testing.T) {
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestCommandStartedTraceAttrs(t *testing.T) {
}

v1260 := []attribute.KeyValue{
semconv1260.DBSystemMongoDB,
semconv.DBSystemNameMongoDB,
{Key: "db.operation.name", Value: attribute.StringValue(opName)},
{Key: "db.namespace", Value: attribute.StringValue(dbNamespace)},
{Key: "db.query.text", Value: attribute.StringValue(stmt)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ func assertSemconv1170(mt *mtest.T, attrs []attribute.KeyValue) {
assert.Contains(mt, attrs, attribute.String("db.name", "test-database"))
}

func assertSemconv1260(mt *mtest.T, attrs []attribute.KeyValue) {
func assertSemconv(mt *mtest.T, attrs []attribute.KeyValue) {
mt.Helper()

assert.Contains(mt, attrs, attribute.String("db.system", "mongodb"))
assert.Contains(mt, attrs, attribute.String("db.system.name", "mongodb"))
assert.Contains(mt, attrs, attribute.String("network.peer.address", "<mock_connection>:27017"))
assert.Contains(mt, attrs, attribute.Int64("network.peer.port", int64(27017)))
assert.Contains(mt, attrs, attribute.String("network.transport", "tcp"))
Expand All @@ -283,7 +283,7 @@ func TestSemanticConventionOptIn(t *testing.T) {
{
name: "database",
semconvOptIn: "database",
assert: assertSemconv1260,
assert: assertSemconv,
},
}
for _, tc := range tt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.30.0"
semconv "go.opentelemetry.io/otel/semconv/v1.32.0"
"go.opentelemetry.io/otel/trace"

"go.mongodb.org/mongo-driver/v2/bson"
Expand Down
Loading