Skip to content

[Typescript] Pass errors to loggers - #537

Open
Gabe Gorelick (gabegorelick) wants to merge 1 commit into
confluentinc:masterfrom
gabegorelick:error-logging
Open

[Typescript] Pass errors to loggers#537
Gabe Gorelick (gabegorelick) wants to merge 1 commit into
confluentinc:masterfrom
gabegorelick:error-logging

Conversation

@gabegorelick

Copy link
Copy Markdown

Pass error to loggers in the existing extras object. Currently, custom loggers do not get passed any underlying error.

Fixes #334

What

Pass error to loggers in the existing extras object. Currently, custom loggers do not get passed any underlying error. That makes it impossible for custom loggers to include things like error.code, error.cause, etc.

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?

References

#334

Test & Review

I have been running this patch in production.

Open questions / Follow-ups

Pass `error` to loggers in the existing `extras` object. Currently,
custom loggers do not get passed any underlying error.

Fixes confluentinc#334
Comment thread lib/kafkajs/_consumer.js
} catch (err) {
/* TODO: we should cry more about this and render the consumer unusable. */
this.#logger.error(`Seek error. This is effectively a fatal error: ${err.stack}`);
this.#logger.error('Seek error. This is effectively a fatal error',

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep err.stack in the message if we don't want to break consumers. But this library does not consistently include err.stack in log messages.

Comment thread lib/kafkajs/_consumer.js
if (!this.#connectionError)
this.#connectionError = err;
}
this.#logger.error(`Error: ${err.message}`, this.#createConsumerBindingMessageMetadata());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice how we didn't include err.stack here.

Comment thread lib/kafkajs/_consumer.js
this.#lastConsumedOffsets.set(key, m);
} catch (e) {
/* Not much we can do, except log the error. */
this.#logger.error(`Consumer encountered error while storing offset. Error details: ${JSON.stringify(e)}`, this.#createConsumerBindingMessageMetadata());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice how in this site, the error gets JSON stringified.

Passing the raw error to callers lets this lib be more consistent. The downstream loggers can decide how they want to serialize errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capturing the original error code using the Logger Callback

1 participant