Skip to content

Recording Exceptions Example for Typescript Doesn't Work Out of the Box #5805

@Grunet

Description

@Grunet

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 as unknown 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 as Error 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions