mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-24 03:47:19 +02:00
fix: lock accesses to encoder in json stdout exporter to prevent crash (#2265)
* lock accesses to encoder fixes #2264 * move locking outside loop to avoid deadlock * Update CHANGELOG.md
This commit is contained in:
parent
00d8ca5890
commit
66fccc0be0
@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- json stdout exporter no longer crashes due to concurrency bug. (#2265)
|
||||
|
||||
### Changed
|
||||
|
||||
- NoopMeterProvider is now private and NewNoopMeterProvider must be used to obtain a noopMeterProvider. (#2237)
|
||||
|
@ -49,6 +49,7 @@ func New(options ...Option) (*Exporter, error) {
|
||||
// Exporter is an implementation of trace.SpanSyncer that writes spans to stdout.
|
||||
type Exporter struct {
|
||||
encoder *json.Encoder
|
||||
encoderMu sync.Mutex
|
||||
timestamps bool
|
||||
|
||||
stoppedMu sync.RWMutex
|
||||
@ -70,6 +71,8 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
|
||||
|
||||
stubs := tracetest.SpanStubsFromReadOnlySpans(spans)
|
||||
|
||||
e.encoderMu.Lock()
|
||||
defer e.encoderMu.Unlock()
|
||||
for i := range stubs {
|
||||
stub := &stubs[i]
|
||||
// Remove timestamps
|
||||
|
Loading…
x
Reference in New Issue
Block a user