-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Problem
Currently, when using @effect-aws/powertools-tracer with any @effect-aws/client-* package, users must write significant boilerplate to properly instrument AWS SDK clients for X-Ray subsegments:
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import { DynamoDBDocumentService } from "@effect-aws/dynamodb";
import { XrayTracer } from "@effect-aws/powertools-tracer/Tracer";
import { Effect, Layer } from "effect";
export const InstrumentedLayer = Layer.unwrapEffect(
Effect.gen(function* () {
const tracer = yield* XrayTracer;
const rawClient = new DynamoDBClient({});
const instrumentedClient = yield* Effect.fromNullable(
tracer.captureAWSv3Client(rawClient),
);
const documentClient = DynamoDBDocumentClient.from(instrumentedClient);
return DynamoDBDocumentService.baseLayer(() => documentClient);
}),
);This pattern:
- Requires understanding of
Layer.unwrapEffect+Effect.gencombination - Must be repeated for every AWS service client
- Requires manually accessing
XrayTracerand callingcaptureAWSv3Client - Easy to get wrong (timing of client capture matters for X-Ray)
Proposed Solution
Add a helper function to @effect-aws/powertools-tracer that simplifies AWS SDK client instrumentation. Ideally something like:
import { DynamoDB } from "@effect-aws/client-dynamodb";
import { S3 } from "@effect-aws/client-s3";
import { withXrayTracing } from "@effect-aws/powertools-tracer";
// Wrap any client layer - works with all @effect-aws/client-* packages
const InstrumentedDynamoDB = withXrayTracing(DynamoDB.defaultLayer);
const InstrumentedS3 = withXrayTracing(S3.defaultLayer);
// Also works with custom configurations
const CustomDynamoDB = withXrayTracing(
DynamoDB.layer({ region: "eu-central-1" })
);The exact API design is open for discussion - the key goal is to eliminate the boilerplate while keeping the instrumentation in @effect-aws/powertools-tracer rather than modifying client packages.
Why add this to powertools-tracer?
- No changes to client packages - All 60+
@effect-aws/client-*packages remain unchanged - No new dependencies - Client packages don't need to depend on powertools-tracer
- Single maintenance point - Instrumentation logic lives in one place
- Composable - Works with Effect's layer composition and any client layer
- Optional - Users who don't need X-Ray don't pay any cost
Additional Context
- AWS Powertools Tracer uses
captureAWSv3Client()which patches the AWS SDK client - The
@effect-aws/powertools-tracerpackage already providesXrayTracertag - All
@effect-aws/client-*packages usebaseLayer()which accepts a client factory - this could be leveraged
Benefits
- Reduced boilerplate - One-liner instead of 10+ lines
- Consistent pattern - Same API for all AWS services
- Harder to misuse - Library handles timing/scoping correctly
- Better DX - Users don't need to understand Layer internals
floydspace
Metadata
Metadata
Assignees
Labels
No labels