Skip to content

Conversation

@bpholt
Copy link
Member

@bpholt bpholt commented Oct 14, 2025

I have a Lambda with an initialization Resource that (simplified) looks like this:

for
  xray <- XRay.entryPoint[IO]()
  given Local[IO, Span[IO]] <- IO.local(Span.noop[IO]).toResource
  client <- EmberClientBuilder.default[F].build.map(NatchezMiddleware.client(_))
  region <- Env[IO].get("AWS_REGION").liftEitherT(new RuntimeException("missing AWS_REGION environment variable")).map(AwsRegion(_)).rethrowT.toResource
  awsEnv <- AwsEnvironment.default(client, region)
  kms <- AwsClient(KMS, awsEnv) // smithy4s AWS KMS client
yield implicit inv =>
  given KernelSource[CloudFormationCustomResourceRequest[Foo]] = KernelSource.emptyKernelSource

  TracedHandler(xray):
    CloudFormationCustomResource(client, new FooHandler(client, kms))

When I went to use TracedHandler.apply, I noticed that it was constructing its own IOLocal to hold the trace state. I don't think that will be in sync with the given Local[IO, Span[IO]] <- IO.local(Span.noop[IO]) built in the resource, and I want them to be in sync because I want the Client[F] to have the same trace state as the rest of the handler, so I think we need a new way to build a TracedHandler that can inherit the ambient Local[F, Span[F]].

I started off by adding this as a separate TracedHandler.local method, but I didn't think that was a particularly good name, so I ended up basically replacing TracedHandler.apply (in a binary-compatible way).

@bpholt bpholt requested a review from armanbilge October 14, 2025 21:14
@bpholt bpholt self-assigned this Oct 14, 2025
@bpholt bpholt force-pushed the traced-handler branch 3 times, most recently from 8b1f7e1 to db98aad Compare October 14, 2025 21:42
@bpholt
Copy link
Member Author

bpholt commented Oct 14, 2025

This is failing because we're on an old Scala.js version. Hopefully we can merge #592, and then I'll rebase this to take advantage of the update. Until then, this can be reviewed for the concepts, but CI won't pass.

Rebased and now it successfully builds!

…Impl

this allows for Scala version-specific interfaces but without
duplicating the implementation logic

trait TracedHandlerPlatform:
def apply[F[_]: MonadCancelThrow, Event, Result](entryPoint: EntryPoint[F])(
handler: Trace[F] ?=> F[Option[Result]])(
Copy link
Member Author

Choose a reason for hiding this comment

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

Splitting the apply method into Scala version-specific files lets us use a context function here, which improves the experience on Scala 3.

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.

1 participant