Skip to content

Commit

Permalink
fix: lock accesses to encoder in json stdout exporter to prevent crash (
Browse files Browse the repository at this point in the history
#2265)

* lock accesses to encoder

fixes #2264

* move locking outside loop to avoid deadlock

* Update CHANGELOG.md
  • Loading branch information
lizthegrey committed Sep 30, 2021
1 parent 00d8ca5 commit 66fccc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions exporters/stdout/stdouttrace/trace.go
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 66fccc0

Please sign in to comment.