Skip to content

Conversation

@jsumners-nr
Copy link
Contributor

This PR adds a tracing channel for the asJson function. APM tools can utilize this channel for their tracing needs. At New Relic, this is the only channel we need. Other vendors may like a bit more, so I'm tagging them here to get their input.

I'm opening this in draft mode while the feedback is collected. Once we have "yeah, this is good" from enough people, I will add documentation and convert the PR to ready.

attn: @AbhiPrasad @bengl @bizob2828 @timfish

Copy link

@timfish timfish left a comment

Choose a reason for hiding this comment

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

Great!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

+1

Can you add some docs and check the bechmarks?

@mcollina
Copy link
Member

@bengl might this help DataDog as well?

Copy link
Contributor

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

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

I can't see the entire function, is there a point where an error needs to be emitted?

@AbhiPrasad
Copy link

+1 from the Sentry side.

For reference, here's the existing OTEL instrumentation: https://www.npmjs.com/package/@opentelemetry/instrumentation-pino

@jsumners-nr
Copy link
Contributor Author

I published the PR and then went to lunch. As I was having lunch, I realized that subscribers should not need to utilize the exported channels. So I reworked the test in 52c6862 to only use the event names.

Question to the crowd: should Pino even export its internal channels?

@jsumners-nr
Copy link
Contributor Author

For reference, here's the existing OTEL instrumentation: npmjs.com/package/@opentelemetry/instrumentation-pino

@AbhiPrasad I am not very familiar with the OTEL instrumentation. Does this PR address what OTEL would need in order to utilize tracing channels instead of monkey patching Pino?

@jsumners-nr

This comment was marked as outdated.

@jsumners-nr jsumners-nr marked this pull request as ready for review September 10, 2025 16:33
@bengl
Copy link

bengl commented Sep 10, 2025

Our instrumentation in dd-trace-js (and yeah this is a RITM/IITM instrumentation, as we haven't converted this one to Orchestrion-JS yet) is a little different because rather than producing spans to cover logging, we only instrument loggers to enable injection, which allows correlation between our logs and traces products. Importantly, we need the ability to modify the logged JSON before it's stringified (or as part of the stringification) adding in the traceId and spanId that was active when the logger function was called.

lib/tools.js Outdated
}

