-
Notifications
You must be signed in to change notification settings - Fork 41
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
Tracing doodles #50
Closed
Closed
Tracing doodles #50
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8ffa2da
Define Feral
armanbilge 1e2163b
Redefine IOLambda in terms of Feral
armanbilge f36fdc0
Or maybe, just use Resource?
armanbilge ac17850
Rework http4s lambda
armanbilge 8fda33f
Rework cloudformation lambda
armanbilge 1dc61d8
make Context generic in its effect type
bpholt 7860c4d
Create lambda-natchez module
armanbilge 6271e7a
Add arn/requestId tags to trace
armanbilge 29e2c73
Span-based TracedLambda
armanbilge 00eb18f
the CloudFormationCustomResource lambda should output nothing
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 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
35 changes: 35 additions & 0 deletions
35
lambda-natchez/src/main/scala/feral/lambda/natchez/HasKernel.scala
This file contains 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,35 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package feral.lambda.natchez | ||
|
||
import feral.lambda.events.ApiGatewayProxyEventV2 | ||
import natchez.Kernel | ||
|
||
trait HasKernel[Event] { | ||
def extract(event: Event): Kernel | ||
} | ||
|
||
object HasKernel extends HasKernelLowPriority { | ||
@inline def apply[E](implicit hk: HasKernel[E]): hk.type = hk | ||
|
||
implicit val apiGateProxyEventV2Kernel: HasKernel[ApiGatewayProxyEventV2] = | ||
e => Kernel(e.headers) | ||
} | ||
|
||
private[natchez] sealed class HasKernelLowPriority { | ||
implicit def emptyKernel[E]: HasKernel[E] = _ => Kernel(Map.empty) | ||
} |
27 changes: 27 additions & 0 deletions
27
lambda-natchez/src/main/scala/feral/lambda/natchez/LiftTrace.scala
This file contains 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,27 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package feral.lambda.natchez | ||
|
||
import cats.~> | ||
import natchez.Span | ||
import natchez.Trace | ||
|
||
// https://github.com/tpolecat/natchez/pull/448 | ||
trait LiftTrace[F[_], G[_]] { | ||
def run[A](span: Span[F])(f: Trace[G] => G[A]): F[A] | ||
def liftK: F ~> G | ||
} |
33 changes: 33 additions & 0 deletions
33
lambda-natchez/src/main/scala/feral/lambda/natchez/TracedLambda.scala
This file contains 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,33 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package feral.lambda.natchez | ||
|
||
import cats.effect.kernel.MonadCancelThrow | ||
import feral.lambda.Lambda | ||
import natchez.EntryPoint | ||
import natchez.Trace | ||
|
||
object TracedLambda { | ||
def apply[F[_]: MonadCancelThrow, G[_], Event: HasKernel, Result](entryPoint: EntryPoint[F])( | ||
lambda: Trace[G] => Lambda[G, Event, Result])( | ||
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. I'm not sure yet how I feel about injecting |
||
implicit lift: LiftTrace[F, G]): Lambda[F, Event, Result] = { (event, context) => | ||
val kernel = HasKernel[Event].extract(event) | ||
entryPoint.continueOrElseRoot(context.functionName, kernel).use { span => | ||
lift.run(span)(lambda(_)(event, context.mapK(lift.liftK))) | ||
} | ||
} | ||
} |
This file contains 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
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.
One of the nice things about having all the events together in the same module is it makes it easy to provide these implicits. Although I'm doubtful if any will have a special implementation except this one.