Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move B3 propagator from main repo to contrib repo #344

Merged
merged 6 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ updates:
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "gomod"
directory: "/propagators"
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "gomod"
directory: "/tools"
schedule:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Benchmark tests for the gRPC instrumentation. (#296)
- Integration testing for the gRPC instrumentation. (#297)
- Allow custom labels to be added to net/http metrics. (#306)
- Added B3 propagator, moving it out of open.telemetry.io/otel repo. (#344)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Collection of 3rd-party instrumentation and exporters for [OpenTelemetry-Go](htt

- [Instrumentation](./instrumentation/): Packages providing OpenTelemetry instrumentation for 3rd-party libraries.
- [Exporters](./exporters/): Packages providing OpenTelemetry exporters for 3rd-party telemetry systems.
- [Propagators](./propagators/): Packages providing Opentelemetry context propagators for 3rd-party propagation formats.
- [Detectors](./detectors/): Packages providing OpenTelemetry resource detectors for 3rd-party cloud computing environments.

## Contributing

Expand Down
103 changes: 103 additions & 0 deletions propagators/b3/b3_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright The 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 b3_test

import (
"context"
"net/http"
"testing"

"go.opentelemetry.io/contrib/propagators/b3"
"go.opentelemetry.io/otel/api/trace"
)

func BenchmarkExtractB3(b *testing.B) {
testGroup := []struct {
name string
tests []extractTest
}{
{
name: "valid headers",
tests: extractHeaders,
},
{
name: "invalid headers",
tests: extractInvalidHeaders,
},
}

for _, tg := range testGroup {
propagator := b3.B3{}
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) {
testGroup := []struct {
name string
tests []injectTest
}{
{
name: "valid headers",
tests: injectHeader,
},
{
name: "invalid headers",
tests: injectInvalidHeader,
},
}

for _, tg := range testGroup {
for _, tt := range tg.tests {
propagator := b3.B3{InjectEncoding: tt.encoding}
traceBenchmark(tg.name+"/"+tt.name, b, func(b *testing.B) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
ctx := trace.ContextWithSpan(
context.Background(),
testSpan{sc: tt.sc},
)
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)
})
}
Loading