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

Tracer#joinOrRoot - propagate extracted headers downstream #301

Merged
merged 1 commit into from
Sep 9, 2023

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Aug 31, 2023

Closes #277.

While reviewing the #291, I spotted the reason behind #277.

@iRevive iRevive requested a review from NthPortal August 31, 2023 07:33
Comment on lines 72 to +76
SpanContext.fromContext(context) match {
case Some(parent) =>
childScope(parent)(fa)
Local[F, Vault].scope(childScope(parent)(fa))(context)
case None =>
rootScope(fa)
Local[F, Vault].scope(fa)(context)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the actual fix

Copy link
Contributor

Choose a reason for hiding this comment

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

Dam, this is what I was missing! Had done the same changes as you've done to the context conversions but still couldn't get it working. This is what I was missing. Nice one!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the whole propagation thing is getting complicated.
Perhaps once we separate context carrier (a.k.a. Vault) and context itself in #291 things should get better

Copy link
Contributor

Choose a reason for hiding this comment

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

why doesn't TraceScope handle these? I'm not quite understanding

Copy link
Contributor Author

@iRevive iRevive Aug 31, 2023

Choose a reason for hiding this comment

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

TraceScope propagation knows nothing about the external JContext, which is stored in the Vault, until we pass it.

So, once we pass the vault with external JContext (that has extract headers), things start to work.

Anytime I'm trying to reproduce the whole propagation process in my brain my brain is getting slightly damaged 😄

@iRevive
Copy link
Contributor Author

iRevive commented Aug 31, 2023

@lacarvalho91 would you like to take a look?

Copy link
Contributor

@lacarvalho91 lacarvalho91 left a comment

Choose a reason for hiding this comment

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

Awesome

Copy link
Contributor

@NthPortal NthPortal left a comment

Choose a reason for hiding this comment

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

it looks to be largely correct to me and a strict improvement over what we have currently.

however, I don't think it's a long-term solution, for a couple of reasons. my instincts feel that converting between JContext and Vault feels fundamentally brittle, though perhaps I could be convinced otherwise. but more importantly, Vault is not a spec-compliant context, as its keys do not have names for debugging purposes

Comment on lines 46 to 48
} else {
context = Scope.Noop.storeInContext(context)
Scope.Noop.storeInContext(Vault.empty)
}
Copy link
Contributor

@NthPortal NthPortal Aug 31, 2023

Choose a reason for hiding this comment

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

nittest of picks: don't need { }

Comment on lines +24 to 25
import cats.syntax.apply._
import cats.syntax.functor._
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import cats.syntax.apply._
import cats.syntax.functor._
import cats.syntax.all._

@iRevive
Copy link
Contributor Author

iRevive commented Aug 31, 2023

however, I don't think it's a long-term solution

Definitely! It's a band-aid to move forward. Then, in #291 we can reconsider the implementation details.

As I mentioned in #291, in my opinion, we wrongfully treat Vault as a context when it's a 'context carrier'. In fact, if the app uses IOLocal[Vault] exclusively for tracing, the Vault will always have exactly one entry, which is Scope. And Scope, in general, wraps JContext or JSpan.

So, when we store a custom entry (e.g. a passthrough header), it's not stored directly in the Vault. The entry is stored in the JContext and the JContext (wrapped into the Scope) is stored in the Vault.

converting between JContext and Vault feels fundamentally brittle,

yeah, basically there is no conversion at all. All we do is store JContext in Vault and that's it. We don't replicate existing values from JContext (e.g. headers) to Vault.

@iRevive iRevive merged commit 2b663b7 into typelevel:main Sep 9, 2023
9 checks passed
@iRevive iRevive deleted the issue-277 branch September 9, 2023 11:37
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.

Context propagation doesn't work when the context isn't a span
3 participants