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

Improve Tracing #177

Merged
merged 3 commits into from
Jul 1, 2024
Merged

Improve Tracing #177

merged 3 commits into from
Jul 1, 2024

Conversation

bpholt
Copy link
Member

@bpholt bpholt commented Jun 28, 2024

The currently implementation attaches the background long polling requests to the trace of the first invocation of authoritiesForService for a given service. This keeps that trace alive much longer than it should.

This PR fixes that by requiring an EntryPoint[F] and Local[F, Span[F]] on construction of the ConsulServiceDiscoveryAlg[F], so that when a new background process is started, it can work in its own trace. The downside of this approach is that it requires breaking binary compatibility, but I think that's an acceptable tradeoff.

@bpholt bpholt self-assigned this Jun 28, 2024
@bpholt bpholt requested a review from a team as a code owner June 28, 2024 22:24
@mergify mergify bot added the core label Jun 28, 2024
Stream.unfoldEval(initialConsulIndex) { maybeIndex =>
// since this is a background task, it doesn't make sense to attach it to the trace that initially started it
import natchez.Trace.Implicits.noop
Copy link
Member Author

Choose a reason for hiding this comment

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

The noop Trace[F] previously passed to lookup prevented the span creation immediately within lookup (e.g. the span named com.dwolla.consul.ConsulServiceDiscoveryAlg.lookup) but the issue is observable when using a Client[F] that has been wrapped in the Natchez middleware from natchez-http4s. Assuming it's using a Local[F, Span[F]]-based MTL Trace[F], the span referenced by the Natchez middleware is not the noop span, but the current value of the Local instance, meaning the middleware creates a new span and sends that trace's kernel as part of the request being made.

.map(Span.Options.Defaults.withLink)
.flatMap {
entryPoint
.root("com.dwolla.consul.ConsulServiceDiscoveryAlg.continuallyUpdating", _)
Copy link
Member Author

Choose a reason for hiding this comment

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

We technically don't need to create a new root span here; we could use the Local[F, Span[F]] to set the no-op span for the fa scope. But we have to break bincompat to demand the Local[F, Span[F]], so we might as well also ask for the EntryPoint[F] and create a new root span.

Copy link
Member Author

Choose a reason for hiding this comment

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

And AFAICT we really do need Local[F, Span[F]]. One alternative I tried, using Trace[F].span("continuallyUpdating", Span.Options.Suppress), did successfully suppress the span creation from the Natchez http4s middleware, but the duration of the continuallyUpdating was still tied to the execution of the background requests, so doesn't accomplish the main goal.

@bpholt bpholt added the bug Something isn't working label Jun 28, 2024
@bpholt bpholt merged commit be1db26 into main Jul 1, 2024
19 checks passed
@bpholt bpholt deleted the tracing branch July 1, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants