From 7ae31588b76d4afda2f632279d43314da4324476 Mon Sep 17 00:00:00 2001 From: Afzal Ansari Date: Mon, 7 Aug 2023 18:47:05 +0000 Subject: [PATCH 1/8] replace ot with otel traces and const Signed-off-by: Afzal Ansari --- .../pkg/tracing/rpcmetrics/observer_test.go | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index 89f1db38695..295d4980fcf 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -16,24 +16,25 @@ package rpcmetrics import ( + "context" "fmt" "testing" "time" - opentracing "github.com/opentracing/opentracing-go" "github.com/stretchr/testify/assert" - otbridge "go.opentelemetry.io/otel/bridge/opentracing" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.7.0" - "github.com/opentracing/opentracing-go/ext" + "go.opentelemetry.io/otel/trace" u "github.com/jaegertracing/jaeger/internal/metricstest" ) type testTracer struct { metrics *u.Factory - tracer opentracing.Tracer + tracer trace.TracerProvider } func withTestTracer(runTest func(tt *testTracer)) { @@ -47,46 +48,39 @@ func withTestTracer(runTest func(tt *testTracer)) { semconv.ServiceNameKey.String("test"), )), ) - tracer, _ := otbridge.NewTracerPair(tp.Tracer("")) runTest(&testTracer{ metrics: metrics, - tracer: tracer, + tracer: tp, }) } func TestObserver(t *testing.T) { withTestTracer(func(testTracer *testTracer) { ts := time.Now() - finishOptions := opentracing.FinishOptions{ - FinishTime: ts.Add(50 * time.Millisecond), - } + finishOptions := trace.WithTimestamp(ts.Add((50 * time.Millisecond))) testCases := []struct { name string - tag opentracing.Tag + tag trace.SpanKind opNameOverride string err bool }{ - {name: "local-span", tag: opentracing.Tag{Key: "x", Value: "y"}}, - {name: "get-user", tag: ext.SpanKindRPCServer}, - {name: "get-user", tag: ext.SpanKindRPCServer, opNameOverride: "get-user-override"}, - {name: "get-user", tag: ext.SpanKindRPCServer, err: true}, - {name: "get-user-client", tag: ext.SpanKindRPCClient}, + {name: "local-span", tag: trace.SpanKindInternal}, + {name: "get-user", tag: trace.SpanKindServer}, + {name: "get-user", tag: trace.SpanKindServer, opNameOverride: "get-user-override"}, + {name: "get-user", tag: trace.SpanKindServer, err: true}, + {name: "get-user-client", tag: trace.SpanKindClient}, } for _, testCase := range testCases { - span := testTracer.tracer.StartSpan( - testCase.name, - testCase.tag, - opentracing.StartTime(ts), - ) + _, span := testTracer.tracer.Tracer("test").Start(context.Background(), testCase.name, trace.WithSpanKind(testCase.tag), trace.WithTimestamp(ts)) if testCase.opNameOverride != "" { - span.SetOperationName(testCase.opNameOverride) + span.SetName(testCase.opNameOverride) } if testCase.err { - ext.Error.Set(span, true) + span.SetStatus(codes.Error, "An error occured") } - span.FinishWithOptions(finishOptions) + span.End(finishOptions) } testTracer.metrics.AssertCounterMetrics(t, @@ -152,9 +146,9 @@ func TestTags(t *testing.T) { } t.Run(fmt.Sprintf("%s-%v-%s", testCase.key, testCase.value, testCase.variant), func(t *testing.T) { withTestTracer(func(testTracer *testTracer) { - span := testTracer.tracer.StartSpan("span", ext.SpanKindRPCServer) - span.SetTag(testCase.key, testCase.value) - span.Finish() + _, span := testTracer.tracer.Tracer("test").Start(context.Background(), "span", trace.WithSpanKind(trace.SpanKindServer)) + span.SetAttributes(attribute.Key(testCase.key).String(testCase.value.(string))) + span.End() testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...) }) }) From 7adf8457e70353d7330fd4f26e78e3453f1e8ccb Mon Sep 17 00:00:00 2001 From: Afzal Ansari Date: Tue, 8 Aug 2023 19:20:57 +0000 Subject: [PATCH 2/8] transform interface into type Signed-off-by: Afzal Ansari --- .../pkg/tracing/rpcmetrics/observer_test.go | 37 +++++++++++-------- model/span.go | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index 295d4980fcf..fb65bd94529 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -34,7 +34,7 @@ import ( type testTracer struct { metrics *u.Factory - tracer trace.TracerProvider + tracer trace.Tracer } func withTestTracer(runTest func(tt *testTracer)) { @@ -50,7 +50,7 @@ func withTestTracer(runTest func(tt *testTracer)) { ) runTest(&testTracer{ metrics: metrics, - tracer: tp, + tracer: tp.Tracer("test"), }) } @@ -61,19 +61,19 @@ func TestObserver(t *testing.T) { testCases := []struct { name string - tag trace.SpanKind + spanKind trace.SpanKind opNameOverride string err bool }{ - {name: "local-span", tag: trace.SpanKindInternal}, - {name: "get-user", tag: trace.SpanKindServer}, - {name: "get-user", tag: trace.SpanKindServer, opNameOverride: "get-user-override"}, - {name: "get-user", tag: trace.SpanKindServer, err: true}, - {name: "get-user-client", tag: trace.SpanKindClient}, + {name: "local-span", spanKind: trace.SpanKindInternal}, + {name: "get-user", spanKind: trace.SpanKindServer}, + {name: "get-user", spanKind: trace.SpanKindServer, opNameOverride: "get-user-override"}, + {name: "get-user", spanKind: trace.SpanKindServer, err: true}, + {name: "get-user-client", spanKind: trace.SpanKindClient}, } for _, testCase := range testCases { - _, span := testTracer.tracer.Tracer("test").Start(context.Background(), testCase.name, trace.WithSpanKind(testCase.tag), trace.WithTimestamp(ts)) + _, span := testTracer.tracer.Start(context.Background(), testCase.name, trace.WithSpanKind(testCase.spanKind), trace.WithTimestamp(ts)) if testCase.opNameOverride != "" { span.SetName(testCase.opNameOverride) } @@ -113,10 +113,6 @@ func TestTags(t *testing.T) { {key: "error", value: true, metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "true")}, }}, - // OTEL bridge does not interpret string "true" as error status - // {key: "error", value: "true", variant: "string", metrics: []u.ExpectedMetric{ - // {Name: "requests", Value: 1, Tags: tags("error", "true")}, - // }}, } for i := 200; i <= 500; i += 100 { @@ -146,8 +142,19 @@ func TestTags(t *testing.T) { } t.Run(fmt.Sprintf("%s-%v-%s", testCase.key, testCase.value, testCase.variant), func(t *testing.T) { withTestTracer(func(testTracer *testTracer) { - _, span := testTracer.tracer.Tracer("test").Start(context.Background(), "span", trace.WithSpanKind(trace.SpanKindServer)) - span.SetAttributes(attribute.Key(testCase.key).String(testCase.value.(string))) + _, span := testTracer.tracer.Start(context.Background(), "span", trace.WithSpanKind(trace.SpanKindServer)) + switch v := testCase.value.(type) { + case int: + span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) + case bool: + span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) + case int64: + span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) + case uint16: + span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) + default: + span.SetAttributes(attribute.Key(testCase.key).String(v.(string))) + } span.End() testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...) }) diff --git a/model/span.go b/model/span.go index 253aca52bd7..a6d7d55c484 100644 --- a/model/span.go +++ b/model/span.go @@ -78,7 +78,7 @@ func (s *Span) GetSpanKind() (spanKind trace.SpanKind, found bool) { // GetSamplerType returns the sampler type for span func (s *Span) GetSamplerType() string { - // There's no corresponding opentracing-go tag label corresponding to sampler.type + // There's no corresponding opentelemetry tag label corresponding to sampler.type if tag, ok := KeyValues(s.Tags).FindByKey(samplerType); ok { if tag.VStr == "" { return samplerTypeUnknown From 3c8cb9aee9cbcba72ba1f58e44ac36d69459e5d6 Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:47:07 +0000 Subject: [PATCH 3/8] reformats attr Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- .../pkg/tracing/rpcmetrics/observer_test.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index fb65bd94529..5bab461211b 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -103,14 +103,15 @@ func TestTags(t *testing.T) { key string variant string value interface{} + attr attribute.KeyValue metrics []u.ExpectedMetric } testCases := []tagTestCase{ - {key: "something", value: 42, metrics: []u.ExpectedMetric{ + {key: "something", value: 42, attr: attribute.Key("something").String(fmt.Sprint(42)), metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "false")}, }}, - {key: "error", value: true, metrics: []u.ExpectedMetric{ + {key: "error", value: true, attr: attribute.Key("error").String(fmt.Sprint(true)), metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "true")}, }}, } @@ -128,6 +129,7 @@ func TestTags(t *testing.T) { testCases = append(testCases, tagTestCase{ key: "http.status_code", value: v.value, + attr: attribute.Key("http.status_code").String(fmt.Sprint(v.value)), variant: v.variant, metrics: []u.ExpectedMetric{ {Name: "http_requests", Value: 1, Tags: tags("status_code", fmt.Sprintf("%dxx", i/100))}, @@ -143,18 +145,7 @@ func TestTags(t *testing.T) { t.Run(fmt.Sprintf("%s-%v-%s", testCase.key, testCase.value, testCase.variant), func(t *testing.T) { withTestTracer(func(testTracer *testTracer) { _, span := testTracer.tracer.Start(context.Background(), "span", trace.WithSpanKind(trace.SpanKindServer)) - switch v := testCase.value.(type) { - case int: - span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) - case bool: - span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) - case int64: - span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) - case uint16: - span.SetAttributes(attribute.Key(testCase.key).String(fmt.Sprint(v))) - default: - span.SetAttributes(attribute.Key(testCase.key).String(v.(string))) - } + span.SetAttributes(testCase.attr) span.End() testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...) }) From ae6b6593827cb4f011351d45f70a7120c9c21433 Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Thu, 10 Aug 2023 08:26:25 +0000 Subject: [PATCH 4/8] rmvs key-value pair Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- .../pkg/tracing/rpcmetrics/observer_test.go | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index 5bab461211b..6dcf9c69d63 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -73,7 +73,11 @@ func TestObserver(t *testing.T) { } for _, testCase := range testCases { - _, span := testTracer.tracer.Start(context.Background(), testCase.name, trace.WithSpanKind(testCase.spanKind), trace.WithTimestamp(ts)) + _, span := testTracer.tracer.Start( + context.Background(), + testCase.name, trace.WithSpanKind(testCase.spanKind), + trace.WithTimestamp(ts), + ) if testCase.opNameOverride != "" { span.SetName(testCase.opNameOverride) } @@ -100,18 +104,16 @@ func TestObserver(t *testing.T) { func TestTags(t *testing.T) { type tagTestCase struct { - key string variant string - value interface{} attr attribute.KeyValue metrics []u.ExpectedMetric } testCases := []tagTestCase{ - {key: "something", value: 42, attr: attribute.Key("something").String(fmt.Sprint(42)), metrics: []u.ExpectedMetric{ + {attr: attribute.Key("something").Int(42), metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "false")}, }}, - {key: "error", value: true, attr: attribute.Key("error").String(fmt.Sprint(true)), metrics: []u.ExpectedMetric{ + {attr: attribute.Key("error").Bool(true), metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "true")}, }}, } @@ -127,8 +129,6 @@ func TestTags(t *testing.T) { } for _, v := range status_codes { testCases = append(testCases, tagTestCase{ - key: "http.status_code", - value: v.value, attr: attribute.Key("http.status_code").String(fmt.Sprint(v.value)), variant: v.variant, metrics: []u.ExpectedMetric{ @@ -142,9 +142,12 @@ func TestTags(t *testing.T) { for i := range testCase.metrics { testCase.metrics[i].Tags["endpoint"] = "span" } - t.Run(fmt.Sprintf("%s-%v-%s", testCase.key, testCase.value, testCase.variant), func(t *testing.T) { + t.Run(fmt.Sprintf("%s-%v-%s", testCase.attr.Key, testCase.attr.Value, testCase.variant), func(t *testing.T) { withTestTracer(func(testTracer *testTracer) { - _, span := testTracer.tracer.Start(context.Background(), "span", trace.WithSpanKind(trace.SpanKindServer)) + _, span := testTracer.tracer.Start( + context.Background(), + "span", trace.WithSpanKind(trace.SpanKindServer), + ) span.SetAttributes(testCase.attr) span.End() testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...) From 17153088cba979d6b3fa468bda91c15500c3194d Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Fri, 11 Aug 2023 17:06:44 +0000 Subject: [PATCH 5/8] updates the span attr val Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- .../pkg/tracing/rpcmetrics/observer_test.go | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index 6dcf9c69d63..305f90e9d71 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -104,33 +104,20 @@ func TestObserver(t *testing.T) { func TestTags(t *testing.T) { type tagTestCase struct { - variant string attr attribute.KeyValue metrics []u.ExpectedMetric } - - testCases := []tagTestCase{ - {attr: attribute.Key("something").Int(42), metrics: []u.ExpectedMetric{ - {Name: "requests", Value: 1, Tags: tags("error", "false")}, - }}, - {attr: attribute.Key("error").Bool(true), metrics: []u.ExpectedMetric{ - {Name: "requests", Value: 1, Tags: tags("error", "true")}, - }}, - } + testCases := []tagTestCase{} for i := 200; i <= 500; i += 100 { status_codes := []struct { - value interface{} - variant string + value int64 }{ - {value: i}, - {value: uint16(i), variant: "uint16"}, - {value: fmt.Sprintf("%d", i), variant: "string"}, + {value: int64(i)}, } for _, v := range status_codes { testCases = append(testCases, tagTestCase{ - attr: attribute.Key("http.status_code").String(fmt.Sprint(v.value)), - variant: v.variant, + attr: attribute.Key(semconv.HTTPStatusCodeKey).Int64(v.value), metrics: []u.ExpectedMetric{ {Name: "http_requests", Value: 1, Tags: tags("status_code", fmt.Sprintf("%dxx", i/100))}, }, @@ -142,7 +129,7 @@ func TestTags(t *testing.T) { for i := range testCase.metrics { testCase.metrics[i].Tags["endpoint"] = "span" } - t.Run(fmt.Sprintf("%s-%v-%s", testCase.attr.Key, testCase.attr.Value, testCase.variant), func(t *testing.T) { + t.Run(fmt.Sprintf("%s-%v", testCase.attr.Key, testCase.attr.Value), func(t *testing.T) { withTestTracer(func(testTracer *testTracer) { _, span := testTracer.tracer.Start( context.Background(), From 9c1689e8a72bf252f41a510569858a06b1bed1e5 Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Fri, 11 Aug 2023 17:43:56 +0000 Subject: [PATCH 6/8] adds the testcase related to metrics Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index 305f90e9d71..a1378c2c64d 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -107,7 +107,14 @@ func TestTags(t *testing.T) { attr attribute.KeyValue metrics []u.ExpectedMetric } - testCases := []tagTestCase{} + testCases := []tagTestCase{ + {attr: attribute.Key("something").Int(42), metrics: []u.ExpectedMetric{ + {Name: "requests", Value: 1, Tags: tags("error", "false")}, + }}, + {attr: attribute.Key("error").Bool(true), metrics: []u.ExpectedMetric{ + {Name: "requests", Value: 1, Tags: tags("error", "true")}, + }}, + } for i := 200; i <= 500; i += 100 { status_codes := []struct { From 634d0a703ed560c4dd9795ab6699a84be41ad5c5 Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Fri, 11 Aug 2023 18:26:30 +0000 Subject: [PATCH 7/8] set span status for error Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- .../pkg/tracing/rpcmetrics/observer_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index a1378c2c64d..686895f36ee 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -65,11 +65,11 @@ func TestObserver(t *testing.T) { opNameOverride string err bool }{ - {name: "local-span", spanKind: trace.SpanKindInternal}, - {name: "get-user", spanKind: trace.SpanKindServer}, - {name: "get-user", spanKind: trace.SpanKindServer, opNameOverride: "get-user-override"}, + {name: "local-span", spanKind: trace.SpanKindInternal, err: false}, + {name: "get-user", spanKind: trace.SpanKindServer, err: false}, + {name: "get-user", spanKind: trace.SpanKindServer, opNameOverride: "get-user-override", err: false}, {name: "get-user", spanKind: trace.SpanKindServer, err: true}, - {name: "get-user-client", spanKind: trace.SpanKindClient}, + {name: "get-user-client", spanKind: trace.SpanKindClient, err: false}, } for _, testCase := range testCases { @@ -108,10 +108,10 @@ func TestTags(t *testing.T) { metrics []u.ExpectedMetric } testCases := []tagTestCase{ - {attr: attribute.Key("something").Int(42), metrics: []u.ExpectedMetric{ + {attr: attribute.Key("Something").Int(42), metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "false")}, }}, - {attr: attribute.Key("error").Bool(true), metrics: []u.ExpectedMetric{ + {attr: attribute.Key("Error").Bool(true), metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "true")}, }}, } @@ -143,6 +143,9 @@ func TestTags(t *testing.T) { "span", trace.WithSpanKind(trace.SpanKindServer), ) span.SetAttributes(testCase.attr) + if testCase.attr.Key == attribute.Key(codes.Error.String()) { + span.SetStatus(codes.Error, "An error occured") + } span.End() testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...) }) From 4f454eae89c9509d99992dfc1f329aaeebd58f8c Mon Sep 17 00:00:00 2001 From: Afzal <94980910+afzalbin64@users.noreply.github.com> Date: Sat, 12 Aug 2023 07:18:29 +0000 Subject: [PATCH 8/8] updates attr keys Signed-off-by: Afzal <94980910+afzalbin64@users.noreply.github.com> --- .../pkg/tracing/rpcmetrics/observer_test.go | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go index 686895f36ee..19d7ba348dc 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go @@ -26,7 +26,7 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.7.0" + semconv "go.opentelemetry.io/otel/semconv/v1.20.0" "go.opentelemetry.io/otel/trace" u "github.com/jaegertracing/jaeger/internal/metricstest" @@ -65,11 +65,11 @@ func TestObserver(t *testing.T) { opNameOverride string err bool }{ - {name: "local-span", spanKind: trace.SpanKindInternal, err: false}, - {name: "get-user", spanKind: trace.SpanKindServer, err: false}, - {name: "get-user", spanKind: trace.SpanKindServer, opNameOverride: "get-user-override", err: false}, + {name: "local-span", spanKind: trace.SpanKindInternal}, + {name: "get-user", spanKind: trace.SpanKindServer}, + {name: "get-user", spanKind: trace.SpanKindServer, opNameOverride: "get-user-override"}, {name: "get-user", spanKind: trace.SpanKindServer, err: true}, - {name: "get-user-client", spanKind: trace.SpanKindClient, err: false}, + {name: "get-user-client", spanKind: trace.SpanKindClient}, } for _, testCase := range testCases { @@ -105,31 +105,25 @@ func TestObserver(t *testing.T) { func TestTags(t *testing.T) { type tagTestCase struct { attr attribute.KeyValue + err bool metrics []u.ExpectedMetric } testCases := []tagTestCase{ - {attr: attribute.Key("Something").Int(42), metrics: []u.ExpectedMetric{ + {err: false, metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "false")}, }}, - {attr: attribute.Key("Error").Bool(true), metrics: []u.ExpectedMetric{ + {err: true, metrics: []u.ExpectedMetric{ {Name: "requests", Value: 1, Tags: tags("error", "true")}, }}, } for i := 200; i <= 500; i += 100 { - status_codes := []struct { - value int64 - }{ - {value: int64(i)}, - } - for _, v := range status_codes { - testCases = append(testCases, tagTestCase{ - attr: attribute.Key(semconv.HTTPStatusCodeKey).Int64(v.value), - metrics: []u.ExpectedMetric{ - {Name: "http_requests", Value: 1, Tags: tags("status_code", fmt.Sprintf("%dxx", i/100))}, - }, - }) - } + testCases = append(testCases, tagTestCase{ + attr: semconv.HTTPStatusCode(i), + metrics: []u.ExpectedMetric{ + {Name: "http_requests", Value: 1, Tags: tags("status_code", fmt.Sprintf("%dxx", i/100))}, + }, + }) } for _, testCase := range testCases { @@ -143,7 +137,7 @@ func TestTags(t *testing.T) { "span", trace.WithSpanKind(trace.SpanKindServer), ) span.SetAttributes(testCase.attr) - if testCase.attr.Key == attribute.Key(codes.Error.String()) { + if testCase.err { span.SetStatus(codes.Error, "An error occured") } span.End()