Skip to content

Commit

Permalink
Remove service.name attribute (#763)
Browse files Browse the repository at this point in the history
* Remove service.name attribute

`service.name` should correspond to the Resource of the entity
producing telemetry, not the remote service. If anything, the
attribute that should be used for a database service is `peer.service`.

* remember to make precommit first

* Add note to CHANGELOG regarding removal of service.name attribute
  • Loading branch information
evantorrie authored May 3, 2021
1 parent fd3865e commit 6d3a163
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Removed

- Remove service name from `otelmongodb` configuration and span attributes. (#763)

## [0.20.0] - 2021-04-23

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
func Example() {
// connect to MongoDB
opts := options.Client()
opts.Monitor = otelmongo.NewMonitor("test-service")
opts.Monitor = otelmongo.NewMonitor()
opts.ApplyURI("mongodb://localhost:27017")
client, err := mongo.Connect(context.Background(), opts)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ type spanKey struct {

type monitor struct {
sync.Mutex
spans map[spanKey]trace.Span
serviceName string
cfg config
spans map[spanKey]trace.Span
cfg config
}

func (m *monitor) Started(ctx context.Context, evt *event.CommandStartedEvent) {
hostname, port := peerInfo(evt)

attrs := []attribute.KeyValue{
ServiceName(m.serviceName),
DBOperation(evt.CommandName),
DBInstance(evt.DatabaseName),
DBSystem("mongodb"),
Expand Down Expand Up @@ -100,12 +98,11 @@ func (m *monitor) Finished(evt *event.CommandFinishedEvent, err error) {
}

// NewMonitor creates a new mongodb event CommandMonitor.
func NewMonitor(serviceName string, opts ...Option) *event.CommandMonitor {
func NewMonitor(opts ...Option) *event.CommandMonitor {
cfg := newConfig(opts...)
m := &monitor{
spans: make(map[spanKey]trace.Span),
serviceName: serviceName,
cfg: cfg,
spans: make(map[spanKey]trace.Span),
cfg: cfg,
}
return &event.CommandMonitor{
Started: m.Started,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Test(t *testing.T) {

addr := "mongodb://localhost:27017/?connect=direct"
opts := options.Client()
opts.Monitor = NewMonitor("mongo", WithTracerProvider(provider), WithCommandAttributeDisabled(tc.commandAttributeDisabled))
opts.Monitor = NewMonitor(WithTracerProvider(provider), WithCommandAttributeDisabled(tc.commandAttributeDisabled))
opts.ApplyURI(addr)
client, err := mongo.Connect(ctx, opts)
if err != nil {
Expand All @@ -79,10 +79,9 @@ func Test(t *testing.T) {

spans := sr.Completed()
assert.Len(t, spans, 2)
assert.Equal(t, spans[0].SpanContext().TraceID, spans[1].SpanContext().TraceID)
assert.Equal(t, spans[0].SpanContext().TraceID(), spans[1].SpanContext().TraceID())

s := spans[0]
assert.Equal(t, "mongo", s.Attributes()[ServiceNameKey].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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import "go.opentelemetry.io/otel/attribute"
const (
TargetHostKey = attribute.Key("out.host")
TargetPortKey = attribute.Key("out.port")
ServiceNameKey = attribute.Key("service.name")
DBOperationKey = attribute.Key("db.operation")
ErrorKey = attribute.Key("error")
ErrorMsgKey = attribute.Key("error.msg")
Expand All @@ -35,11 +34,6 @@ func TargetPort(targetPort string) attribute.KeyValue {
return TargetPortKey.String(targetPort)
}

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

// DBOperation defines the name of the operation.
func DBOperation(operation string) attribute.KeyValue {
return DBOperationKey.String(operation)
Expand Down

0 comments on commit 6d3a163

Please sign in to comment.