-
Notifications
You must be signed in to change notification settings - Fork 576
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
Add aws componenets benchmark #812
Add aws componenets benchmark #812
Conversation
@Aneurysm9 @MrAlias Can you review this PR? |
Codecov Report
@@ Coverage Diff @@
## main #812 +/- ##
=====================================
Coverage 78.7% 78.8%
=====================================
Files 62 62
Lines 2707 2707
=====================================
+ Hits 2133 2135 +2
+ Misses 441 440 -1
+ Partials 133 132 -1
|
@Aneurysm9 not sure but getting code cov failure in tests due to some missing token issue. |
GitHub Actions was having a struggle the other day. I've kicked off the CI process again, we'll see if it's feeling better today! |
otel.SetTracerProvider(curTp) | ||
otel.SetTextMapPropagator(curProp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are no-ops. The global set operation is only ever performed once.
It would make more sense to define tracer
with TracerProvider
in an init
function and skip any dealing with the TextMapPropagtor
(it doesn't look used in any of these benchmarks).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting to add trace.Start
in init
function ? As per @Aneurysm9's suggestion I have added restoring logic of propagators so had to add those in every benchmark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suggesting you create a TracerProvider
in an init
function that you then use to set the value of a package level tracer
variable with.
The restoring logic you added does nothing, the second call is a no-op. You should not use the global tracer here.
span.SetAttributes(attribute.Key("example attribute 2").String("value 2")) | ||
} | ||
|
||
func startAndEndUnSampledSpan() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The created span in this function will come from a TracerProvider
that has an AlwaysSample
Sampler
. This span will be sampled and this function is no different, as far as I can see, from startAndEndSampledSpan
. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good callout. I will probably add tracer with NeverSample
config.
I see my review has been re-requested, but the issues I raised on my first review have not been addressed AFAIK. Can you link me to the fixes if I missed them? |
Yeah re-request review was done by mistake I still have to address your comments. |
@MrAlias Submitted new changes to address your query please take a look. |
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
var tracer = otel.Tracer("sample-app") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var tracer = otel.Tracer("sample-app") | |
var tracer trace.Tracer |
idg := NewIDGenerator() | ||
|
||
tp := sdktrace.NewTracerProvider( | ||
sdktrace.WithSampler(sdktrace.AlwaysSample()), | ||
sdktrace.WithIDGenerator(idg), | ||
) | ||
|
||
otel.SetTracerProvider(tp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idg := NewIDGenerator() | |
tp := sdktrace.NewTracerProvider( | |
sdktrace.WithSampler(sdktrace.AlwaysSample()), | |
sdktrace.WithIDGenerator(idg), | |
) | |
otel.SetTracerProvider(tp) | |
tracer = sdktrace.NewTracerProvider( | |
sdktrace.WithSampler(sdktrace.AlwaysSample()), | |
sdktrace.WithIDGenerator(NewIDGenerator()), | |
).Tracer("sample-app") |
func startAndEndSampledSpan() { | ||
var span trace.Span | ||
_, span = tracer.Start( | ||
context.Background(), | ||
"Example Trace", | ||
) | ||
|
||
defer span.End() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func startAndEndSampledSpan() { | |
var span trace.Span | |
_, span = tracer.Start( | |
context.Background(), | |
"Example Trace", | |
) | |
defer span.End() | |
} |
for i := 0; i < b.N; i++ { | ||
startAndEndSampledSpan() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i := 0; i < b.N; i++ { | |
startAndEndSampledSpan() | |
} | |
for i := 0; i < b.N; i++ { | |
_, span := tracer.Start(context.Background(), "Example Trace") | |
span.End() | |
} |
func startAndEndNestedSampledSpan() { | ||
var span trace.Span | ||
ctx, span := tracer.Start(context.Background(), "Parent operation...") | ||
defer span.End() | ||
|
||
_, span = tracer.Start(ctx, "Sub operation...") | ||
defer span.End() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func startAndEndNestedSampledSpan() { | |
var span trace.Span | |
ctx, span := tracer.Start(context.Background(), "Parent operation...") | |
defer span.End() | |
_, span = tracer.Start(ctx, "Sub operation...") | |
defer span.End() | |
} |
for i := 0; i < b.N; i++ { | ||
startAndEndNestedSampledSpan() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i := 0; i < b.N; i++ { | |
startAndEndNestedSampledSpan() | |
} | |
ctx, parent := tracer.Start(context.Background(), "Parent operation...") | |
defer parent.End() | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
_, span := tracer.Start(ctx, "Sub operation...") | |
span.End() | |
} |
func getCurrentSampledSpan() trace.Span { | ||
var span trace.Span | ||
ctx, span := tracer.Start( | ||
context.Background(), | ||
"Example Trace", | ||
) | ||
defer span.End() | ||
|
||
return trace.SpanFromContext(ctx) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func getCurrentSampledSpan() trace.Span { | |
var span trace.Span | |
ctx, span := tracer.Start( | |
context.Background(), | |
"Example Trace", | |
) | |
defer span.End() | |
return trace.SpanFromContext(ctx) | |
} |
func BenchmarkGetCurrentSampledSpan(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
getCurrentSampledSpan() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provides no additional bencmarking of this package. The creation and ending of a span is already benchmarked and this only adds a benchmark on retrieving a span from a context, something that is not a function of this package.
func BenchmarkGetCurrentSampledSpan(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
getCurrentSampledSpan() | |
} | |
} |
func BenchmarkAddAttributesToSampledSpan(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
addAttributesToSampledSpan() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar here, this tests the AddAttributes
method of the default SDK and does not provide any relevant benchmark for this package.
func BenchmarkAddAttributesToSampledSpan(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
addAttributesToSampledSpan() | |
} | |
} |
func addAttributesToSampledSpan() { | ||
var span trace.Span | ||
_, span = tracer.Start( | ||
context.Background(), | ||
"Example Trace", | ||
) | ||
defer span.End() | ||
|
||
span.SetAttributes(attribute.Key("example attribute 1").String("value 1")) | ||
span.SetAttributes(attribute.Key("example attribute 2").String("value 2")) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func addAttributesToSampledSpan() { | |
var span trace.Span | |
_, span = tracer.Start( | |
context.Background(), | |
"Example Trace", | |
) | |
defer span.End() | |
span.SetAttributes(attribute.Key("example attribute 1").String("value 1")) | |
span.SetAttributes(attribute.Key("example attribute 2").String("value 2")) | |
} |
@@ -0,0 +1,104 @@ | |||
// Copyright The OpenTelemetry Authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be renamed to something descriptive of the benchmarks included. I.e. idgenerator_benchmark_test.go
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Added benchmarks for aws idgenerator, propagator and for sampling and non-sampling scenarios