Skip to content
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

Extract lambda-natchez module #456

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target lambda-http4s/.js/target lambda/js/target scalafix/rules/target lambda/jvm/target sbt-lambda/target lambda-cloudformation-custom-resource/.jvm/target project/target
run: mkdir -p lambda-natchez/jvm/target lambda-natchez/js/target lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target lambda-http4s/.js/target lambda/js/target scalafix/rules/target lambda/jvm/target sbt-lambda/target lambda-cloudformation-custom-resource/.jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target lambda-http4s/.js/target lambda/js/target scalafix/rules/target lambda/jvm/target sbt-lambda/target lambda-cloudformation-custom-resource/.jvm/target project/target
run: tar cf targets.tar lambda-natchez/jvm/target lambda-natchez/js/target lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target lambda-http4s/.js/target lambda/js/target scalafix/rules/target lambda/jvm/target sbt-lambda/target lambda-cloudformation-custom-resource/.jvm/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down
18 changes: 16 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ lazy val root =
tlCrossRootProject
.aggregate(
lambda,
lambdaNatchez,
lambdaHttp4s,
lambdaCloudFormationCustomResource,
examples,
Expand All @@ -88,7 +89,7 @@ lazy val lambda = crossProject(JSPlatform, JVMPlatform)
name := "feral-lambda",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-effect" % catsEffectVersion,
"org.tpolecat" %%% "natchez-core" % natchezVersion,
"org.typelevel" %%% "case-insensitive" % "1.4.0",
"io.circe" %%% "circe-scodec" % circeVersion,
"io.circe" %%% "circe-jawn" % circeVersion,
"com.comcast" %%% "ip4s-core" % "3.4.0",
Expand Down Expand Up @@ -170,6 +171,19 @@ lazy val lambdaCloudFormationCustomResource = crossProject(JSPlatform, JVMPlatfo
.settings(commonSettings)
.dependsOn(lambda)

lazy val lambdaNatchez = crossProject(JSPlatform, JVMPlatform)
.in(file("lambda-natchez"))
.settings(
name := "feral-lambda-natchez",
libraryDependencies ++= Seq(
"org.tpolecat" %%% "natchez-core" % natchezVersion,
"org.scalameta" %%% "munit-scalacheck" % munitVersion % Test,
"org.typelevel" %%% "munit-cats-effect-3" % munitCEVersion % Test
)
)
.settings(commonSettings)
.dependsOn(lambda)

lazy val examples = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("examples"))
Expand All @@ -183,7 +197,7 @@ lazy val examples = crossProject(JSPlatform, JVMPlatform)
)
)
.settings(commonSettings)
.dependsOn(lambda, lambdaHttp4s)
.dependsOn(lambda, lambdaNatchez, lambdaHttp4s)
.enablePlugins(NoPublishPlugin)

lazy val unidocs = project
Expand Down
7 changes: 4 additions & 3 deletions examples/src/main/scala/feral/examples/Http4sLambda.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

package feral.examples

import _root_.natchez.Trace
import _root_.natchez.http4s.NatchezMiddleware
import _root_.natchez.xray.XRay
import cats.effect._
import cats.effect.std.Random
import feral.lambda._
import feral.lambda.events._
import feral.lambda.http4s._
import natchez.Trace
import natchez.http4s.NatchezMiddleware
import natchez.xray.XRay
import feral.lambda.natchez._
import org.http4s.HttpApp
import org.http4s.HttpRoutes
import org.http4s.client.Client
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/scala/feral/examples/KinesisLambda.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package feral.examples

import _root_.natchez.Trace
import _root_.natchez.xray.XRay
import cats.effect._
import cats.effect.std.Random
import feral.lambda._
import feral.lambda.events.SqsEvent
import natchez.Trace
import natchez.xray.XRay
import skunk.Session

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package feral.lambda
package feral.lambda.natchez

import natchez.TraceValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package feral.lambda
package feral.lambda.natchez

import natchez.Kernel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package feral.lambda
package feral.lambda.natchez

import cats.data.Kleisli
import cats.effect.IO
import cats.effect.kernel.MonadCancelThrow
import cats.syntax.all._
import feral.lambda.Invocation
import natchez.EntryPoint
import natchez.Span
import natchez.Trace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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

import _root_.natchez.Kernel
import feral.lambda.events.ApiGatewayProxyEvent
import feral.lambda.events.ApiGatewayProxyEventV2
import feral.lambda.events.DynamoDbStreamEvent
import feral.lambda.events.KinesisStreamEvent
import feral.lambda.events.S3BatchEvent
import feral.lambda.events.SqsRecordAttributes
import feral.lambda.natchez.KernelSource
import org.typelevel.ci._

protected trait KernelSources {
private[this] val `X-Amzn-Trace-Id` = ci"X-Amzn-Trace-Id"

implicit def apiGatewayProxyEvent: KernelSource[ApiGatewayProxyEvent] =
e => Kernel(e.headers.getOrElse(Map.empty))

implicit def apiGatewayProxyEventV2: KernelSource[ApiGatewayProxyEventV2] =
e => Kernel(e.headers)

implicit def sqsRecordAttributes: KernelSource[SqsRecordAttributes] =
a => Kernel(a.awsTraceHeader.map(`X-Amzn-Trace-Id` -> _).toMap)

implicit def s3BatchEvent: KernelSource[S3BatchEvent] = KernelSource.emptyKernelSource

@deprecated(
"See feral.lambda.events.KinesisStreamEvent deprecation",
since = "0.3.0"
)
implicit def kinesisStreamEvent: KernelSource[KinesisStreamEvent] =
KernelSource.emptyKernelSource

implicit def dynamoDbStreamEvent: KernelSource[DynamoDbStreamEvent] =
KernelSource.emptyKernelSource
}

package object natchez extends KernelSources
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* limitations under the License.
*/

package feral.lambda
package feral.lambda.natchez

import cats.data.Kleisli
import cats.effect.IO
import feral.lambda.INothing
import feral.lambda.Invocation
import feral.lambda.events.KinesisStreamEvent
import natchez.EntryPoint
import natchez.Span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package feral.lambda
package events

import io.circe.Decoder
import natchez.Kernel
import org.typelevel.ci.CIString

sealed abstract class ApiGatewayProxyEvent {
Expand Down Expand Up @@ -78,9 +77,6 @@ object ApiGatewayProxyEvent {
"multiValueHeaders"
)(ApiGatewayProxyEvent.apply)

implicit def kernelSource: KernelSource[ApiGatewayProxyEvent] =
e => Kernel(e.headers.getOrElse(Map.empty))

private final case class Impl(
body: Option[String],
resource: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package feral.lambda
package events

import io.circe.Decoder
import natchez.Kernel
import org.typelevel.ci.CIString

sealed abstract class Http {
Expand Down Expand Up @@ -86,9 +85,6 @@ object ApiGatewayProxyEventV2 {
"isBase64Encoded"
)(ApiGatewayProxyEventV2.apply)

implicit def kernelSource: KernelSource[ApiGatewayProxyEventV2] =
e => Kernel(e.headers)

private final case class Impl(
rawPath: String,
rawQueryString: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ object DynamoDbStreamEvent {
implicit val decoder: Decoder[DynamoDbStreamEvent] =
Decoder.forProduct1("Records")(DynamoDbStreamEvent.apply)

implicit def kernelSource: KernelSource[DynamoDbStreamEvent] = KernelSource.emptyKernelSource

private final case class Impl(
records: List[DynamoDbRecord]
) extends DynamoDbStreamEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ object KinesisStreamEvent {
implicit val decoder: Decoder[KinesisStreamEvent] =
Decoder.forProduct1("Records")(KinesisStreamEvent.apply)

implicit def kernelSource: KernelSource[KinesisStreamEvent] = KernelSource.emptyKernelSource

private final case class Impl(
records: List[KinesisStreamRecord]
) extends KinesisStreamEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package feral.lambda.events

import feral.lambda.KernelSource
import io.circe.Decoder

// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/aws-lambda/trigger/s3-batch.d.ts
Expand All @@ -41,8 +40,6 @@ object S3BatchEvent {
Decoder.forProduct4("invocationSchemaVersion", "invocationId", "job", "tasks")(
S3BatchEvent.apply)

implicit def kernelSource: KernelSource[S3BatchEvent] = KernelSource.emptyKernelSource

private final case class Impl(
invocationSchemaVersion: String,
invocationId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package events

import io.circe.Decoder
import io.circe.scodec._
import natchez.Kernel
import org.typelevel.ci._
import scodec.bits.ByteVector

import java.time.Instant
Expand Down Expand Up @@ -176,9 +174,6 @@ object SqsRecordAttributes {
)
}

implicit def kernelSource: KernelSource[SqsRecordAttributes] = a =>
Kernel(a.awsTraceHeader.map(`X-Amzn-Trace-Id` -> _).toMap)

private final case class Impl(
awsTraceHeader: Option[String],
approximateReceiveCount: String,
Expand All @@ -192,7 +187,6 @@ object SqsRecordAttributes {
override def productPrefix = "SqsRecordAttributes"
}

private[this] val `X-Amzn-Trace-Id` = ci"X-Amzn-Trace-Id"
}

sealed abstract class SqsMessageAttribute
Expand Down