natchez integration and lambda init
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 195
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
There's a problem when using tracing in combo with resources that are cached (in init or setup part of execution), which is even included in one of the examples: https://github.com/typelevel/feral/blob/main/examples/src/main/scala/feral/examples/KinesisLambda.scala#L52-L53.
The problem:
- Actual root span cannot be used in init because it will never be closed. This is even worse if you reuse
Trace[IO]instance inside request handler code, because all spans there would become children of this never-ending root span. And some natchez backend implementations (like XRay) only send root span together with all children when root span is finished. So you get no recorded spans as a result. - If you use fake root span to solve the first problem (smth like this: https://github.com/tpolecat/natchez/issues/566#issue-1278510665), then spans produced during init (like DB connection pool initialization with skunk) are separate from spans produced in the first request (handler code) of that lambda instance.
This means that TracedHandler implementation is useless if you need to have Trace[IO] during init. In case of skunk, you would want to see SQL query spans inside request spans and for that you need to reuse same instance of Trace[IO] for all requests.
How it should work:
It should be possible to build a single Trace[IO] instance for the lifetime of lambda instance. Spans produced during initialization would get recorded as children of root span for the first ever request to that lambda instance.
I hope I managed to describe this clearly 😅. Would be great to work this out and get that example fixed so that it would show how to use skunk and tracing with feral.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with TracedHandler and the cached-resource setup in examples/src/main/scala/feral/examples/KinesisLambda.scala around lines 52–53. Read the linked Natchez discussion and inspect how initialization and request-handler spans are associated. Done means a single Trace[IO] can cover initialization and requests, with initialization spans recorded under the first request root, and the Skunk tracing example is corrected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100