Skip to content

Commit a5f3100

Browse files
committed
pretty
1 parent 619b303 commit a5f3100

File tree

5 files changed

+47
-33
lines changed

5 files changed

+47
-33
lines changed

packages/sample-app/src/sample_associations.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ async function customerServiceDemo() {
112112
});
113113

114114
console.log("Customer 1 (cust-001):");
115-
console.log(`Response: ${customer1Response.choices[0].message.content}\n`);
115+
console.log(
116+
`Response: ${customer1Response.choices[0].message.content}\n`,
117+
);
116118

117119
// Customer 2 - Update associations for new customer
118120
traceloop.Associations.set([
@@ -131,7 +133,9 @@ async function customerServiceDemo() {
131133
});
132134

133135
console.log("Customer 2 (cust-002):");
134-
console.log(`Response: ${customer2Response.choices[0].message.content}\n`);
136+
console.log(
137+
`Response: ${customer2Response.choices[0].message.content}\n`,
138+
);
135139
},
136140
);
137141
}

packages/sample-app/src/sample_chatbot_interactive.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ class InteractiveChatbot {
110110
parameters: z.object({
111111
expression: z
112112
.string()
113-
.describe("The mathematical expression to evaluate (e.g., '2 + 2' or '10 * 5')"),
113+
.describe(
114+
"The mathematical expression to evaluate (e.g., '2 + 2' or '10 * 5')",
115+
),
114116
}),
115117
execute: async ({ expression }) => {
116118
try {
@@ -130,16 +132,25 @@ class InteractiveChatbot {
130132
description:
131133
"Get the current weather for a location. Use this when users ask about weather conditions.",
132134
parameters: z.object({
133-
location: z.string().describe("The city and country, e.g., 'London, UK'"),
135+
location: z
136+
.string()
137+
.describe("The city and country, e.g., 'London, UK'"),
134138
}),
135139
execute: async ({ location }) => {
136140
console.log(
137141
`\n${colors.yellow}🔧 Weather: Checking weather for ${location}${colors.reset}`,
138142
);
139143
// Simulated weather data
140-
const weatherConditions = ["sunny", "cloudy", "rainy", "partly cloudy"];
144+
const weatherConditions = [
145+
"sunny",
146+
"cloudy",
147+
"rainy",
148+
"partly cloudy",
149+
];
141150
const condition =
142-
weatherConditions[Math.floor(Math.random() * weatherConditions.length)];
151+
weatherConditions[
152+
Math.floor(Math.random() * weatherConditions.length)
153+
];
143154
const temperature = Math.floor(Math.random() * 30) + 10; // 10-40°C
144155
return {
145156
location,

packages/traceloop-sdk/src/lib/tracing/associations.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export enum AssociationProperty {
1717
* Use this to check if a property should be set directly or with the TRACELOOP_ASSOCIATION_PROPERTIES prefix.
1818
*/
1919
export const STANDARD_ASSOCIATION_PROPERTIES = new Set<string>(
20-
Object.values(AssociationProperty)
20+
Object.values(AssociationProperty),
2121
);
2222

2323
/**
@@ -48,7 +48,9 @@ export class Associations {
4848
// Get current associations from context or create empty object
4949
const existingAssociations = otelContext
5050
.active()
51-
.getValue(ASSOCATION_PROPERTIES_KEY) as Record<string, string> | undefined;
51+
.getValue(ASSOCATION_PROPERTIES_KEY) as
52+
| Record<string, string>
53+
| undefined;
5254
const currentAssociations: Record<string, string> = existingAssociations
5355
? { ...existingAssociations }
5456
: {};
@@ -65,7 +67,7 @@ export class Associations {
6567

6668
// Set the new context as active using the context manager
6769
// This is the equivalent of Python's attach(set_value(...))
68-
const contextManager = (otelContext as any)['_getContextManager']();
70+
const contextManager = (otelContext as any)["_getContextManager"]();
6971
if (
7072
contextManager &&
7173
contextManager instanceof AsyncLocalStorageContextManager

packages/traceloop-sdk/test/associations.test.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ describe("Test Associations API", () => {
111111
assert.ok(chatSpan);
112112

113113
// Check that the association is set on both workflow and LLM spans
114-
assert.strictEqual(
115-
workflowSpan.attributes["conversation_id"],
116-
"conv-123",
117-
);
114+
assert.strictEqual(workflowSpan.attributes["conversation_id"], "conv-123");
118115
assert.strictEqual(
119116
chatSpan.attributes[
120117
`${SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.conversation_id`
@@ -276,15 +273,6 @@ describe("Test Associations API", () => {
276273
});
277274

278275
it("should propagate associations to all child spans", async () => {
279-
@traceloop.task({ name: "subtask" })
280-
async function subtask() {
281-
const chatCompletion = await openai.chat.completions.create({
282-
messages: [{ role: "user", content: "Child task message" }],
283-
model: "gpt-3.5-turbo",
284-
});
285-
return chatCompletion.choices[0].message.content;
286-
}
287-
288276
const result = await traceloop.withWorkflow(
289277
{ name: "test_child_propagation" },
290278
async () => {
@@ -295,7 +283,16 @@ describe("Test Associations API", () => {
295283
]);
296284

297285
// Call a child task
298-
const taskResult = await subtask();
286+
const taskResult = await traceloop.withTask(
287+
{ name: "subtask" },
288+
async () => {
289+
const chatCompletion = await openai.chat.completions.create({
290+
messages: [{ role: "user", content: "Child task message" }],
291+
model: "gpt-3.5-turbo",
292+
});
293+
return chatCompletion.choices[0].message.content;
294+
},
295+
);
299296

300297
return taskResult;
301298
},
@@ -327,10 +324,16 @@ describe("Test Associations API", () => {
327324
);
328325
assert.strictEqual(workflowSpan.attributes["user_id"], "user-propagate");
329326

330-
assert.strictEqual(taskSpan.attributes["conversation_id"], "conv-propagate");
327+
assert.strictEqual(
328+
taskSpan.attributes["conversation_id"],
329+
"conv-propagate",
330+
);
331331
assert.strictEqual(taskSpan.attributes["user_id"], "user-propagate");
332332

333-
assert.strictEqual(chatSpan.attributes["conversation_id"], "conv-propagate");
333+
assert.strictEqual(
334+
chatSpan.attributes["conversation_id"],
335+
"conv-propagate",
336+
);
334337
assert.strictEqual(chatSpan.attributes["user_id"], "user-propagate");
335338
});
336339

pnpm-lock.yaml

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)