Skip to content

Commit 3349baf

Browse files
matej-gAneurysm9
andauthored
otelmemcache: Simplify config and span status setting (#477)
* otelmemcache: Simplify config - remove service name - Service name no longer needed - No need to keep config inside of client any longer * otelmemcache: Do not set status and service name attribute - Set status only in case of error * otelmemcache: Adjust tests * Update CHANGELOG * PR feedback - revert to config func Co-authored-by: Anthony Mirabella <[email protected]>
1 parent 62c8535 commit 3349baf

File tree

5 files changed

+14
-70
lines changed

5 files changed

+14
-70
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## [Unreleased]
1010

11+
### Fixed
12+
13+
- `otelmemcache` no longer sets span status to OK instead of leaving it unset. (#477)
14+
15+
### Removed
16+
17+
- Remove service name from `otelmemcache` configuration and span attributes. (#477)
18+
1119
## [0.17.0] - 2021-02-15
1220

1321
### Added

instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/config.go

-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
)
2020

2121
type config struct {
22-
serviceName string
2322
tracerProvider oteltrace.TracerProvider
2423
}
2524

@@ -33,10 +32,3 @@ func WithTracerProvider(provider oteltrace.TracerProvider) Option {
3332
cfg.tracerProvider = provider
3433
}
3534
}
36-
37-
// WithServiceName sets the service name.
38-
func WithServiceName(serviceName string) Option {
39-
return func(cfg *config) {
40-
cfg.serviceName = serviceName
41-
}
42-
}

instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/gomemcache.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ import (
2121

2222
"go.opentelemetry.io/contrib"
2323
"go.opentelemetry.io/otel"
24+
"go.opentelemetry.io/otel/codes"
2425
"go.opentelemetry.io/otel/label"
25-
"go.opentelemetry.io/otel/semconv"
2626
oteltrace "go.opentelemetry.io/otel/trace"
2727
)
2828

2929
const (
30-
defaultTracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache"
31-
defaultServiceName = "memcached"
30+
tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache"
3231
)
3332

3433
// Client is a wrapper around *memcache.Client.
3534
type Client struct {
3635
*memcache.Client
37-
cfg *config
3836
tracer oteltrace.Tracer
3937
ctx context.Context
4038
}
@@ -54,19 +52,14 @@ func NewClientWithTracing(client *memcache.Client, opts ...Option) *Client {
5452
o(cfg)
5553
}
5654

57-
if cfg.serviceName == "" {
58-
cfg.serviceName = defaultServiceName
59-
}
60-
6155
if cfg.tracerProvider == nil {
6256
cfg.tracerProvider = otel.GetTracerProvider()
6357
}
6458

6559
return &Client{
6660
client,
67-
cfg,
6861
cfg.tracerProvider.Tracer(
69-
defaultTracerName,
62+
tracerName,
7063
oteltrace.WithInstrumentationVersion(contrib.SemVersion()),
7164
),
7265
context.Background(),
@@ -77,7 +70,6 @@ func NewClientWithTracing(client *memcache.Client, opts ...Option) *Client {
7770
// of the operation name and item key(s) (if available)
7871
func (c *Client) attrsByOperationAndItemKey(operation operation, key ...string) []label.KeyValue {
7972
labels := []label.KeyValue{
80-
semconv.ServiceNameKey.String(c.cfg.serviceName),
8173
memcacheDBSystem(),
8274
memcacheDBOperation(operation),
8375
}
@@ -111,7 +103,7 @@ func (c *Client) startSpan(operationName operation, itemKey ...string) oteltrace
111103
// Ends span and, if applicable, sets error status
112104
func endSpan(s oteltrace.Span, err error) {
113105
if err != nil {
114-
s.SetStatus(memcacheErrToStatusCode(err), err.Error())
106+
s.SetStatus(codes.Error, err.Error())
115107
}
116108
s.End()
117109
}
@@ -121,7 +113,6 @@ func (c *Client) WithContext(ctx context.Context) *Client {
121113
cc := c.Client
122114
return &Client{
123115
Client: cc,
124-
cfg: c.cfg,
125116
tracer: c.tracer,
126117
ctx: ctx,
127118
}

instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/gomemcache_test.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"go.opentelemetry.io/otel/codes"
2727
"go.opentelemetry.io/otel/label"
2828
"go.opentelemetry.io/otel/oteltest"
29-
"go.opentelemetry.io/otel/semconv"
3029
oteltrace "go.opentelemetry.io/otel/trace"
3130
)
3231

@@ -41,10 +40,7 @@ func TestNewClientWithTracing(t *testing.T) {
4140
)
4241

4342
assert.NotNil(t, c.Client)
44-
assert.NotNil(t, c.cfg)
45-
assert.NotNil(t, c.cfg.tracerProvider)
4643
assert.NotNil(t, c.tracer)
47-
assert.Equal(t, defaultServiceName, c.cfg.serviceName)
4844
}
4945

5046
func TestOperation(t *testing.T) {
@@ -61,10 +57,9 @@ func TestOperation(t *testing.T) {
6157
assert.Len(t, spans, 1)
6258
assert.Equal(t, oteltrace.SpanKindClient, spans[0].SpanKind())
6359
assert.Equal(t, string(operationAdd), spans[0].Name())
64-
assert.Len(t, spans[0].Attributes(), 4)
60+
assert.Len(t, spans[0].Attributes(), 3)
6561

6662
expectedLabelMap := map[label.Key]label.Value{
67-
semconv.ServiceNameKey: semconv.ServiceNameKey.String(defaultServiceName).Value,
6863
memcacheDBSystem().Key: memcacheDBSystem().Value,
6964
memcacheDBOperation(operationAdd).Key: memcacheDBOperation(operationAdd).Value,
7065
label.Key(memcacheDBItemKeyName).String(mi.Key).Key: label.Key(memcacheDBItemKeyName).String(mi.Key).Value,
@@ -83,10 +78,9 @@ func TestOperationWithCacheMissError(t *testing.T) {
8378
assert.Len(t, spans, 1)
8479
assert.Equal(t, oteltrace.SpanKindClient, spans[0].SpanKind())
8580
assert.Equal(t, string(operationGet), spans[0].Name())
86-
assert.Len(t, spans[0].Attributes(), 4)
81+
assert.Len(t, spans[0].Attributes(), 3)
8782

8883
expectedLabelMap := map[label.Key]label.Value{
89-
semconv.ServiceNameKey: semconv.ServiceNameKey.String(defaultServiceName).Value,
9084
memcacheDBSystem().Key: memcacheDBSystem().Value,
9185
memcacheDBOperation(operationGet).Key: memcacheDBOperation(operationGet).Value,
9286
label.Key(memcacheDBItemKeyName).String(key).Key: label.Key(memcacheDBItemKeyName).String(key).Value,

instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/status.go

-41
This file was deleted.

0 commit comments

Comments
 (0)