Skip to content

Iterating on X-Ray support#452

Closed
bpholt wants to merge 5 commits into
typelevel:series/0.1from
Dwolla:xray
Closed

Iterating on X-Ray support#452
bpholt wants to merge 5 commits into
typelevel:series/0.1from
Dwolla:xray

Conversation

@bpholt

@bpholt bpholt commented Nov 17, 2021

Copy link
Copy Markdown
Member

This addresses some PR comments in #427 that we decided to hold up for a followup PR.

@armanbilge armanbilge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM :)

Comment on lines +225 to +242
def fromKernel[F[_] : Concurrent : Clock : Random : XRayEnvironment](
name: String,
kernel: Kernel,
entry: XRayEntryPoint[F]
): F[XRaySpan[F]] =
kernel.toHeaders
.get(Header)
.flatMap(parseHeader)
.map(x => fromHeader(name, x, entry))
.get
entry: XRayEntryPoint[F],
useEnvironmentFallback: Boolean = true,
): F[Option[XRaySpan[F]]] =
OptionT.fromOption[F](kernel.toHeaders.get(Header))
.subflatMap(parseHeader)
.semiflatMap(fromHeader(name, _, entry))
.orElse {
OptionT.whenF(useEnvironmentFallback) {
XRayEnvironment[F]
.kernelFromEnvironment
.flatMap(XRaySpan.fromKernel(name, _, entry, useEnvironmentFallback = false))
}
.flattenOption
}
.value

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think a better way is to just read the environment variables and construct the kernel before fromKernel is called, so that people can use whatever method they prefer for getting the trace context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, I couldn't quite follow. Do you mean, we should only read from the environment variables once, during setup?

@christiankjaer christiankjaer Nov 18, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not exactly. When you use X-Ray you always know whether you should use some headers or the environment variables. I don't think the concept of a fallback will ever be necessary. The construction of the kernel is application specific and you probably never mix environment variables and HTTP headers for instance.

If I am using AWS lambda I will always be using environment variables. If I am writing a http4s service I will always be using HTTP headers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, I see, thanks for explaining. So basically, expose this as a config option when creating the EntryPoint? Or do you mean, the EntryPoint itself should never grab the kernel from the environment, and it should be up to the user to do this manually?

@christiankjaer christiankjaer Nov 18, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In the entry point you always pass the kernel when you want to create an initial span from an existing trace. How this kernel is constructed is up to you.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Apologies if I missed something, but I think the only hole in the current config is if someone wants to raise an error (or create a root) if the provided kernel is lacking even if the environment can in fact provide a Trace ID as a fallback

They can do this if the set the useEnvironmentFallback param to false, right?

@armanbilge armanbilge Nov 18, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this option is on a package-private method and furthermore not available in the natchez Entrypoint abstraction. So the only place a user can hypothetically adjust this config is when they create the XRay entrypoint.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, right. Ok, so we need to propagate that option outward.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I updated the PR with what I think were the suggested changes. Please let me know what you think!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 yes, exactly what I had in mind, thanks :) @christiankjaer what do you think?

@armanbilge armanbilge mentioned this pull request Dec 13, 2021
6 tasks
@tpolecat

Copy link
Copy Markdown
Member

This looks good, can you rebase or otherwise resolve?

@armanbilge

Copy link
Copy Markdown
Member

I'll do that!

@tpolecat

Copy link
Copy Markdown
Member

superseded by #468

@tpolecat tpolecat closed this Dec 13, 2021
@bpholt
bpholt deleted the xray branch June 22, 2022 16:20
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.

4 participants