https://github.com/freckle/hs-opentelemetry-awsxray
IdGenerator and Propagator for hs-opentelemetry-sdk that generates and propagates TraceId and SpanId values that are compatible with AWS X-Ray
https://github.com/freckle/hs-opentelemetry-awsxray
opentelemetry terraform-managed
Last synced: 8 months ago
JSON representation
IdGenerator and Propagator for hs-opentelemetry-sdk that generates and propagates TraceId and SpanId values that are compatible with AWS X-Ray
- Host: GitHub
- URL: https://github.com/freckle/hs-opentelemetry-awsxray
- Owner: freckle
- License: mit
- Created: 2023-02-28T15:29:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-27T00:29:03.000Z (over 1 year ago)
- Last Synced: 2025-01-27T01:24:11.580Z (over 1 year ago)
- Topics: opentelemetry, terraform-managed
- Language: Haskell
- Homepage:
- Size: 59.6 KB
- Stars: 1
- Watchers: 8
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# AWS X-Ray Support for hs-opentelemetry
[](https://github.com/freckle/hs-opentelemetry-awsxray/actions/workflows/ci.yml)
An `IdGenerator` and `Propagator` for [`hs-opentelemetry-sdk`][sdk] that
generates and propagates `TraceId` and `SpanId` values that are [compatible with
AWS X-Ray][xray].
[sdk]: https://hackage.haskell.org/package/hs-opentelemetry-sdk
[xray]: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids
## Usage
The API currently exposed by the `hs-opentelemetry-sdk` package lacks a
convenient way to modify the `TracerProviderOptions` (to tell it to use our
generator/propagator) as part of initialization. You basically have to
re-implement the internals of `initializeTracerProvider` to do so.
While we plan to open a PR upstream to address the lack of API here, the
workaround approach has at least been been encapsulated in a module of this
library for convenience:
```hs
import OpenTelemetry.AWSXRay
import OpenTelemetry.Trace
import OpenTelemetry.Trace.Setup
import OpenTelemetry.Trace.Setup.Lens
main :: IO ()
main = do
withTracerProvider modifyTracerProviderOptions $ \tracerProvider -> do
let tracer = makeTracer tracerProvider "my-app" tracerOptions
-- do something with tracer
modifyTracerProviderOptions :: TracerProviderOptions -> TracerProviderOptions
modifyTracerProviderOptions =
idGeneratorL .~ awsXRayIdGenerator
. propagatorL <>~ awsXRayContextPropagator
```
This example uses lens, but you certainly don't have to.
## Additional References
- https://docs.aws.amazon.com/xray/latest/devguide/xray-services-adot.html
- https://aws.amazon.com/blogs/opensource/migrating-x-ray-tracing-to-aws-distro-for-opentelemetry/
---
[CHANGELOG](./CHANGELOG.md) | [LICENSE](./LICENSE)