Repository navigation
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
76
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
76 commits
Select commit
Hold shift + click to select a range
c05c29d
Extract lambda-natchez module
alexcardell 8d84619
Remove natchez-core dependency from lambda module
alexcardell 2862dff
Add lambda-otel4s module
alexcardell ad9ef67
Use SqsEvent for attributes, not SqsRecord
alexcardell 328000b
Add otel4s-sdk example
alexcardell ed29cea
re-run prePR
alexcardell e759554
Remove resolvers
alexcardell ad6c45e
Add otel4s TracedHandler tests
alexcardell 25ef4e2
Rework package structure
alexcardell c932050
prePR
alexcardell b64efb1
Swap tests from SDK to oteljava
alexcardell 09a3ef8
Run prePR
alexcardell f36f069
Add back extra JVM test
alexcardell de2b260
Add OtelJava JVM example
alexcardell ca04346
Update otel4s to 0.6.0
alexcardell ecd17cf
Simplify for-comp
alexcardell 0a68750
Fix headers
alexcardell 29aecf7
Remove semconv-experimental
alexcardell 8bd5eba
Add attributes for other events
alexcardell 621e8e1
Remove unused imports
alexcardell ed1d2ce
Add http4s-otel4s-middleware to example
alexcardell 4950af2
Fix import order
alexcardell 9a1d4a4
use otel4s-sdk-trace-testkit to run tests across all platforms
iRevive 1f995b6
Move TracedHandlerSuite to JVM
alexcardell 3f541f6
Update workflows
alexcardell a0252cf
Swap module order
alexcardell f8b4f52
Fix TracedHandlerSuite class name
alexcardell c0a1919
Add JS TracedHandler suite
alexcardell dacbcb7
Remove unused imports
alexcardell e7ad6e7
Update base version
alexcardell 5e277a1
Update otel4s to 0.8
alexcardell 82408eb
Lambda otel4s: test span attributes
iRevive 5092bf7
Format
alexcardell c29d0a4
Swap List[Attribute[_]] to Attributes
alexcardell 288e04e
Remove unused import
alexcardell eca13ff
Remove unused import
alexcardell ec4ded6
Add LambdaContextAttributes test
alexcardell ada7d29
Add LambdaMessageAttributesTest
alexcardell 7289d13
Deduplicate examples module settings keys
alexcardell 3c299b8
Make otel4s attribute utilities package private
alexcardell de0ab57
Remove _root_ from example imports
alexcardell 5f7db04
Fix example
alexcardell 0ad05e9
Remove http4s-otel4s-middleware
alexcardell 3ead38f
Bump otel to 0.9
alexcardell 1542720
Fix 0.9 bump
alexcardell 7af71ab
Move KernelSources to KernelSource companion
alexcardell 1a6d6a3
Remove Event parameter from TracedHandler
alexcardell 0b8d4cc
Use shared trace handler suite
alexcardell 44a0aaf
Add v0.4.0 rewrites for natchez module
alexcardell 0f14301
Fix formatting
alexcardell 7f433d8
Add scalafix v0.4.0 rewrite input/output
alexcardell a5bf437
Split 0.3.0 and 0.4.0 rewrite rules into subprojects
alexcardell 480dfcf
Update workflows
alexcardell 8b0c5ff
Fix scalafix 0.4.0 rewrites test
alexcardell 0f985ad
Remove 0.3.0 migrations
alexcardell 352295b
Remove unused examples imports
alexcardell ed8be15
Rename EventSpanAttributes -> EventAttributeSources
alexcardell 7eddd69
Add http4s-otel4s-middleware
alexcardell 3e421af
Simplify otel attributes file structure
alexcardell d16a090
Fix imports
alexcardell 0ff2142
Update example
alexcardell 33591aa
Fix munit-cats-effect dependency reference
alexcardell 4606aac
Fix fixture
alexcardell 7dd11a9
fix deprecation
alexcardell f8c232b
Update mergify
alexcardell 2aea5e0
Bump
alexcardell ceae75d
fmt
alexcardell e6f6cd2
Fix lambda plugin scala version
alexcardell 544cea7
Add comment explaining semanticdb
alexcardell d96fbc0
more semantic conventions
alexcardell 8fa46a7
Fix unused import
alexcardell 88d59af
bump otel4s
alexcardell 9594341
Bump to 1.0.0
alexcardell e76ea43
Change input implicit to TracerProvider
alexcardell 43a268e
Fix tupling
alexcardell 1b1aa67
Regenerate GitHub Actions workflow
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
85 changes: 85 additions & 0 deletions
85
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,85 @@ | ||
| /* | ||
| * 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.effect.Resource | ||
| 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 middleware = ClientMiddleware.builder[IO](spanDataProvider).build | ||
|
|
||
| middleware.map((_, tp)) | ||
| } | ||
| .flatMap { | ||
| case (middleware, tracerProvider) => | ||
| implicit val tp: TracerProvider[IO] = tracerProvider | ||
|
|
||
| for { | ||
| client <- EmberClientBuilder.default[IO].build.map(middleware.wrapClient) | ||
| tracer <- Resource.eval(tp.get("com.example")) | ||
| } yield { implicit inv: Invocation[IO, SqsEvent] => | ||
| implicit val t: Tracer[IO] = tracer | ||
| 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.