function asJson (obj, msg, num, time) {
asJsonChan.start.publish({ instance: this, arguments })
Copy link

Choose a reason for hiding this comment

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

Could you add a test verifying that the "active span" (or just dummy object in AsyncLocalStorage) is exactly the same as when the logging function is called?

@jsumners-nr jsumners-nr marked this pull request as draft September 10, 2025 19:44
@jsumners-nr
Copy link
Contributor Author

Just had a call with @bengl on this. My current implementation is a bit flawed in understanding how tracing channel is meant to be used by libraries intending to support tracing channel. I need to refactor some things, so I have converted this back to draft.

@jsumners-nr
Copy link
Contributor Author

Basic benchmarks from my system are as follows:

Branch
BASIC benchmark averages
Bunyan average: 229.332ms
Winston average: 164.530ms
Bole average: 116.666ms
Debug average: 161.615ms
LogLevel average: 184.567ms
Pino average: 108.741ms
PinoMinLength average: 153.653ms
PinoNodeStream average: 120.895ms
==========
System: Darwin/darwin arm64 24.5.0 ~ Apple M1 Max (cores/threads: 10)
Main
BASIC benchmark averages
Bunyan average: 243.435ms
Winston average: 178.937ms
Bole average: 121.427ms
Debug average: 165.846ms
LogLevel average: 204.094ms
Pino average: 118.123ms
PinoMinLength average: 172.404ms
PinoNodeStream average: 148.096ms
==========
System: Darwin/darwin arm64 24.5.0 ~ Apple M1 Max (cores/threads: 10)

These results line up with the ones in our automated PR benchmarks. I find it strange that they are lower for the branch, but they are consistent in this. There should be a bit of a hit when there are subscribers attached, but our baseline seems unaffected.

@jsumners-nr jsumners-nr marked this pull request as ready for review September 12, 2025 13:23
@jsumners-nr jsumners-nr requested a review from bengl September 12, 2025 13:24
@jsumners-nr
Copy link
Contributor Author

Using traceSync directly results in the following benchmarks that are still inline with/better than the main branch:

BASIC benchmark averages
Bunyan average: 227.906ms
Winston average: 163.139ms
Bole average: 119.506ms
Debug average: 164.494ms
LogLevel average: 182.774ms
Pino average: 118.126ms
PinoMinLength average: 151.332ms
PinoNodeStream average: 118.453ms
==========
System: Darwin/darwin arm64 24.5.0 ~ Apple M1 Max (cores/threads: 10)

@jsumners-nr jsumners-nr requested review from Qard and bengl September 15, 2025 13:40
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@jsumners-nr jsumners-nr requested a review from Qard September 15, 2025 14:46
@jsumners jsumners merged commit 72df513 into pinojs:main Sep 15, 2025
21 of 22 checks passed
@jsumners-nr jsumners-nr deleted the tracing-channel branch September 15, 2025 16:38
@jsumners-nr
Copy link
Contributor Author

Awesome! We got it merged. Thank you for helping get this thing in the right state, everyone. It'll go out in Pino's next release.

alanplatt added a commit to DEFRA/grants-ui that referenced this pull request Nov 7, 2025
![snyk-top-banner](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)


<h3>Snyk has created this PR to upgrade pino from 9.9.5 to 9.11.0.</h3>

:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.

<hr/>


- The recommended version is **2 versions** ahead of your current
version.

- The recommended version was released **24 days ago**.




<details>
<summary><b>Release notes</b></summary>
<br/>
  <details>
    <summary>Package name: <b>pino</b></summary>
    <ul>
      <li>
<b>9.11.0</b> - <a
href="https://redirect.github.com/pinojs/pino/releases/tag/v9.11.0">2025-09-20</a></br><h2>What's
Changed</h2>
<ul>
<li>feat: added timestamp rfc3339 format with nanoseconds by <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/edge33/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/edge33">@ edge33</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3288586845" data-permission-text="Title is private"
data-url="pinojs/pino#2251"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2251/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2251">#2251</a></li>
<li>fix: gracefully handle missing diagChannel.tracingChannel on Node
&lt; 18.19 by <a class="user-mention notranslate"
data-hovercard-type="user"
data-hovercard-url="/users/aryamohanan/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/aryamohanan">@ aryamohanan</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3433786084" data-permission-text="Title is private"
data-url="pinojs/pino#2290"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2290/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2290">#2290</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/edge33/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/edge33">@ edge33</a> made their first
contribution in <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3288586845"
data-permission-text="Title is private"
data-url="pinojs/pino#2251"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2251/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2251">#2251</a></li>
<li><a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/aryamohanan/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/aryamohanan">@ aryamohanan</a> made
their first contribution in <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3433786084"
data-permission-text="Title is private"
data-url="pinojs/pino#2290"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2290/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2290">#2290</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a class="commit-link"
href="https://redirect.github.com/pinojs/pino/compare/v9.10.0...v9.11.0"><tt>v9.10.0...v9.11.0</tt></a></p>
      </li>
      <li>
<b>9.10.0</b> - <a
href="https://redirect.github.com/pinojs/pino/releases/tag/v9.10.0">2025-09-17</a></br><h2>What's
Changed</h2>
<ul>
<li>docs: Move pino-logflare out of legacy transports list by <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/kamilogorek/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/kamilogorek">@ kamilogorek</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3406229630" data-permission-text="Title is private"
data-url="pinojs/pino#2283"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2283/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2283">#2283</a></li>
<li>Add support for <code>Pear</code> and <code>Bare</code> runtimes by
<a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/yassernasc/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/yassernasc">@ yassernasc</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3388452783" data-permission-text="Title is private"
data-url="pinojs/pino#2278"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2278/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2278">#2278</a></li>
<li>Add tracing channels by <a class="user-mention notranslate"
data-hovercard-type="user"
data-hovercard-url="/users/jsumners-nr/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/jsumners-nr">@ jsumners-nr</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3402802217" data-permission-text="Title is private"
data-url="pinojs/pino#2281"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2281/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2281">#2281</a></li>
<li>Add pino-console to ecoystem page by <a class="user-mention
notranslate" data-hovercard-type="user"
data-hovercard-url="/users/mcollina/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/mcollina">@ mcollina</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3426535226" data-permission-text="Title is private"
data-url="pinojs/pino#2288"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2288/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2288">#2288</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/kamilogorek/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/kamilogorek">@ kamilogorek</a> made
their first contribution in <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3406229630"
data-permission-text="Title is private"
data-url="pinojs/pino#2283"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2283/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2283">#2283</a></li>
<li><a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/yassernasc/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/yassernasc">@ yassernasc</a> made
their first contribution in <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3388452783"
data-permission-text="Title is private"
data-url="pinojs/pino#2278"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2278/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2278">#2278</a></li>
<li><a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/jsumners-nr/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/jsumners-nr">@ jsumners-nr</a> made
their first contribution in <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3402802217"
data-permission-text="Title is private"
data-url="pinojs/pino#2281"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2281/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2281">#2281</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a class="commit-link"
href="https://redirect.github.com/pinojs/pino/compare/v9.9.5...v9.10.0"><tt>v9.9.5...v9.10.0</tt></a></p>
      </li>
      <li>
<b>9.9.5</b> - <a
href="https://redirect.github.com/pinojs/pino/releases/tag/v9.9.5">2025-09-10</a></br><h2>What's
Changed</h2>
<ul>
<li>fix: allow object type in %s placeholder by <a class="user-mention
notranslate" data-hovercard-type="user"
data-hovercard-url="/users/mcollina/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/mcollina">@ mcollina</a> in <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3388093159" data-permission-text="Title is private"
data-url="pinojs/pino#2277"
data-hovercard-type="pull_request"
data-hovercard-url="/pinojs/pino/pull/2277/hovercard"
href="https://redirect.github.com/pinojs/pino/pull/2277">#2277</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a class="commit-link"
href="https://redirect.github.com/pinojs/pino/compare/v9.9.4...v9.9.5"><tt>v9.9.4...v9.9.5</tt></a></p>
      </li>
    </ul>
from <a href="https://redirect.github.com/pinojs/pino/releases">pino
GitHub release notes</a>
  </details>
</details>

---

> [!IMPORTANT]
>
> - Check the changes in this PR to ensure they won't cause issues with
your project.
> - This PR was automatically created by Snyk using the credentials of a
real user.

---

**Note:** _You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs._

**For more information:** <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiJlMGNmZDdhOS0yNzM2LTQ3ZDUtOTY5Ny1iYWZjYzg0MDk5ZDgiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6ImUwY2ZkN2E5LTI3MzYtNDdkNS05Njk3LWJhZmNjODQwOTlkOCJ9fQ=="
width="0" height="0"/>

> - 🧐 [View latest project
report](https://app.snyk.io/org/bugbaredrums/project/cf9c5b42-a7d0-446f-a41c-275c56edf456?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 📜 [Customise PR
templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template)
> - 🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/bugbaredrums/project/cf9c5b42-a7d0-446f-a41c-275c56edf456/settings/integration?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/bugbaredrums/project/cf9c5b42-a7d0-446f-a41c-275c56edf456/settings/integration?pkg&#x3D;pino&amp;utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr#auto-dep-upgrades)

[//]: #
'snyk:metadata:{"breakingChangeRiskLevel":null,"FF_showPullRequestBreakingChanges":null,"FF_showPullRequestBreakingChangesWebSearch":null,"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"pino","from":"9.9.5","to":"9.11.0"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"e0cfd7a9-2736-47d5-9697-bafcc84099d8","prPublicId":"e0cfd7a9-2736-47d5-9697-bafcc84099d8","packageManager":"npm","priorityScoreList":[],"projectPublicId":"cf9c5b42-a7d0-446f-a41c-275c56edf456","projectUrl":"https://app.snyk.io/org/bugbaredrums/project/cf9c5b42-a7d0-446f-a41c-275c56edf456?utm_source=github&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":2,"publishedDate":"2025-09-20T13:03:07.987Z"},"vulns":[]}'
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.

8 participants