File tree Expand file tree Collapse file tree 3 files changed +25
-31
lines changed
Expand file tree Collapse file tree 3 files changed +25
-31
lines changed Original file line number Diff line number Diff line change @@ -18,28 +18,13 @@ package feral.lambda
1818
1919import cats .effect .{Trace => _ , _ }
2020import cats .mtl .Local
21- import cats .syntax .all ._
2221import natchez ._
23- import natchez .mtl ._
2422
2523trait TracedHandlerPlatform {
2624 def apply [F [_]: MonadCancelThrow , Event , Result ](entryPoint : EntryPoint [F ])(
2725 handler : Trace [F ] => F [Option [Result ]])(
2826 implicit inv : Invocation [F , Event ],
2927 KS : KernelSource [Event ],
3028 L : Local [F , Span [F ]]): F [Option [Result ]] =
31- for {
32- event <- inv.event
33- context <- inv.context
34- kernel = KS .extract(event)
35- result <- entryPoint.continueOrElseRoot(context.functionName, kernel).use {
36- Local [F , Span [F ]].scope {
37- Trace [F ].put(
38- AwsTags .arn(context.invokedFunctionArn),
39- AwsTags .requestId(context.awsRequestId)
40- ) >> handler(Trace [F ])
41- }
42- }
43- } yield result
44-
29+ TracedHandlerImpl [F , Event , Result ](entryPoint)(handler)
4530}
Original file line number Diff line number Diff line change @@ -18,26 +18,12 @@ package feral.lambda
1818
1919import cats .effect .{Trace as _ , * }
2020import cats .mtl .Local
21- import cats .syntax .all .*
2221import natchez .*
23- import natchez .mtl .*
2422
2523trait TracedHandlerPlatform :
2624 def apply [F [_]: MonadCancelThrow , Event , Result ](entryPoint : EntryPoint [F ])(
2725 handler : Trace [F ] ?=> F [Option [Result ]])(
2826 using Invocation [F , Event ],
2927 KernelSource [Event ],
3028 Local [F , Span [F ]]): F [Option [Result ]] =
31- for
32- event <- Invocation [F , Event ].event
33- context <- Invocation [F , Event ].context
34- kernel = KernelSource [Event ].extract(event)
35- result <- entryPoint
36- .continueOrElseRoot(context.functionName, kernel)
37- .use:
38- Local [F , Span [F ]].scope:
39- Trace [F ].put(
40- AwsTags .arn(context.invokedFunctionArn),
41- AwsTags .requestId(context.awsRequestId)
42- ) >> handler
43- yield result
29+ TracedHandlerImpl [F , Event , Result ](entryPoint) { implicit t => handler }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import cats.mtl.Local
2323import cats .syntax .all ._
2424import fs2 .compat .NotGiven
2525import natchez ._
26+ import natchez .mtl ._
2627
2728object TracedHandler extends TracedHandlerPlatform {
2829
@@ -81,3 +82,25 @@ object TracedHandler extends TracedHandlerPlatform {
8182 }
8283
8384}
85+
86+ private [lambda] object TracedHandlerImpl {
87+ def apply [F [_]: MonadCancelThrow , Event , Result ](entryPoint : EntryPoint [F ])(
88+ handler : Trace [F ] => F [Option [Result ]])(
89+ implicit inv : Invocation [F , Event ],
90+ KS : KernelSource [Event ],
91+ L : Local [F , Span [F ]]): F [Option [Result ]] =
92+ for {
93+ event <- Invocation [F , Event ].event
94+ context <- Invocation [F , Event ].context
95+ kernel = KernelSource [Event ].extract(event)
96+ result <- entryPoint.continueOrElseRoot(context.functionName, kernel).use {
97+ Local [F , Span [F ]].scope {
98+ Trace [F ].put(
99+ AwsTags .arn(context.invokedFunctionArn),
100+ AwsTags .requestId(context.awsRequestId)
101+ ) >> handler(Trace [F ])
102+ }
103+ }
104+ } yield result
105+
106+ }
You can’t perform that action at this time.
0 commit comments