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

Add winston-newrelic-agent-transport to transport documentation #2382

Merged

Conversation

kimnetics
Copy link
Contributor

@kimnetics kimnetics commented Dec 21, 2023

Background

The New Relic agent typically automatically sends Winston logs to New Relic when using CommonJS. With CommonJS no additional transport should be needed. However, when using ECMAScript modules, the automatic sending of logs can with certain coding patterns not work.

The winston-newrelic-agent-transport transport was created to leverage the New Relic agent to send logs to New Relic for the times when automatic log sending is not working.

PR

This PR updates the transports documentation to include information about winston-newrelic-agent-transport.

Why create another New Relic transport?

The current Newrelic Transport only handles errors. Its use of newrelic.noticeError to transmit log messages constrains it to specific use cases. Also, the noticeError method was not intended for logging.

@DABH
Copy link
Contributor

DABH commented Jan 3, 2024

@kimnetics Do you feel that this transport subsumes all of the existing functionality in https://github.com/winstonjs/winston/blob/master/docs/transports.md#newrelic-transport ? That transport (https://github.com/namshi/newrelic-winston) hasn't been updated in 5 years, so I'm assuming it's not actively maintained, and I'd be fine just replacing that transport with this one -- if it's a strict superset of features. Let me know your thoughts!

@kimnetics
Copy link
Contributor Author

@DABH It is not a strict superset, but I do not believe it should be. In regards to general logging, my transport is a superset as the old transport only logs errors. The old transport does have some characteristics which are not brought forward into my transport. My rationale for not bringing them forward is explained below:

'dev' or 'test' exclusion from logging

The old transport has hardcoded logic to exclude 'dev' and 'test' environment from logging. That seems pretty opinionated for a logging transport. It could surprise people. My opinion is that a transport should just transport. That kind of logic is probably better left to the app's Winston logger code where any other special behavior configuration would likely be.

Personally, I want logging to happen in dev and test, so I do not want that logic in the first place.

Use of newrelic.noticeError

The old transport is using newrelic.noticeError to log. I believe this may be throwing off New Relic (NR) error counts, but there are rare cases where you would want to use it and with my transport you need to call it separately.

The purpose of that method is not to log but rather to let NR know that an error has occurred. This allows NR to properly class it as an error in the UI and counts. Normally errors are automatically noticed by NR so that method is typically only for times when you want something to be counted as an error, but for some reason don't want to throw an error. In other words, the method used by the old transport is for very special use cases. I believe I have only used it once in years of using NR.

My transport does not use newrelic.noticeError so in the special cases when you need to let NR know an error has occurred you need to call it separately from the logging statement. This matches to the NR API which separates logging from noticing an error. There is a reason they are separate. You sometimes don't want to both log an error and count an error.

I am concerned that the old transport may be producing potentially confusing output on the NR error page and counts. I believe both the NR automatically caught errors and the old transport newrelic.noticeError log messages are showing there. Users have to be careful when considering error counts as they may be doubled if the old transport is used to log errors already being caught by NR.

@kimnetics
Copy link
Contributor Author

One more thing about the newrelic.noticeError behavior.

Since the old transport is using newrelic.noticeError, its logging messages are showing on the Error page in the NR UI.

My transport has all logging messages showing on the Logs page in the NR UI.

@kimnetics
Copy link
Contributor Author

@DABH I do believe we should replace the existing newrelic-winston transport with this one. Its use of newrelic.noticeError to log is problematical. I was planning to make a video to show what I mean about the double of entry of error messages, when I found that the transport is based on a deprecated New Relic agent version.

Doing an npm install produces the following:

 ✘ npm install newrelic-winston
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '[email protected]',
npm WARN EBADENGINE   required: { node: '>=6.0.0 <13.0.0', npm: '>=3.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.18.2', npm: '9.8.1' }
npm WARN EBADENGINE }
npm WARN deprecated [email protected]: This version of the New Relic Node Agent has reached the end of life.

If you're agreeable, I could remove the old transport as part of this PR. Please let me know if I should add another commit that removes the old transport.

@DABH
Copy link
Contributor

DABH commented Feb 4, 2024

Gotcha. Yeah, I figured as much due to the lack of activity on that repo. I'm okay with adding yours and removing the other one (feel free to make another commit or PR for that). Thanks again for your contribution to the winston ecosystem!

@kimnetics kimnetics changed the title Add winston-newrelic-agent-transport to transport documentation. Add winston-newrelic-agent-transport to transport documentation Feb 4, 2024
@kimnetics
Copy link
Contributor Author

@DABH As I thought about it, a separate PR to remove newrelic-winston was cleaner than using a another commit on this PR. I created a separate PR to handle the removal: #2405.

