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

Remove service.name attribute #763

Merged
merged 4 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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