Your Lambda handler function
Wrapped handler that auto-flushes traces
// API Gateway event
export const handler = withObserve(async (event) => {
const body = JSON.parse(event.body);
const openai = observe(new OpenAI());
const result = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: body.message }],
});
return {
statusCode: 200,
body: JSON.stringify(result.choices[0].message),
};
});
Wrap an AWS Lambda handler with automatic trace flushing
Always flushes before returning - Lambda freezes the container immediately after the handler returns, so this is required.