@DABH DABH merged commit cc731ef into winstonjs:master Feb 4, 2024
4 checks passed
@kimnetics kimnetics deleted the add-winston-newrelic-agent-transport branch February 4, 2024 17:28
Vylpes pushed a commit to Vylpes/card-drop that referenced this pull request Apr 23, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [winston](https://github.com/winstonjs/winston) | dependencies | minor | [`3.11.0` -> `3.13.0`](https://renovatebot.com/diffs/npm/winston/3.11.0/3.13.0) |

---

### Release Notes

<details>
<summary>winstonjs/winston (winston)</summary>

### [`v3.13.0`](https://github.com/winstonjs/winston/releases/tag/v3.13.0)

[Compare Source](winstonjs/winston@v3.12.1...v3.13.0)

-   fix(http): allow passing maximumDepth to prevent big object being stringified ([#&#8203;2425](winstonjs/winston#2425))  [`a237865`](winstonjs/winston@a237865)

### [`v3.12.1`](https://github.com/winstonjs/winston/releases/tag/v3.12.1)

[Compare Source](winstonjs/winston@v3.12.0...v3.12.1)

-   Bump [@&#8203;types/node](https://github.com/types/node) from 20.11.24 to 20.11.29 ([#&#8203;2431](winstonjs/winston#2431))  [`b10b98f`](winstonjs/winston@b10b98f)
-   Revert "Remove nonexistent Logger methods from types" ([#&#8203;2434](winstonjs/winston#2434))  [`0277035`](winstonjs/winston@0277035)
-   fixed flaky test case ([#&#8203;2412](winstonjs/winston#2412))  [`d95c948`](winstonjs/winston@d95c948)

### [`v3.12.0`](https://github.com/winstonjs/winston/releases/tag/v3.12.0)

[Compare Source](winstonjs/winston@v3.11.0...v3.12.0)

-   missing timestamp format in ready-to-use-pattern example ([#&#8203;2421](winstonjs/winston#2421))  [`9e5b407`](winstonjs/winston@9e5b407)
-   bump deps ([#&#8203;2422](winstonjs/winston#2422))  [`4a85e6b`](winstonjs/winston@4a85e6b)
-   \[chore] Run coveralls CI check on Node 20 not 16 ([#&#8203;2418](winstonjs/winston#2418))  [`e153c68`](winstonjs/winston@e153c68)
-   Bump [@&#8203;types/node](https://github.com/types/node) from 20.8.6 to 20.11.19 ([#&#8203;2413](winstonjs/winston#2413))  [`587f40f`](winstonjs/winston@587f40f)
-   Update README.md ([#&#8203;2417](winstonjs/winston#2417))  [`8e99a00`](winstonjs/winston@8e99a00)
-   docs: fix anchor in transports docs ([#&#8203;2416](winstonjs/winston#2416))  [`0bde36b`](winstonjs/winston@0bde36b)
-   add winston-transport-vscode to transports docs ([#&#8203;2411](winstonjs/winston#2411))  [`8fb5b41`](winstonjs/winston@8fb5b41)
-   Bump [@&#8203;babel/cli](https://github.com/babel/cli) from 7.23.0 to 7.23.9 ([#&#8203;2406](winstonjs/winston#2406))  [`a326743`](winstonjs/winston@a326743)
-   Add winston-newrelic-agent-transport to transport documentation ([#&#8203;2382](winstonjs/winston#2382))  [`cc731ef`](winstonjs/winston@cc731ef)
-   Remove newrelic-winston transport entry. ([#&#8203;2405](winstonjs/winston#2405))  [`f077f30`](winstonjs/winston@f077f30)
-   Bump eslint from 8.55.0 to 8.56.0 ([#&#8203;2397](winstonjs/winston#2397))  [`3943c41`](winstonjs/winston@3943c41)
-   Bump the npm_and_yarn group group with 1 update ([#&#8203;2391](winstonjs/winston#2391))  [`8260866`](winstonjs/winston@8260866)
-   Fix unhandled rejection handling ([#&#8203;2390](winstonjs/winston#2390))  [`333b763`](winstonjs/winston@333b763)
-   Fix all rimraf usages to the best of my ability; glob is not true by default in rimraf; file archive test only passed every other time using async rimraf, could use further investigation  [`c3f3b5b`](winstonjs/winston@c3f3b5b)
-   Fix rimraf usage in new test  [`8f3c653`](winstonjs/winston@8f3c653)
-   Fix rimraf import in test (why didn't this break in PR CI?)  [`f3836aa`](winstonjs/winston@f3836aa)
-   Added functionality to long broken zippedArchive option ([#&#8203;2337](winstonjs/winston#2337))  [`02d4267`](winstonjs/winston@02d4267)
-   Bump async from 3.2.4 to 3.2.5 ([#&#8203;2378](winstonjs/winston#2378))  [`069a40d`](winstonjs/winston@069a40d)
-   Bump [@&#8203;babel/preset-env](https://github.com/babel/preset-env) from 7.23.2 to 7.23.7 ([#&#8203;2384](winstonjs/winston#2384))  [`79282e1`](winstonjs/winston@79282e1)
-   Bump winston-transport; fix test issue ([#&#8203;2386](winstonjs/winston#2386))  [`05788b9`](winstonjs/winston@05788b9)
-   Bump eslint from 8.51.0 to 8.55.0 ([#&#8203;2375](winstonjs/winston#2375))  [`a7c2eec`](winstonjs/winston@a7c2eec)
-   Bump std-mocks from 1.0.1 to 2.0.0 ([#&#8203;2361](winstonjs/winston#2361))  [`85c336e`](winstonjs/winston@85c336e)
-   Bump actions/setup-node from 3 to 4 ([#&#8203;2362](winstonjs/winston#2362))  [`448d11c`](winstonjs/winston@448d11c)
-   chore(README.md): adds documentation around coloring json formatted logs  [`91ec069`](winstonjs/winston@91ec069)
-   Remove nonexistent Logger methods from types  [`c3c3911`](winstonjs/winston@c3c3911)
-   Update dependencies  [`caf2df6`](winstonjs/winston@caf2df6)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/212
Reviewed-by: Vylpes <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
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.

2 participants