-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
72
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
72 commits
Select commit
Hold shift + click to select a range
bdd04ab
Extract lambda-natchez module
alexcardell e9e4f2d
Remove natchez-core dependency from lambda module
alexcardell c9e990f
Add lambda-otel4s module
alexcardell 1b51a90
Use SqsEvent for attributes, not SqsRecord
alexcardell 80c86f3
Add otel4s-sdk example
alexcardell e455e8e
re-run prePR
alexcardell 8e16c45
Remove resolvers
alexcardell 39de366
Add otel4s TracedHandler tests
alexcardell 962db5b
Rework package structure
alexcardell 99fe831
prePR
alexcardell bc6ca86
Swap tests from SDK to oteljava
alexcardell 8693872
Run prePR
alexcardell c1603fe
Add back extra JVM test
alexcardell b777ad5
Add OtelJava JVM example
alexcardell 250d028
Update otel4s to 0.6.0
alexcardell c759e46
Simplify for-comp
alexcardell 4dcedfb
Fix headers
alexcardell 5d2fe55
Remove semconv-experimental
alexcardell ed653c4
Add attributes for other events
alexcardell 7781210
Remove unused imports
alexcardell 584c243
Add http4s-otel4s-middleware to example
alexcardell 02f2143
Fix import order
alexcardell 5faecb0
use otel4s-sdk-trace-testkit to run tests across all platforms
iRevive 844fddf
Move TracedHandlerSuite to JVM
alexcardell bfff8f2
Update workflows
alexcardell 7310357
Swap module order
alexcardell f0f7585
Fix TracedHandlerSuite class name
alexcardell 37cc33f
Add JS TracedHandler suite
alexcardell 29b51c2
Remove unused imports
alexcardell 5547fd2
Update base version
alexcardell ad58bff
Update otel4s to 0.8
alexcardell c81279c
Lambda otel4s: test span attributes
iRevive 271b937
Format
alexcardell a54e522
Swap List[Attribute[_]] to Attributes
alexcardell ff87ea8
Remove unused import
alexcardell 25b0cf8
Remove unused import
alexcardell f2622a1
Add LambdaContextAttributes test
alexcardell e07ba78
Add LambdaMessageAttributesTest
alexcardell 5b03a45
Deduplicate examples module settings keys
alexcardell 913bfb1
Make otel4s attribute utilities package private
alexcardell 11ebd3e
Remove _root_ from example imports
alexcardell 8d9a599
Fix example
alexcardell ea82a43
Remove http4s-otel4s-middleware
alexcardell dc110c4
Bump otel to 0.9
alexcardell 691f832
Fix 0.9 bump
alexcardell d08a948
Move KernelSources to KernelSource companion
alexcardell 5dc42c1
Remove Event parameter from TracedHandler
alexcardell 86ae33e
Use shared trace handler suite
alexcardell 2b398e8
Add v0.4.0 rewrites for natchez module
alexcardell fcd9a67
Fix formatting
alexcardell fc41dcb
Add scalafix v0.4.0 rewrite input/output
alexcardell 926baa0
Split 0.3.0 and 0.4.0 rewrite rules into subprojects
alexcardell 6ef9c20
Update workflows
alexcardell ceae158
Fix scalafix 0.4.0 rewrites test
alexcardell dae7207
Remove 0.3.0 migrations
alexcardell 66a3d93
Remove unused examples imports
alexcardell c16c20a
Rename EventSpanAttributes -> EventAttributeSources
alexcardell 5cb414e
Add http4s-otel4s-middleware
alexcardell ffc962e
Simplify otel attributes file structure
alexcardell edee180
Fix imports
alexcardell 5e628d7
Update example
alexcardell e23b16f
Fix munit-cats-effect dependency reference
alexcardell 7abe21e
Fix fixture
alexcardell e68bfeb
fix deprecation
alexcardell 432cc4b
Update mergify
alexcardell 42278bf
Bump
alexcardell 4a18338
fmt
alexcardell b5c6efc
Fix lambda plugin scala version
alexcardell 5eacd1b
Add comment explaining semanticdb
alexcardell e62dee3
more semantic conventions
alexcardell 52301c4
Fix unused import
alexcardell c34e9b0
bump otel4s
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
Oops, something went wrong.
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.