Skip to content

Commit

Permalink
mongo: use db.operation instead of resource.name (#337)
Browse files Browse the repository at this point in the history
* mongo: use db.operation instead of resource.name

* mongo: remove unused tags
  • Loading branch information
vmihailenco committed Sep 13, 2020
1 parent 39944bf commit 9434278
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
2 changes: 1 addition & 1 deletion instrumentation/go.mongodb.org/mongo-driver/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (m *monitor) Started(ctx context.Context, evt *event.CommandStartedEvent) {
b, _ := bson.MarshalExtJSON(evt.Command, false, false)
attrs := []label.KeyValue{
ServiceName(m.serviceName),
ResourceName("mongo." + evt.CommandName),
DBOperation(evt.CommandName),
DBInstance(evt.DatabaseName),
DBStatement(string(b)),
DBSystem("mongodb"),
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/go.mongodb.org/mongo-driver/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Test(t *testing.T) {

s := spans[0]
assert.Equal(t, "mongo", s.Attributes[ServiceNameKey].AsString())
assert.Equal(t, "mongo.insert", s.Attributes[ResourceNameKey].AsString())
assert.Equal(t, "insert", s.Attributes[DBOperationKey].AsString())
assert.Equal(t, hostname, s.Attributes[PeerHostnameKey].AsString())
assert.Equal(t, port, s.Attributes[PeerPortKey].AsString())
assert.Contains(t, s.Attributes[DBStatementKey].AsString(), `"test-item":"test-value"`)
Expand Down
42 changes: 9 additions & 33 deletions instrumentation/go.mongodb.org/mongo-driver/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ package mongo
import "go.opentelemetry.io/otel/label"

const (
TargetHostKey = label.Key("out.host")
TargetPortKey = label.Key("out.port")
HTTPMethodKey = label.Key("http.method")
HTTPCodeKey = label.Key("http.code")
HTTPURLKey = label.Key("http.url")
SpanTypeKey = label.Key("span.type")
ServiceNameKey = label.Key("service.name")
ResourceNameKey = label.Key("resource.name")
ErrorKey = label.Key("error")
ErrorMsgKey = label.Key("error.msg")
TargetHostKey = label.Key("out.host")
TargetPortKey = label.Key("out.port")
ServiceNameKey = label.Key("service.name")
DBOperationKey = label.Key("db.operation")
ErrorKey = label.Key("error")
ErrorMsgKey = label.Key("error.msg")
)

// TargetHost sets the target host address.
Expand All @@ -39,34 +35,14 @@ func TargetPort(targetPort string) label.KeyValue {
return TargetPortKey.String(targetPort)
}

// HTTPMethod specifies the HTTP method used in a span.
func HTTPMethod(httpMethod string) label.KeyValue {
return HTTPMethodKey.String(httpMethod)
}

// HTTPCode sets the HTTP status code as a attribute.
func HTTPCode(httpCode string) label.KeyValue {
return HTTPCodeKey.String(httpCode)
}

// HTTPURL sets the HTTP URL for a span.
func HTTPURL(httpURL string) label.KeyValue {
return HTTPURLKey.String(httpURL)
}

// SpanType defines the Span type (web, db, cache).
func SpanType(spanType string) label.KeyValue {
return SpanTypeKey.String(spanType)
}

// ServiceName defines the Service name for this Span.
func ServiceName(serviceName string) label.KeyValue {
return ServiceNameKey.String(serviceName)
}

// ResourceName defines the Resource name for the Span.
func ResourceName(resourceName string) label.KeyValue {
return ResourceNameKey.String(resourceName)
// DBOperation defines the name of the operation.
func DBOperation(operation string) label.KeyValue {
return DBOperationKey.String(operation)
}

// Error specifies whether an error occurred.
Expand Down

0 comments on commit 9434278

Please sign in to comment.