Skip to content

Commit

Permalink
Add spanId to openai-manual example (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White authored Oct 30, 2023
1 parent 05f5f16 commit cb05a8a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions JavaScript/openai-manual/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const openai = new OpenAI({
});

const tracer = new AutoblocksTracer(process.env.AUTOBLOCKS_INGESTION_KEY, {
// These apply to every call of ab.sendEvent() so we don't have to repeat them
// These apply to every call of tracer.sendEvent() so we don't have to repeat them
traceId: crypto.randomUUID(),
properties: {
provider: 'openai',
Expand All @@ -18,6 +18,9 @@ const tracer = new AutoblocksTracer(process.env.AUTOBLOCKS_INGESTION_KEY, {
async function run() {
console.log('Running example...');

// Use a spanId to group together the request + response/error events
const spanId = crypto.randomUUID();

const openAIRequest = {
model: 'gpt-3.5-turbo',
messages: [
Expand All @@ -41,7 +44,7 @@ async function run() {
};

await tracer.sendEvent('ai.request', {
properties: openAIRequest,
properties: { ...openAIRequest, spanId },
});

try {
Expand All @@ -51,12 +54,14 @@ async function run() {
properties: {
response,
latency: Date.now() - now,
spanId,
},
});
} catch (error) {
await tracer.sendEvent('ai.error', {
properties: {
error,
spanId,
},
});
}
Expand Down

1 comment on commit cb05a8a

@vercel
Copy link

@vercel vercel bot commented on cb05a8a Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.