Skip to content

Commit

Permalink
Zipkin Exporter: Use default resouce's serviceName as default serivce…
Browse files Browse the repository at this point in the history
… name (open-telemetry#1777)

Signed-off-by: lastchiliarch <lastchiliarch@163.com>
  • Loading branch information
lastchiliarch committed Apr 8, 2021
1 parent 7d8e6bd commit fd9218d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions exporters/trace/zipkin/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"go.opentelemetry.io/otel/sdk/resource"
"net"
"strconv"

Expand Down Expand Up @@ -54,8 +55,13 @@ func getServiceName(attrs []attribute.KeyValue) string {
}
}

// Resource holds a default value so this might not be reach.
return ""
// Fetch default service.name from default resource for backup
var defaultServiceName string
defaultResource := resource.Default()
if value, exists := defaultResource.Set().Value(semconv.ServiceNameKey); exists {
defaultServiceName = value.AsString()
}
return defaultServiceName
}

func toZipkinSpanModel(data *tracesdk.SpanSnapshot) zkmodel.SpanModel {
Expand Down
5 changes: 3 additions & 2 deletions exporters/trace/zipkin/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,11 +953,12 @@ func TestRemoteEndpointTransformation(t *testing.T) {
}

func TestServiceName(t *testing.T) {
defaultServiceName := "unknown_service:___TestServiceName_in_go_opentelemetry_io_otel_exporters_trace_zipkin"
attrs := []attribute.KeyValue{}
assert.Empty(t, getServiceName(attrs))
assert.Equal(t, getServiceName(attrs), defaultServiceName)

attrs = append(attrs, attribute.String("test_key", "test_value"))
assert.Empty(t, getServiceName(attrs))
assert.Equal(t, getServiceName(attrs), defaultServiceName)

attrs = append(attrs, semconv.ServiceNameKey.String("my_service"))
assert.Equal(t, "my_service", getServiceName(attrs))
Expand Down

0 comments on commit fd9218d

Please sign in to comment.