Skip to content

Commit

Permalink
Merge pull request #1 from jetbridge/evt-bus-xray
Browse files Browse the repository at this point in the history
Add xray tracer header to event bus publish
  • Loading branch information
fwang authored Nov 11, 2024
2 parents f2a74e8 + d07b28d commit 10bb591
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/sst/src/node/event-bus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { ZodAny, ZodObject, ZodRawShape, ZodSchema, z } from "zod";
import { useLoader } from "../util/loader.js";
import { Config } from "../config/index.js";

/**
* @link https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-eventbridge/Interface/PutEventsCommandInput/
*/
type PublishOptions = {
traceHeader?: string;
};

/**
* PutEventsCommandOutput is used in return type of createEvent, in case the consumer of SST builds
* their project with declaration files, this is not portable. In order to allow TS to generate a
Expand Down Expand Up @@ -45,14 +52,22 @@ export function createEventBuilder<
>(type: Type, schema: Schema) {
type Parsed = inferParser<Schema>;
type Publish = undefined extends MetadataSchema
? (properties: Parsed["in"]) => Promise<PutEventsCommandOutput>
? (
properties: Parsed["in"],
options?: PublishOptions
) => Promise<PutEventsCommandOutput>
: (
properties: Parsed["in"],
// @ts-expect-error
metadata: inferParser<MetadataSchema>["in"]
metadata: inferParser<MetadataSchema>["in"],
options?: PublishOptions
) => Promise<void>;
const validate = validator(schema);
async function publish(properties: any, metadata: any) {
async function publish(
properties: any,
metadata: any,
options?: PublishOptions
) {
const result = await useLoader(
"sst.bus.publish",
async (input: PutEventsRequestEntry[]) => {
Expand All @@ -65,6 +80,9 @@ export function createEventBuilder<
client.send(
new PutEventsCommand({
Entries: chunk,
...(options?.traceHeader && {
TraceHeader: options.traceHeader,
}),
})
)
);
Expand Down

0 comments on commit 10bb591

Please sign in to comment.