-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(trace): add concurrent-safe Reset
method to SpanRecorder
#5994
feat(trace): add concurrent-safe Reset
method to SpanRecorder
#5994
Conversation
Can you provide a use-case for this? All of our uses have not needed this functionality. |
I have already added it to the description. |
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.
In the same package, InMemoryExporter
has a Reset method.
So applying the same to SpanRecorder
sounds sensible.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5994 +/- ##
=====================================
Coverage 82.1% 82.1%
=====================================
Files 273 273
Lines 23616 23624 +8
=====================================
+ Hits 19399 19406 +7
- Misses 3872 3873 +1
Partials 345 345 |
We have also a |
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.
Can you add a changelog entry?
Co-authored-by: Robert Pająk <[email protected]>
… concurrency safety
I'm not in favor of adding additional surface area to the API based on possibilities. I would like there to be valid use cases instead of arguments about symmetry and hypothetical that motivate us. |
I'll mention the background for adding this feature: When I was writing the unit tests for otelgin, initially I wanted to implement logic similar to the following: package main
import (
"testing"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
)
func TestOtel(t *testing.T) {
imsb := tracetest.NewInMemoryExporter()
otel.SetTracerProvider(trace.NewTracerProvider(
trace.WithSyncer(imsb),
))
t.Run("test1", func(t *testing.T) {
defer imsb.Reset()
// do something...
// check imsb...
})
t.Run("test2", func(t *testing.T) {
defer imsb.Reset()
// do something...
// check imsb...
})
} Because, I hope that However, I found that a large amount of test logic uses Therefore, this PR came into being. I think the |
Thanks for the use-case. I would recommend not using the global in testing, but that is a review for another PR. 😉 |
We probably need a Reset method to reuse it for testing. Just like
InMemoryExporter
.opentelemetry-go/sdk/trace/tracetest/exporter.go
Lines 61 to 65 in b99d2b8
ex:
output: