1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-12-01 23:12:29 +02:00

Move tracing code to trace package (#1307)

* Move tracing code to trace package

* Update changelog
This commit is contained in:
Krzesimir Nowak
2020-11-06 23:13:31 +01:00
committed by GitHub
parent 9ac3a08eef
commit 3268501910
58 changed files with 857 additions and 808 deletions

View File

@@ -18,13 +18,14 @@ import (
"context"
"testing"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
func BenchmarkStartEndSpan(b *testing.B) {
traceBenchmark(b, "Benchmark StartEndSpan", func(b *testing.B, t otel.Tracer) {
traceBenchmark(b, "Benchmark StartEndSpan", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -35,7 +36,7 @@ func BenchmarkStartEndSpan(b *testing.B) {
}
func BenchmarkSpanWithAttributes_4(b *testing.B) {
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t otel.Tracer) {
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()
@@ -53,7 +54,7 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) {
}
func BenchmarkSpanWithAttributes_8(b *testing.B) {
traceBenchmark(b, "Benchmark Start With 8 Attributes", func(b *testing.B, t otel.Tracer) {
traceBenchmark(b, "Benchmark Start With 8 Attributes", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()
@@ -75,7 +76,7 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) {
}
func BenchmarkSpanWithAttributes_all(b *testing.B) {
traceBenchmark(b, "Benchmark Start With all Attribute types", func(b *testing.B, t otel.Tracer) {
traceBenchmark(b, "Benchmark Start With all Attribute types", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()
@@ -99,7 +100,7 @@ func BenchmarkSpanWithAttributes_all(b *testing.B) {
}
func BenchmarkSpanWithAttributes_all_2x(b *testing.B) {
traceBenchmark(b, "Benchmark Start With all Attributes types twice", func(b *testing.B, t otel.Tracer) {
traceBenchmark(b, "Benchmark Start With all Attributes types twice", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()
@@ -133,8 +134,8 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) {
}
func BenchmarkTraceID_DotString(b *testing.B) {
t, _ := otel.TraceIDFromHex("0000000000000001000000000000002a")
sc := otel.SpanContext{TraceID: t}
t, _ := trace.TraceIDFromHex("0000000000000001000000000000002a")
sc := trace.SpanContext{TraceID: t}
want := "0000000000000001000000000000002a"
for i := 0; i < b.N; i++ {
@@ -145,7 +146,7 @@ func BenchmarkTraceID_DotString(b *testing.B) {
}
func BenchmarkSpanID_DotString(b *testing.B) {
sc := otel.SpanContext{SpanID: otel.SpanID{1}}
sc := trace.SpanContext{SpanID: trace.SpanID{1}}
want := "0100000000000000"
for i := 0; i < b.N; i++ {
if got := sc.SpanID.String(); got != want {
@@ -154,7 +155,7 @@ func BenchmarkSpanID_DotString(b *testing.B) {
}
}
func traceBenchmark(b *testing.B, name string, fn func(*testing.B, otel.Tracer)) {
func traceBenchmark(b *testing.B, name string, fn func(*testing.B, trace.Tracer)) {
b.Run("AlwaysSample", func(b *testing.B) {
b.ReportAllocs()
fn(b, tracer(b, name, sdktrace.AlwaysSample()))
@@ -165,7 +166,7 @@ func traceBenchmark(b *testing.B, name string, fn func(*testing.B, otel.Tracer))
})
}
func tracer(b *testing.B, name string, sampler sdktrace.Sampler) otel.Tracer {
func tracer(b *testing.B, name string, sampler sdktrace.Sampler) trace.Tracer {
tp := sdktrace.NewTracerProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sampler}))
return tp.Tracer(name)
}