diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c65386dc4a..7549fa332b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed - Improve performance by reducing allocations in the gRPC stats handler in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#8035) +- Switched the default for `OTEL_SEMCONV_STABILITY_OPT_IN` to emit the v1.37.0 semantic conventions by default in `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo`. (#8230) ### Deprecated diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor.go b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor.go index 0cc4c4135d7..605dc7b06f9 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor.go +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor.go @@ -19,9 +19,8 @@ import ( // Constants for environment variable keys and versions. const ( - semconvOptIn = "OTEL_SEMCONV_STABILITY_OPT_IN" - semconvOptInDup = "database/dup" - semconvOptIn1260 = "database" + semconvOptIn = "OTEL_SEMCONV_STABILITY_OPT_IN" + semconvOptInDup = "database/dup" ) // EventMonitor is responsible for monitoring events with a specified semantic @@ -88,13 +87,7 @@ func (m EventMonitor) CommandStartedTraceAttrs( ) } - // Check for the 1.26.0 opt-in - if hasOptIn(m.version, semconvOptIn1260) { - return commandStartedTraceAttrs(evt, opts...) - } - - // Fallback to v1.21.0 - return commandStartedTraceAttrsV1210(evt, opts...) + return commandStartedTraceAttrs(evt, opts...) } // peerInfo extracts the hostname and port from a CommandStartedEvent. diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor_test.go b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor_test.go index 953d5250075..086fdca6530 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor_test.go +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor_test.go @@ -27,11 +27,6 @@ func TestNewEventMonitor(t *testing.T) { version: "", want: "", }, - { - name: "Version 1260", - version: semconvOptIn1260, - want: "database", - }, { name: "Duplicate Version", version: semconvOptInDup, @@ -114,18 +109,12 @@ func TestCommandStartedTraceAttrs(t *testing.T) { name: "no version", initAttrs: []attribute.KeyValue{}, version: "", - want: v1210, + want: v1260, }, { name: "unsupported version", initAttrs: []attribute.KeyValue{}, version: "database/foo", - want: v1210, - }, - { - name: "database", - initAttrs: []attribute.KeyValue{}, - version: "database", want: v1260, }, { diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/mongo_test.go b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/mongo_test.go index 00c07bee203..fa499042144 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/mongo_test.go +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/mongo_test.go @@ -30,10 +30,10 @@ func TestDBCrudOperation(t *testing.T) { return assert.Equal(t, "test-collection.insert", s.Name(), "expected %s", s.Name()) }, func(s sdktrace.ReadOnlySpan) bool { - return assert.Contains(t, s.Attributes(), attribute.String("db.operation", "insert")) + return assert.Contains(t, s.Attributes(), attribute.String("db.operation.name", "insert")) }, func(s sdktrace.ReadOnlySpan) bool { - return assert.Contains(t, s.Attributes(), attribute.String("db.mongodb.collection", "test-collection")) + return assert.Contains(t, s.Attributes(), attribute.String("db.collection.name", "test-collection")) }, func(s sdktrace.ReadOnlySpan) bool { return assert.Equal(t, codes.Unset, s.Status().Code) @@ -56,7 +56,7 @@ func TestDBCrudOperation(t *testing.T) { excludeCommand: false, validators: append(commonValidators, func(s sdktrace.ReadOnlySpan) bool { for _, attr := range s.Attributes() { - if attr.Key == "db.statement" { + if attr.Key == "db.query.text" { return assert.Contains(t, attr.Value.AsString(), `"test-item":"test-value"`) } } @@ -72,7 +72,7 @@ func TestDBCrudOperation(t *testing.T) { excludeCommand: true, validators: append(commonValidators, func(s sdktrace.ReadOnlySpan) bool { for _, attr := range s.Attributes() { - if attr.Key == "db.statement" { + if attr.Key == "db.query.text" { return false } } @@ -128,11 +128,11 @@ func TestDBCrudOperation(t *testing.T) { s := spans[0] assert.Equal(mt, trace.SpanKindClient, s.SpanKind()) attrs := s.Attributes() - assert.Contains(mt, attrs, attribute.String("db.system", "mongodb")) - assert.Contains(mt, attrs, attribute.String("net.peer.name", "")) - assert.Contains(mt, attrs, attribute.Int64("net.peer.port", int64(27017))) - assert.Contains(mt, attrs, attribute.String("net.transport", "ip_tcp")) - assert.Contains(mt, attrs, attribute.String("db.name", "test-database")) + assert.Contains(mt, attrs, attribute.String("db.system.name", "mongodb")) + assert.Contains(mt, attrs, attribute.String("network.peer.address", ":27017")) + assert.Contains(mt, attrs, attribute.Int64("network.peer.port", int64(27017))) + assert.Contains(mt, attrs, attribute.String("network.transport", "tcp")) + assert.Contains(mt, attrs, attribute.String("db.namespace", "test-database")) for _, v := range tc.validators { assert.True(mt, v(s)) } @@ -158,10 +158,10 @@ func TestDBCollectionAttribute(t *testing.T) { return assert.Equal(t, "test-collection.delete", s.Name()) }, func(s sdktrace.ReadOnlySpan) bool { - return assert.Contains(t, s.Attributes(), attribute.String("db.operation", "delete")) + return assert.Contains(t, s.Attributes(), attribute.String("db.operation.name", "delete")) }, func(s sdktrace.ReadOnlySpan) bool { - return assert.Contains(t, s.Attributes(), attribute.String("db.mongodb.collection", "test-collection")) + return assert.Contains(t, s.Attributes(), attribute.String("db.collection.name", "test-collection")) }, func(s sdktrace.ReadOnlySpan) bool { return assert.Equal(t, codes.Unset, s.Status().Code) @@ -184,7 +184,7 @@ func TestDBCollectionAttribute(t *testing.T) { return assert.Equal(t, "listCollections", s.Name()) }, func(s sdktrace.ReadOnlySpan) bool { - return assert.Contains(t, s.Attributes(), attribute.String("db.operation", "listCollections")) + return assert.Contains(t, s.Attributes(), attribute.String("db.operation.name", "listCollections")) }, func(s sdktrace.ReadOnlySpan) bool { return assert.Equal(t, codes.Unset, s.Status().Code) @@ -233,11 +233,11 @@ func TestDBCollectionAttribute(t *testing.T) { s := spans[0] assert.Equal(mt, trace.SpanKindClient, s.SpanKind()) attrs := s.Attributes() - assert.Contains(mt, attrs, attribute.String("db.system", "mongodb")) - assert.Contains(mt, attrs, attribute.String("net.peer.name", "")) - assert.Contains(mt, attrs, attribute.Int64("net.peer.port", int64(27017))) - assert.Contains(mt, attrs, attribute.String("net.transport", "ip_tcp")) - assert.Contains(mt, attrs, attribute.String("db.name", "test-database")) + assert.Contains(mt, attrs, attribute.String("db.system.name", "mongodb")) + assert.Contains(mt, attrs, attribute.String("network.peer.address", ":27017")) + assert.Contains(mt, attrs, attribute.Int64("network.peer.port", int64(27017))) + assert.Contains(mt, attrs, attribute.String("network.transport", "tcp")) + assert.Contains(mt, attrs, attribute.String("db.namespace", "test-database")) for _, v := range tc.validators { assert.True(mt, v(s)) } @@ -245,16 +245,6 @@ func TestDBCollectionAttribute(t *testing.T) { } } -func assertSemconv1170(mt *mtest.T, attrs []attribute.KeyValue) { - mt.Helper() - - assert.Contains(mt, attrs, attribute.String("db.system", "mongodb")) - assert.Contains(mt, attrs, attribute.String("net.peer.name", "")) - assert.Contains(mt, attrs, attribute.Int64("net.peer.port", int64(27017))) - assert.Contains(mt, attrs, attribute.String("net.transport", "ip_tcp")) - assert.Contains(mt, attrs, attribute.String("db.name", "test-database")) -} - func assertSemconv(mt *mtest.T, attrs []attribute.KeyValue) { mt.Helper() @@ -274,7 +264,7 @@ func TestSemanticConventionOptIn(t *testing.T) { { name: "default", semconvOptIn: "", - assert: assertSemconv1170, + assert: assertSemconv, }, { name: "database",