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

feat(attributes) bump semconv to 1.26.0 #6172

Closed
Closed
Show file tree
Hide file tree
Changes from 5 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 @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed

- The function signature of `NewLogProcessor` in `go.opentelemetry.io/contrib/processors/minsev` has changed to accept the added `Severitier` interface instead of a `log.Severity`. (#6116)
- Attributes for otelmongo will change to reflect [semconv/v1.26.0](https://github.com/open-telemetry/opentelemetry-go/pull/5476). `db.operation` will change to `db.operation.name`, `db.name` will change to `db.namespace`, `net.peer.port` will change to `network.peer.port`, `net.transport` will change to `network.transport`, and `db.statement` will change to `db.query.text`.
prestonvasquez marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package otelmongo // import "go.opentelemetry.io/contrib/instrumentation/go.mong
import (
"context"
"fmt"
"net"
"strconv"
"strings"
"sync"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
"go.opentelemetry.io/otel/trace"

"go.mongodb.org/mongo-driver/bson"
Expand All @@ -37,18 +38,18 @@ func (m *monitor) Started(ctx context.Context, evt *event.CommandStartedEvent) {

attrs := []attribute.KeyValue{
semconv.DBSystemMongoDB,
semconv.DBOperation(evt.CommandName),
semconv.DBName(evt.DatabaseName),
semconv.NetPeerName(hostname),
semconv.NetPeerPort(port),
semconv.NetTransportTCP,
semconv.DBOperationName(evt.CommandName),
semconv.DBNamespace(evt.DatabaseName),
semconv.NetworkPeerAddress(net.JoinHostPort(hostname, strconv.Itoa(port))),
semconv.NetworkPeerPort(port),
semconv.NetworkTransportTCP,
}
if !m.cfg.CommandAttributeDisabled {
attrs = append(attrs, semconv.DBStatement(sanitizeCommand(evt.Command)))
attrs = append(attrs, semconv.DBQueryText(sanitizeCommand(evt.Command)))
}
if collection, err := extractCollection(evt); err == nil && collection != "" {
spanName = collection + "."
attrs = append(attrs, semconv.DBMongoDBCollection(collection))
attrs = append(attrs, semconv.DBCollectionName(collection))
}
spanName += evt.CommandName
opts := []trace.SpanStartOption{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"`)
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -131,10 +131,10 @@ func TestDBCrudOperation(t *testing.T) {
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", "<mock_connection>"))
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("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"))
assert.Contains(mt, attrs, attribute.String("db.namespace", "test-database"))
for _, v := range tc.validators {
assert.True(mt, v(s))
}
Expand All @@ -160,10 +160,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)
Expand All @@ -186,7 +186,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)
Expand Down Expand Up @@ -238,10 +238,10 @@ func TestDBCollectionAttribute(t *testing.T) {
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", "<mock_connection>"))
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("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"))
assert.Contains(mt, attrs, attribute.String("db.namespace", "test-database"))
for _, v := range tc.validators {
assert.True(mt, v(s))
}
Expand Down
Loading