Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace: fix span leak in batchSpanProcessor #5518

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

korniltsev
Copy link

@korniltsev korniltsev commented Jun 18, 2024

Description

When a span ReadOnlySpan is processed and then exported by batchSpanProcessor it may be not garbage collected. A strong pointer to a ReadOnlySpan may be kept in batchSpanProcessor.batch slice.

Environment

  • OS: Darwin
  • Architecture: arm64
  • Go Version: go version devel go1.23-eaa7d9ff86 Mon Jun 3 14:56:37 2024 +0000 darwin/arm64
  • opentelemetry-go version: f80064a

Steps To Reproduce

	bsp := sdktrace.NewBatchSpanProcessor(tracetest.NewInMemoryExporter())
	tp := sdktrace.NewTracerProvider(
		sdktrace.WithSpanProcessor(bsp),
	)

	_, span := tp.Tracer("tracer").Start(ctx, "leaked_span")
	span.End()

	tp.ForceFlush(ctx)

Expected behavior

There are no references to the leaked_span in the batchSpanProcessor

Actual behavior

There is a references to the leaked_span in the batchSpanProcessor.batch

PR description

In this PR batchSpanProcessor clears references to spans after export.

Copy link

linux-foundation-easycla bot commented Jun 18, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: korniltsev / name: Tolya Korniltsev (e22d776)

@dashpole
Copy link
Contributor

Would you mind either updating the description or opening an issue with the problem you encountered? In which scenarios are we leaking spans, and how did you encounter the issue?

Copy link

codecov bot commented Jun 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.8%. Comparing base (478f85b) to head (e22d776).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #5518   +/-   ##
=====================================
  Coverage   84.8%   84.8%           
=====================================
  Files        269     269           
  Lines      18079   18080    +1     
=====================================
+ Hits       15333   15336    +3     
+ Misses      2420    2418    -2     
  Partials     326     326           
Files Coverage Δ
sdk/trace/batch_span_processor.go 79.0% <100.0%> (+0.1%) ⬆️

... and 2 files with indirect coverage changes

@korniltsev
Copy link
Author

@dashpole Updated description of the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants