Skip to content

Commit

Permalink
Adjustments for new semconv attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
evantorrie committed Aug 3, 2021
1 parent 2515794 commit 54f346d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,3 @@ func WithCommandAttributeDisabled(disabled bool) Option {
cfg.CommandAttributeDisabled = disabled
})
}

// WithCommandAttributeDisabled specifies if the MongoDB command is added as an attribute to Spans or not.
// The MongoDB command will be added as an attribute to Spans by default if this option is not provided.
func WithCommandAttributeDisabled(disabled bool) Option {
return func(cfg *config) {
cfg.CommandAttributeDisabled = disabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

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

"go.mongodb.org/mongo-driver/bson"
Expand All @@ -48,7 +48,7 @@ func (m *monitor) Started(ctx context.Context, evt *event.CommandStartedEvent) {
hostname, port := peerInfo(evt)

attrs := []attribute.KeyValue{
semconv.DBSystemMongodb,
semconv.DBSystemMongoDB,
semconv.DBOperationKey.String(evt.CommandName),
semconv.DBNameKey.String(evt.DatabaseName),
semconv.NetPeerNameKey.String(hostname),
Expand All @@ -62,7 +62,7 @@ func (m *monitor) Started(ctx context.Context, evt *event.CommandStartedEvent) {
spanName = collection + "."
attrs = append(attrs, semconv.DBMongoDBCollectionKey.String(collection))
}

spanName += evt.CommandName
opts := []trace.SpanStartOption{
trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(attrs...),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type validator func(*oteltest.Span) bool
func TestDBCrudOperation(t *testing.T) {
commonValidators := []validator{
func(s *oteltest.Span) bool {
return assert.Equal(t, "test-collection.insert", s.Name())
return assert.Equal(t, "test-collection.insert", s.Name(), "expected %s", s.Name())
},
func(s *oteltest.Span) bool {
return assert.Equal(t, "insert", s.Attributes()["db.operation"].AsString())
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestDBCrudOperation(t *testing.T) {
assert.Equal(t, "mongodb", s.Attributes()["db.system"].AsString())
assert.Equal(t, "localhost", s.Attributes()["net.peer.name"].AsString())
assert.Equal(t, int64(27017), s.Attributes()["net.peer.port"].AsInt64())
assert.Equal(t, "IP.TCP", s.Attributes()["net.transport"].AsString())
assert.Equal(t, "ip_tcp", s.Attributes()["net.transport"].AsString())
assert.Equal(t, "test-database", s.Attributes()["db.name"].AsString())
for _, v := range tc.validators {
assert.True(t, v(s))
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestDBCollectionAttribute(t *testing.T) {
assert.Equal(t, "mongodb", s.Attributes()["db.system"].AsString())
assert.Equal(t, "localhost", s.Attributes()["net.peer.name"].AsString())
assert.Equal(t, int64(27017), s.Attributes()["net.peer.port"].AsInt64())
assert.Equal(t, "IP.TCP", s.Attributes()["net.transport"].AsString())
assert.Equal(t, "ip_tcp", s.Attributes()["net.transport"].AsString())
assert.Equal(t, "test-database", s.Attributes()["db.name"].AsString())
for _, v := range tc.validators {
assert.True(t, v(s))
Expand Down

0 comments on commit 54f346d

Please sign in to comment.