Skip to content

Clean orphaned traces #2330

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

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

Conversation

laurit
Copy link
Collaborator

@laurit laurit commented Jun 6, 2025

An alternative for #2320

@laurit laurit requested review from a team as code owners June 6, 2025 11:28
Comment on lines +55 to +61
void register(Span span) {
traces.add(new WeakKey(span, referenceQueue));
}

void unregister(SpanContext spanContext) {
traces.remove(new LookupKey(spanContext));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I grok the reasons why, but the asymmetry between register(span) and unregister(context) gives me pause. 🤷🏻


SnapshotProfilingSpanProcessor(TraceRegistry registry, Supplier<StackTraceSampler> sampler) {
this.registry = registry;
this.sampler = sampler;
this.orphanedTraceCleaner = new OrphanedTraceCleaner(registry, sampler);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inject it or make a factory method, because this violates DI principles.

@@ -24,15 +24,27 @@
class TraceRegistry {
private final Set<String> traceIds = Collections.newSetFromMap(new ConcurrentHashMap<>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make the Set also concurrent/threadsafe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it does

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main implementation here (the OrphanedTraceCleaner) seems very similar to the implementation in #2320, with the main difference being that the Registry is responsible for it in #2320 but here we have a separate cleaner that the SnapshotProfilingSpanProcessor delegates to.

To me, this looks like a simpler approach overall, with less code and a slightly clearer separation of responsibilities. I'm not an expert here, so I'm also curious about what @tduncan thinks. Thanks!

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.

2 participants