forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 4
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 <[email protected]>
- Loading branch information
Showing
2 changed files
with
42 additions
and
6 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,26 @@ | ||
package detect | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||
) | ||
|
||
// threadSafeExporterWrapper wraps an OpenTelemetry SpanExporter and makes it thread-safe. | ||
type threadSafeExporterWrapper struct { | ||
mu sync.Mutex | ||
exporter sdktrace.SpanExporter | ||
} | ||
|
||
func (tse *threadSafeExporterWrapper) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error { | ||
tse.mu.Lock() | ||
defer tse.mu.Unlock() | ||
return tse.exporter.ExportSpans(ctx, spans) | ||
} | ||
|
||
func (tse *threadSafeExporterWrapper) Shutdown(ctx context.Context) error { | ||
tse.mu.Lock() | ||
defer tse.mu.Unlock() | ||
return tse.exporter.Shutdown(ctx) | ||
} |