1
0
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:
Liz Fong-Jones 2021-09-30 12:58:26 -07:00 committed by GitHub
parent 00d8ca5890
commit 66fccc0be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -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)

View File

@ -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