diff --git a/packages/sst/src/node/event-bus/index.ts b/packages/sst/src/node/event-bus/index.ts index 47ee61cfb..46cb355df 100644 --- a/packages/sst/src/node/event-bus/index.ts +++ b/packages/sst/src/node/event-bus/index.ts @@ -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 @@ -45,14 +52,22 @@ export function createEventBuilder< >(type: Type, schema: Schema) { type Parsed = inferParser; type Publish = undefined extends MetadataSchema - ? (properties: Parsed["in"]) => Promise + ? ( + properties: Parsed["in"], + options?: PublishOptions + ) => Promise : ( properties: Parsed["in"], // @ts-expect-error - metadata: inferParser["in"] + metadata: inferParser["in"], + options?: PublishOptions ) => Promise; 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[]) => { @@ -65,6 +80,9 @@ export function createEventBuilder< client.send( new PutEventsCommand({ Entries: chunk, + ...(options?.traceHeader && { + TraceHeader: options.traceHeader, + }), }) ) );