-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inline AwsXrayIdGenerator from io.opentelemetry.contrib:opentelemetry…
…-aws-xray to minimize transitive dependencies
- Loading branch information
Showing
5 changed files
with
78 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
aws-xray-id-generator/src/main/scala/com/dwolla/tracing/AwsXrayIdGenerator.scala
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2024 Dwolla, Inc | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Based on https://github.com/open-telemetry/opentelemetry-java-contrib/blob/eece7e8ef04170fb463ddf692f61d4527b50febf/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsXrayIdGenerator.java | ||
*/ | ||
package com.dwolla.tracing | ||
|
||
import cats.effect.* | ||
import cats.effect.std.* | ||
import cats.* | ||
import cats.syntax.all.* | ||
import io.opentelemetry.api.trace.{SpanId, TraceId} | ||
import io.opentelemetry.sdk.trace.IdGenerator | ||
|
||
object AwsXrayIdGenerator { | ||
def apply[F[_] : Applicative : Clock : Random](dispatcher: Dispatcher[F]): AwsXrayIdGenerator[F] = | ||
new AwsXrayIdGenerator(dispatcher) | ||
} | ||
|
||
class AwsXrayIdGenerator[F[_] : Applicative : Clock : Random](dispatcher: Dispatcher[F]) extends IdGenerator { | ||
override def generateSpanId(): String = | ||
dispatcher.unsafeRunSync { | ||
Random[F] | ||
.nextLong | ||
.map(SpanId.fromLong) | ||
} | ||
|
||
override def generateTraceId(): String = dispatcher.unsafeRunSync { | ||
(Clock[F].realTime.map(_.toSeconds), | ||
Random[F].nextInt.map(_ & 0xFFFFFFFFL), | ||
Random[F].nextLong | ||
).mapN { case (timestampSecs, hiRandom, lowRandom) => | ||
TraceId.fromLongs(timestampSecs << 32 | hiRandom, lowRandom) | ||
} | ||
} | ||
} |
This file contains 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 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