-
-
Notifications
You must be signed in to change notification settings - Fork 53
add tracing support with Natchez #44
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d6cfa0f
add tracing support with Natchez
bpholt 2404de8
add Trace[IO] to CloudFormationCustomResource
bpholt 2fe0589
clean up tracing resource in JS IOLambdaPlatform
bpholt c1f8e48
use Natchez http4s middleware to trace ApiGatewayProxyHttp4sLambda
bpholt 4244696
incorporate pending upstream natchez-xray changes
bpholt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
lambda/shared/src/main/scala/feral/lambda/XRayTracing.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright 2021 Typelevel | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* TODO this file won't compile until these PRs are merged & published: | ||
| * https://github.com/christiankjaer/natchez/pull/1 | ||
| * https://github.com/tpolecat/natchez/pull/427 | ||
| */ | ||
|
|
||
| package feral.lambda | ||
|
|
||
| import cats.effect.std.Random | ||
| import cats.effect.{IO, Resource} | ||
| import feral.IOSetup | ||
| import natchez.xray.{XRay, XRayEnvironment} | ||
| import natchez.{EntryPoint, Span} | ||
|
|
||
| trait XRayTracing extends IOSetup { | ||
| private def traceEntryPoint: Resource[IO, EntryPoint[IO]] = | ||
| Resource.eval(Random.scalaUtilRandom[IO]).flatMap { implicit random => | ||
| Resource.eval(XRayEnvironment[IO].daemonAddress).flatMap { | ||
| case Some(addr) => XRay.entryPoint[IO](addr) | ||
| case None => XRay.entryPoint[IO]() | ||
| } | ||
| } | ||
|
|
||
| override protected def traceRootSpan(name: String): Resource[IO, Span[IO]] = | ||
| Resource.eval(XRayEnvironment[IO].kernelFromEnvironment).flatMap { kernel => | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This strategy for extracting the kernel might only apply to normal AWS Lambdas—e.g. for |
||
| traceEntryPoint.flatMap(_.continueOrElseRoot(name, kernel)) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this
Tracepropagate to userland code? Apologies if I'm missing something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, good catch. I've only made changes to
IOLambdaand theIOLambdaPlatforms to make sure it worked at that level. We'd need to add the implicitTraceto the other abstract methods if we want to do this consistently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I thought it might be using some
IOLocalmagic :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to think a little more on how the
ApiGatewayProxyHttp4sLambdafits in here. (Open to suggestions if you see a way to do it with the current structure.)We may need to change
routesto bedef routes: Resource[IO, HttpRoutes[Kleisli[IO, Span[IO], *]]]? But even that doesn't fit perfectly if all we have here is the implicitTrace[IO]. Not sure yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's this https://github.com/tpolecat/natchez-http4s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of punted and added the Natchez server middleware to
ApiGatewayProxyHttp4sLambda. The main problem I see is that doesn't make theTrace[IO]capability available to anything defined indef routes: Resource[IO, HttpRoutes[IO]], meaning I'm not sure how application code could open its own spans or propagate the trace onwards if it makes calls to other services.@armanbilge it looked like you started a new branch that (from the commit messages) might be reworking the structure a little bit to help with this. I'm going to pause here to see what you come up with. 🙂