8000 fix(sdk): protect against failures to JSON.stringify() input/output (… · 5war00p/openllmetry-js@b49a700 · GitHub
[go: up one dir, main page]

Skip to content

Commit b49a700

Browse files
nirga5war00p
authored andcommitted
fix(sdk): protect against failures to JSON.stringify() input/output (traceloop#91)
1 parent d0e1d0e commit b49a700

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,21 @@ function withEntity<
6060
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_NAME, name);
6161

6262
if (shouldSendTraces()) {
63-
const input = inputParameters ?? args;
64-
if (input.length === 1 && typeof input[0] === "object") {
65-
span.setAttribute(
66-
SpanAttributes.TRACELOOP_ENTITY_INPUT,
67-
JSON.stringify({ args: [], kwargs: input[0] }),
68-
);
69-
} else {
70-
span.setAttribute(
71-
SpanAttributes.TRACELOOP_ENTITY_INPUT,
72-
JSON.stringify({ args: input, kwargs: {} }),
73-
);
63+
try {
64+
const input = inputParameters ?? args;
65+
if (input.length === 1 && typeof input[0] === "object") {
66+
span.setAttribute(
67+
SpanAttributes.TRACELOOP_ENTITY_INPUT,
68+
JSON.stringify({ args: [], kwargs: input[0] }),
69+
);
70+
} else {
71+
span.setAttribute(
72+
SpanAttributes.TRACELOOP_ENTITY_INPUT,
73+
JSON.stringify({ args: input, kwargs: {} }),
74+
);
75+
}
76+
} catch {
77+
/* empty */
7478
}
7579
}
7680

@@ -123,10 +127,6 @@ export function withTask<
123127
A extends unknown[],
124128
F extends (...args: A) => ReturnType<F>,
125129
>(config: DecoratorConfig, fn: F, ...args: A) {
126-
console.log(
127-
"Warning: this way of calling `withTask` is deprecated. " +
128-
"Check out https://www.traceloop.com/docs/openllmetry/tracing/annotations#workflows-and-tasks",
129-
);
130130
return withEntity(
131131
TraceloopSpanKindValues.TASK,
132132
config,

0 commit comments

Comments
 (0)
0