Skip to content

Commit

Permalink
Revert JSON stringfy for error in OTEL transport
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofzuraw committed Sep 24, 2024
1 parent 93969b2 commit 5f954ed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 0 additions & 5 deletions .changeset/thick-poets-invite.md

This file was deleted.

7 changes: 0 additions & 7 deletions packages/logger/.eslintrc

This file was deleted.

8 changes: 8 additions & 0 deletions packages/logger/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
root: true,
extends: ["saleor"],
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
},
};
10 changes: 9 additions & 1 deletion packages/logger/src/logger-otel-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ export const attachLoggerOtelTransport = (
* Try to serialize Error. Modern-errors has plugin to serialize
* https://github.com/ehmicky/modern-errors-serialize
*
* It add "serialize" method that converts class to plain object, working for OTEL.
*
* This is not perfect, doesn't work for nested object. We probably need to introduce some abstraction
* on logger error?
*/
try {
serializedAttributes.error = JSON.stringify(serializedAttributes.error);
const errorAttribute = serializedAttributes.error;
const ErrorConstructor = errorAttribute["constructor"];

// @ts-expect-error - ErrorConstructor is a class that could have serialize method. If not, safely throw and ignore
serializedAttributes.error = ErrorConstructor.serialize(serializedAttributes.error);
// @ts-expect-error - Additional mapping for Datadog
serializedAttributes.error.type = serializedAttributes.error.name;
} catch (e) {}
Expand Down

0 comments on commit 5f954ed

Please sign in to comment.