Skip to content

Commit e41b5aa

Browse files
kyzyxaaronvg
andauthored
Fix typescript trace bugs (#1275)
Fixes #1274 <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fix TypeScript tracing bugs in `BamlCtxManager` by handling undefined responses and ensuring proper return values. > > - **Behavior**: > - Fix `span.finish` in `BamlCtxManager` to handle undefined `response` by defaulting to an empty object. > - Ensure `ctx.run` returns the result in `traceFnSync` and `traceFnAsync` methods of `BamlCtxManager`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 8faf23e. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Co-authored-by: aaronvg <[email protected]>
1 parent 039b45a commit e41b5aa

File tree

4 files changed

+51
-56
lines changed

4 files changed

+51
-56
lines changed

engine/language_client_typescript/async_context_vars.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class BamlCtxManager {
5151
return;
5252
}
5353
try {
54-
span.finish(response, manager);
54+
span.finish(response === undefined ? null : response, manager);
5555
}
5656
catch (e) {
5757
console.error('BAML internal error', e);
@@ -78,7 +78,7 @@ class BamlCtxManager {
7878
[`arg${i}`]: arg, // generic way to label args
7979
}), {});
8080
const [mng, span] = this.startTrace(name, params);
81-
this.ctx.run(mng, () => {
81+
return this.ctx.run(mng, () => {
8282
try {
8383
const response = func(...args);
8484
this.endTrace(span, response);
@@ -99,7 +99,7 @@ class BamlCtxManager {
9999
[`arg${i}`]: arg, // generic way to label args
100100
}), {});
101101
const [mng, span] = this.startTrace(name, params);
102-
await this.ctx.run(mng, async () => {
102+
return await this.ctx.run(mng, async () => {
103103
try {
104104
const response = await func(...args);
105105
this.endTrace(span, response);

engine/language_client_typescript/typescript_src/async_context_vars.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class BamlCtxManager {
5757
return
5858
}
5959
try {
60-
span.finish(response, manager)
60+
span.finish(response === undefined ? null : response, manager)
6161
} catch (e) {
6262
console.error('BAML internal error', e)
6363
}
@@ -89,7 +89,7 @@ export class BamlCtxManager {
8989
{},
9090
)
9191
const [mng, span] = this.startTrace(name, params)
92-
this.ctx.run(mng, () => {
92+
return this.ctx.run(mng, () => {
9393
try {
9494
const response = func(...args)
9595
this.endTrace(span, response)
@@ -113,7 +113,7 @@ export class BamlCtxManager {
113113
{},
114114
)
115115
const [mng, span] = this.startTrace(name, params)
116-
await this.ctx.run(mng, async () => {
116+
return await this.ctx.run(mng, async () => {
117117
try {
118118
const response = await func(...args)
119119
this.endTrace(span, response)

0 commit comments

Comments
 (0)