1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Zipkin Exporter: Use default resouce's serviceName as default serivce name (#1777) (#1786)

Signed-off-by: lastchiliarch <lastchiliarch@163.com>

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
sicong.huang
2021-04-12 23:36:21 +08:00
committed by GitHub
parent 4d141e4752
commit 9b25164481
3 changed files with 20 additions and 8 deletions
+1
View File
@@ -49,6 +49,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed
- Modify Zipkin Exporter default service name, use default resouce's serviceName instead of empty. (#1777)
- Updated Jaeger Environment Variables: `JAEGER_ENDPOINT`, `JAEGER_USER`, `JAEGER_PASSWORD`
to `OTEL_EXPORTER_JAEGER_ENDPOINT`, `OTEL_EXPORTER_JAEGER_USER`, `OTEL_EXPORTER_JAEGER_PASSWORD`
in compliance with OTel spec (#1752)
+17 -6
View File
@@ -21,14 +21,16 @@ import (
"net"
"strconv"
zkmodel "github.com/openzipkin/zipkin-go/model"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/semconv"
"go.opentelemetry.io/otel/trace"
zkmodel "github.com/openzipkin/zipkin-go/model"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
)
const (
@@ -39,6 +41,16 @@ const (
keyPeerAddress attribute.Key = "peer.address"
)
var defaultServiceName string
func init() {
// fetch service.name from default resource for backup
defaultResource := resource.Default()
if value, exists := defaultResource.Set().Value(semconv.ServiceNameKey); exists {
defaultServiceName = value.AsString()
}
}
func toZipkinSpanModels(batch []*tracesdk.SpanSnapshot) []zkmodel.SpanModel {
models := make([]zkmodel.SpanModel, 0, len(batch))
for _, data := range batch {
@@ -54,8 +66,7 @@ func getServiceName(attrs []attribute.KeyValue) string {
}
}
// Resource holds a default value so this might not be reach.
return ""
return defaultServiceName
}
func toZipkinSpanModel(data *tracesdk.SpanSnapshot) zkmodel.SpanModel {
+2 -2
View File
@@ -954,10 +954,10 @@ func TestRemoteEndpointTransformation(t *testing.T) {
func TestServiceName(t *testing.T) {
attrs := []attribute.KeyValue{}
assert.Empty(t, getServiceName(attrs))
assert.Equal(t, defaultServiceName, getServiceName(attrs))
attrs = append(attrs, attribute.String("test_key", "test_value"))
assert.Empty(t, getServiceName(attrs))
assert.Equal(t, defaultServiceName, getServiceName(attrs))
attrs = append(attrs, semconv.ServiceNameKey.String("my_service"))
assert.Equal(t, "my_service", getServiceName(attrs))