-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solve panic due to concurrent access to ExportSpans
Signed-off-by: Gahl Saraf <saraf.gahl@gmail.com>
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package detect | ||
|
||
import ( | ||
"context" | ||
sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||
"sync" | ||
) | ||
|
||
// The SpanExporter is expected to be called from a synchronous context, and if called from different routines can panic. | ||
type threadSafeExporter struct { | ||
mut sync.Mutex | ||
exporter sdktrace.SpanExporter | ||
} | ||
|
||
func (tse *threadSafeExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error { | ||
tse.mut.Lock() | ||
defer tse.mut.Unlock() | ||
return tse.exporter.ExportSpans(ctx, spans) | ||
} | ||
|
||
func (tse *threadSafeExporter) Shutdown(ctx context.Context) error { | ||
tse.mut.Lock() | ||
defer tse.mut.Unlock() | ||
return tse.exporter.Shutdown(ctx) | ||
} |