mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-16 10:19:23 +02:00
942713a02d
This PR removes the non-compliant ChildOf and FollowsFrom interfaces and the Relation type, which were inherited from OpenTracing via the initial prototype. Instead allow adding a span context to the go context as a remote span context and use a simple algorithm for figuring out an actual parent of the new span, which was proposed for the OpenTelemetry specification. Also add a way to ignore current span and remote span context in go context, so we can force the tracer to create a new root span - a span with a new trace ID. That required some moderate changes in the opentracing bridge - first reference with ChildOfRef reference type becomes a local parent, the rest become links. This also fixes links handling in the meantime. The downside of the approach proposed here is that we can only set the remote parent when creating a span through the opentracing API. Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
128 lines
3.0 KiB
Go
128 lines
3.0 KiB
Go
// Copyright 2019, OpenTelemetry Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package testtrace_test
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"go.opentelemetry.io/otel/api/trace"
|
|
mocktrace "go.opentelemetry.io/otel/internal/trace"
|
|
)
|
|
|
|
func BenchmarkExtractB3(b *testing.B) {
|
|
testGroup := []struct {
|
|
singleHeader bool
|
|
name string
|
|
tests []extractTest
|
|
}{
|
|
{
|
|
singleHeader: false,
|
|
name: "multiple headers",
|
|
tests: extractMultipleHeaders,
|
|
},
|
|
{
|
|
singleHeader: true,
|
|
name: "single headers",
|
|
tests: extractSingleHeader,
|
|
},
|
|
{
|
|
singleHeader: false,
|
|
name: "invalid multiple headers",
|
|
tests: extractInvalidB3MultipleHeaders,
|
|
},
|
|
{
|
|
singleHeader: true,
|
|
name: "invalid single headers",
|
|
tests: extractInvalidB3SingleHeader,
|
|
},
|
|
}
|
|
|
|
for _, tg := range testGroup {
|
|
propagator := trace.B3{SingleHeader: tg.singleHeader}
|
|
for _, tt := range tg.tests {
|
|
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
|
ctx := context.Background()
|
|
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
|
for h, v := range tt.headers {
|
|
req.Header.Set(h, v)
|
|
}
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, _ = propagator.Extract(ctx, req.Header)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkInjectB3(b *testing.B) {
|
|
var id uint64
|
|
testGroup := []struct {
|
|
singleHeader bool
|
|
name string
|
|
tests []injectTest
|
|
}{
|
|
{
|
|
singleHeader: false,
|
|
name: "multiple headers",
|
|
tests: injectB3MultipleHeader,
|
|
},
|
|
{
|
|
singleHeader: true,
|
|
name: "single headers",
|
|
tests: injectB3SingleleHeader,
|
|
},
|
|
}
|
|
|
|
mockTracer := &mocktrace.MockTracer{
|
|
Sampled: false,
|
|
StartSpanID: &id,
|
|
}
|
|
|
|
for _, tg := range testGroup {
|
|
id = 0
|
|
propagator := trace.B3{SingleHeader: tg.singleHeader}
|
|
for _, tt := range tg.tests {
|
|
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
|
|
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
|
ctx := context.Background()
|
|
if tt.parentSc.IsValid() {
|
|
ctx = trace.ContextWithRemoteSpanContext(ctx, tt.parentSc)
|
|
}
|
|
ctx, _ = mockTracer.Start(ctx, "inject")
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
propagator.Inject(ctx, req.Header)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func traceBenchmark(name string, b *testing.B, fn func(*testing.B)) {
|
|
b.Run(name, func(b *testing.B) {
|
|
b.ReportAllocs()
|
|
fn(b)
|
|
})
|
|
b.Run(name, func(b *testing.B) {
|
|
b.ReportAllocs()
|
|
fn(b)
|
|
})
|
|
}
|