-
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 <pellared@hotmail.com>
… 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. 😉 |
### Added - Add `Reset` method to `SpanRecorder` in `go.opentelemetry.io/otel/sdk/trace/tracetest`. (#5994) - Add `EnabledInstrument` interface in `go.opentelemetry.io/otel/sdk/metric/internal/x`. This is an experimental interface that is implemented by synchronous instruments provided by `go.opentelemetry.io/otel/sdk/metric`. Users can use it to avoid performing computationally expensive operations when recording measurements. It does not fall within the scope of the OpenTelemetry Go versioning and stability [policy](./VERSIONING.md) and it may be changed in backwards incompatible ways or removed in feature releases. (#6016) ### Changed - The default global API now supports full auto-instrumentation from the `go.opentelemetry.io/auto` package. See that package for more information. (#5920) - Propagate non-retryable error messages to client in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#5929) - Propagate non-retryable error messages to client in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5929) - Propagate non-retryable error messages to client in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#5929) - Performance improvements for attribute value `AsStringSlice`, `AsFloat64Slice`, `AsInt64Slice`, `AsBoolSlice`. (#6011) - Change `EnabledParameters` to have a `Severity` field instead of a getter and setter in `go.opentelemetry.io/otel/log`. (#6009) ### Fixed - Fix inconsistent request body closing in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#5954) - Fix inconsistent request body closing in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5954) - Fix inconsistent request body closing in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#5954) - Fix invalid exemplar keys in `go.opentelemetry.io/otel/exporters/prometheus`. (#5995) - Fix attribute value truncation in `go.opentelemetry.io/otel/sdk/trace`. (#5997) - Fix attribute value truncation in `go.opentelemetry.io/otel/sdk/log`. (#6032)
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: