Enhance Loki Transport URL Handling and Error Management #170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Improve the winston-loki library's robustness by implementing more comprehensive URL validation, error handling, and providing clearer error messages during Loki log transmission.
This pull request was created to solve the following GitHub issue:
Improve errors handling
Details
By the docs, the user needs to pass only
host
as anurl
option, so the exact URL is being built internally here:https://github.com/JaniAnttonen/winston-loki/blob/development/src/batcher.js#L42-L43
But if the user doesn't follow docs, or makes a typo, and passes not only a host but for example, a full URL, then internal implementation doesn't care about it and builds an invalid URL. Then, in the
req.post
, an invalid URL is being silently processed with no error, so in fact, no logs are being sent, and no error is being thrown. Here's the problem:https://github.com/JaniAnttonen/winston-loki/blob/development/src/batcher.js#L257-L272
Inside
then
, theresponse
argument should be handled, and if something bad happens, it should throw an error so thatcatch
can handle it correctly. For example, for an invalid URL theresponse
will have a text error saying404 URL not found
.Branch
No response
Improve Error Handling for Invalid URLs in Winston Loki Transport
Description:
Enhance error handling in the Batcher class to properly handle and report invalid URLs and HTTP response errors, particularly when users provide incorrect URL formats.
Tasks:
In
src/batcher.js
, update URL handling:host
parameter in constructorIn
src/batcher.js
, enhancesendBatchToLoki
method:Test:
In
test/batcher.json.test.js
, add tests:In
test/requests.test.js
, add tests:Additional Context:
The changes focus on the URL construction in the Batcher constructor and HTTP response handling in the
sendBatchToLoki
method to prevent silent failures when logs aren't being sent.Description
This pull request introduces several key improvements to the Loki transport mechanism:
URL Handling:
host
parameterError Management:
Request Handling:
Summary
src/batcher.js
src/requests.js
Fixes
Fixes #169. Continue the conversation here: https://app.sweep.dev/c/c690ad31-7eb2-46c6-8848-a73d0bf83ad9.
To have Sweep make further changes, please add a comment to this PR starting with "Sweep:".
📖 For more information on how to use Sweep, please read our documentation.