Skip to content

[sdk-trace] no type validation in places where it is common to pass caught Errors #4998

@pichlermarc

Description

@pichlermarc

What happened?

Description

When calling span.setStatus({ code: SpanStatusCode.ERROR, message: message}) it could be common to pass a caught Error as the message, like so:

try {
  myFunction(); // throws error
} catch (e) { // if typescript strict mode is NOT enabled, `e` is of type `any`
      span.setStatus({
        code: SpanStatusCode.ERROR,
        message: e, //  this expects a `string`, but receives `Error`, which TypeScript treats as `any`, so this does not cause a compile error.
      });
}

Expected Result

message is dropped as being not a string, a diag.warn is logged.

Actual Result

message which should be a string gets passed all though the SDK, to the exporter, and eventually gets JSON.stringifyd into an empty object, the OTel collector then rejects the whole trace export message with a 400 Bad Request.

Additional Details

This is happening in renovate bot where they catch an error and pass it directly as a message in setStatus: https://github.com/renovatebot/renovate/blob/5ca09edcbf454fc1b1ae9272ab240cd03d8d2e75/lib/instrumentation/index.ts#L145-L153

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpkg:sdk-trace-basepriority:p2Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions