-
-
Notifications
You must be signed in to change notification settings - Fork 50
Add lambda-otel4s module #459
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
Open
alexcardell
wants to merge
87
commits into
typelevel:main
Choose a base branch
from
alexcardell:lambda-otel4s
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
1170ca8
Extract lambda-natchez module
alexcardell 09d4127
Remove natchez-core dependency from lambda module
alexcardell 375b814
Add lambda-otel4s module
alexcardell 7ebde29
Use SqsEvent for attributes, not SqsRecord
alexcardell a5506a4
Add otel4s-sdk example
alexcardell a17882b
re-run prePR
alexcardell c596060
Remove resolvers
alexcardell 88fa15a
Add otel4s TracedHandler tests
alexcardell 11be471
Rework package structure
alexcardell 08122de
prePR
alexcardell 5bee0a3
Swap tests from SDK to oteljava
alexcardell 6b80150
Run prePR
alexcardell 5489668
Add back extra JVM test
alexcardell 4ae91a8
Add OtelJava JVM example
alexcardell 29f8248
Update otel4s to 0.6.0
alexcardell db56620
Simplify for-comp
alexcardell a737654
Fix headers
alexcardell 5d0fb2b
Update scalaJS plugin
alexcardell 9abdd5e
Remove semconv-experimental
alexcardell a961320
Add attributes for other events
alexcardell 96ce0a9
Remove unused imports
alexcardell 68ea923
Version bumps (to appease sbt 1.10)
alexcardell b2fcbf2
Add http4s-otel4s-middleware to example
alexcardell 8f06d74
Fix import order
alexcardell 4c1cbb3
use otel4s-sdk-trace-testkit to run tests across all platforms
iRevive 2e0937b
Merge pull request #2 from iRevive/lambda-otel4s
alexcardell 18768c2
Merge branch 'main' into lambda-otel4s
alexcardell 51aad4a
Move TracedHandlerSuite to JVM
alexcardell a208070
Update workflows
alexcardell 2d435fd
Swap module order
alexcardell ad3dbae
Fix TracedHandlerSuite class name
alexcardell fe22625
Add JS TracedHandler suite
alexcardell c8f2913
Remove unused imports
alexcardell e8fbf9d
Update base version
alexcardell 501e76a
Update otel4s to 0.8
alexcardell 5e05972
Lambda otel4s: test span attributes
iRevive a47540b
Merge pull request #3 from iRevive/lambda-otel4s
alexcardell 81ce08d
Format
alexcardell 84d303b
Swap List[Attribute[_]] to Attributes
alexcardell 73ed59c
Remove unused import
alexcardell eefbc7d
Remove unused import
alexcardell b87ae6c
Add LambdaContextAttributes test
alexcardell 1010972
Add LambdaMessageAttributesTest
alexcardell 92dded7
Deduplicate examples module settings keys
alexcardell 7687287
Format build.sbt
alexcardell d35d875
Make otel4s attribute utilities package private
alexcardell a6f8e6c
Remove _root_ from example imports
alexcardell 684cb50
Fix example
alexcardell 353ba48
Remove http4s-otel4s-middleware
alexcardell 07d2bbe
Bump otel to 0.9
alexcardell 20d7b5f
Fix 0.9 bump
alexcardell c52d901
Bump otel4s to 0.10
alexcardell c062551
Move KernelSources to KernelSource companion
alexcardell 8ebf71c
Bump skunk again
alexcardell e538c3f
Remove Event parameter from TracedHandler
alexcardell 4231bca
Use shared trace handler suite
alexcardell 29edc99
Add v0.4.0 rewrites for natchez module
alexcardell 9bcbb13
Fix formatting
alexcardell ef7d883
Add scalafix v0.4.0 rewrite input/output
alexcardell bb2970f
Split 0.3.0 and 0.4.0 rewrite rules into subprojects
alexcardell a99a656
Update workflows
alexcardell 9b5d7d6
Fix scalafix 0.4.0 rewrites test
alexcardell ea168f5
Bump to scala 3.3.4
alexcardell 9cca0f0
Remove 0.3.0 migrations
alexcardell c46d6d3
Bump sbt-lambda scalaVersion
alexcardell 15d8feb
Remove unused examples imports
alexcardell fb3e029
Rename EventSpanAttributes -> EventAttributeSources
alexcardell 38b9114
Merge branch 'main' into lambda-otel4s
alexcardell 4b21959
Add http4s-otel4s-middleware
alexcardell e0e7955
Simplify otel attributes file structure
alexcardell b131fcb
Fix imports
alexcardell 45a474a
Update otel4s to 0.11.0
alexcardell cc3928a
Upgrade otel4s to 0.12.0
alexcardell 88c8cda
Upgrade CE and fs2
alexcardell 4cc9535
Bump scala 2
alexcardell ed24054
Merge branch 'main' into lambda-otel4s
alexcardell d3f5dea
Update example
alexcardell 69be990
Merge branch 'main' into lambda-otel4s
alexcardell eb2e6d2
fix build.sbt
alexcardell 3d740b9
Fix munit-cats-effect dependency reference
alexcardell 56b7615
Fix fixture
alexcardell 77d1511
bump otel4s to 0.13.0
alexcardell 2b0493a
fix deprecation
alexcardell f374e1d
Bump otel4s 0.13.2
alexcardell 0c25ade
Bump otel4s to 0.14.0
alexcardell bc66ebf
Merge branch 'main' into lambda-otel4s
alexcardell f3d5c74
Update mergify
alexcardell 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
82 changes: 82 additions & 0 deletions
82
examples/jvm/src/main/scala/feral/examples/SqsOtelJavaExample.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,82 @@ | ||
| /* | ||
| * 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.examples | ||
|
|
||
| import cats.Monad | ||
| import cats.effect.IO | ||
| import cats.syntax.all._ | ||
| import feral.lambda.INothing | ||
| import feral.lambda.IOLambda | ||
| import feral.lambda.Invocation | ||
| import feral.lambda.events.SqsEvent | ||
| import feral.lambda.events.SqsRecord | ||
| import feral.lambda.otel4s._ | ||
| import org.http4s.client.Client | ||
| import org.http4s.ember.client.EmberClientBuilder | ||
| import org.http4s.otel4s.middleware.trace.client.ClientMiddleware | ||
| import org.http4s.otel4s.middleware.trace.client.ClientSpanDataProvider | ||
| import org.http4s.otel4s.middleware.trace.client.UriRedactor | ||
| import org.typelevel.otel4s.oteljava.OtelJava | ||
| import org.typelevel.otel4s.trace.Tracer | ||
| import org.typelevel.otel4s.trace.TracerProvider | ||
| import org.typelevel.scalaccompat.annotation.unused | ||
|
|
||
| object SqsOtelExample extends IOLambda[SqsEvent, INothing] { | ||
|
|
||
| def handler = | ||
| OtelJava | ||
| .autoConfigured[IO]() | ||
| .evalMap { otel => | ||
| implicit val tp: TracerProvider[IO] = otel.tracerProvider | ||
| val otelClientRedactor = new UriRedactor.OnlyRedactUserInfo {} | ||
| val spanDataProvider = ClientSpanDataProvider.openTelemetry(otelClientRedactor) | ||
| val tracer = tp.get("com.example") | ||
| val middleware = ClientMiddleware.builder[IO](spanDataProvider).build | ||
| (middleware, tracer).tupled | ||
| } | ||
| .flatMap { | ||
| case (middleware, tracer) => | ||
| implicit val t: Tracer[IO] = tracer | ||
|
|
||
| for { | ||
| client <- EmberClientBuilder.default[IO].build.map(middleware.wrapClient) | ||
| } yield { implicit inv: Invocation[IO, SqsEvent] => | ||
| TracedHandler[IO, SqsEvent, INothing]( | ||
| handleEvent[IO](client) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| def handleEvent[F[_]: Monad: Tracer]( | ||
| @unused client: Client[F] | ||
| )(implicit inv: Invocation[F, SqsEvent]): F[Option[INothing]] = inv.event.flatMap { event => | ||
| event | ||
| .records | ||
| .traverse(record => | ||
| Tracer[F].span("handle-record", SqsRecordAttributes(record)).surround { | ||
| handleRecord[F](record) | ||
| }) | ||
| .as(None) | ||
| } | ||
|
|
||
| def handleRecord[F[_]: Monad: Tracer](@unused record: SqsRecord): F[Unit] = { | ||
| Tracer[F].span("some-operation").surround { | ||
| Monad[F].unit | ||
| } | ||
| } | ||
|
|
||
| } |
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
59 changes: 59 additions & 0 deletions
59
lambda-natchez/shared/src/main/scala/feral/lambda/natchez/KernelSource.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,59 @@ | ||
| /* | ||
| * 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.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 natchez.Kernel | ||
| import org.typelevel.ci._ | ||
|
|
||
| trait KernelSource[Event] { | ||
| def extract(event: Event): Kernel | ||
| } | ||
|
|
||
| object KernelSource { | ||
| @inline def apply[E](implicit ev: KernelSource[E]): ev.type = ev | ||
|
|
||
| def emptyKernelSource[E]: KernelSource[E] = _ => Kernel(Map.empty) | ||
|
|
||
| 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 | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.