Skip to content
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

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

Open
pichlermarc opened this issue Sep 18, 2024 · 0 comments · May be fixed by #4999
Open

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

pichlermarc opened this issue Sep 18, 2024 · 0 comments · May be fixed by #4999
Assignees
Labels
bug Something isn't working pkg:sdk-trace-base priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

Comments

@pichlermarc
Copy link
Member

pichlermarc commented Sep 18, 2024

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

@pichlermarc pichlermarc self-assigned this Sep 18, 2024
@pichlermarc pichlermarc added priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect and removed triage labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:sdk-trace-base priority:p2 Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect
Projects
None yet
1 participant