Skip to content

Commit e5b400e

Browse files
committed
Update traces.ts
1 parent 1d55243 commit e5b400e

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

agents/src/telemetry/traces.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ class DynamicTracer {
9999
const endOnExit = options.endOnExit === undefined ? true : options.endOnExit; // default true
100100
const opts: SpanOptions = { attributes: options.attributes };
101101

102-
return new Promise((resolve, reject) => {
103-
this.tracer.startActiveSpan(options.name, opts, ctx, async (span) => {
104-
try {
105-
const result = await fn(span);
106-
resolve(result);
107-
} catch (error) {
108-
reject(error);
109-
} finally {
110-
if (endOnExit) {
111-
span.end();
112-
}
102+
// Directly return the tracer's startActiveSpan result - it handles async correctly
103+
return await this.tracer.startActiveSpan(options.name, opts, ctx, async (span) => {
104+
try {
105+
return await fn(span);
106+
} finally {
107+
if (endOnExit) {
108+
span.end();
113109
}
114-
});
110+
}
115111
});
116112
}
117113

0 commit comments

Comments
 (0)