Skip to content

Commit

Permalink
Fix typescript trace bugs (#1275)
Browse files Browse the repository at this point in the history
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 <aaron@boundaryml.com>
  • Loading branch information
kyzyx and aaronvg authored Dec 30, 2024
1 parent 039b45a commit e41b5aa
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 56 deletions.
6 changes: 3 additions & 3 deletions engine/language_client_typescript/async_context_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BamlCtxManager {
return;
}
try {
span.finish(response, manager);
span.finish(response === undefined ? null : response, manager);
}
catch (e) {
console.error('BAML internal error', e);
Expand All @@ -78,7 +78,7 @@ class BamlCtxManager {
[`arg${i}`]: arg, // generic way to label args
}), {});
const [mng, span] = this.startTrace(name, params);
this.ctx.run(mng, () => {
return this.ctx.run(mng, () => {
try {
const response = func(...args);
this.endTrace(span, response);
Expand All @@ -99,7 +99,7 @@ class BamlCtxManager {
[`arg${i}`]: arg, // generic way to label args
}), {});
const [mng, span] = this.startTrace(name, params);
await this.ctx.run(mng, async () => {
return await this.ctx.run(mng, async () => {
try {
const response = await func(...args);
this.endTrace(span, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class BamlCtxManager {
return
}
try {
span.finish(response, manager)
span.finish(response === undefined ? null : response, manager)
} catch (e) {
console.error('BAML internal error', e)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ export class BamlCtxManager {
{},
)
const [mng, span] = this.startTrace(name, params)
this.ctx.run(mng, () => {
return this.ctx.run(mng, () => {
try {
const response = func(...args)
this.endTrace(span, response)
Expand All @@ -113,7 +113,7 @@ export class BamlCtxManager {
{},
)
const [mng, span] = this.startTrace(name, params)
await this.ctx.run(mng, async () => {
return await this.ctx.run(mng, async () => {
try {
const response = await func(...args)
this.endTrace(span, response)
Expand Down
Loading

0 comments on commit e41b5aa

Please sign in to comment.