-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recording Exceptions Example for Typescript Doesn't Work Out of the Box #5805
Comments
Definitely the tiniest of papercuts, but I figured I'd mention it while I was here |
@Grunet thanks for reporting! All feedback is helpful @open-telemetry/javascript-approvers PTAL! |
Huh, I get const doWork = (x: number) => {
if (x > 0) {
throw new Error("uh oh! failed to do the thing");
}
return x;
}
//...
try {
doWork(1);
} catch (ex) {
span.recordException(ex);
span.setStatus({ code: SpanStatusCode.ERROR });
} |
@Grunet do you have a copy-pastable repro per chance? |
It's not an exact repro, but I just copied recordException's type signature and the types it was depending on and put it into this playground that exhibits the issue for me If you need a full runnable minimal repro just lmk, it just might take a sec to put together |
The example for "Recording exceptions" for Typescript doesn't work as-is. You have to do something to convince the compiler that you're allowed to pass the
ex
(typed asunknown
by default since I think JS lets you throw anything) into the recordException call.https://opentelemetry.io/docs/languages/js/instrumentation/#recording-exceptions
Typing it as
any
in the catch block or explicitly casting it asError
in the recordException call both seem to work.Not sure if this is the right code but it seems like
recordException
is not making any assumptions about the input type anyways, so it seems safe to do these sorts of things.https://github.com/open-telemetry/opentelemetry-js/blob/84cce753617a1195138cab3254e1b22f80982150/packages/opentelemetry-sdk-trace-base/src/Span.ts#L317
The text was updated successfully, but these errors were encountered: