Skip to content

chore: Refactored zlib instrumentation to be subscriber based - #4233

Draft
jsumners-nr wants to merge 1 commit into
newrelic:mainfrom
jsumners-nr:issue-4222
Draft

chore: Refactored zlib instrumentation to be subscriber based#4233
jsumners-nr wants to merge 1 commit into
newrelic:mainfrom
jsumners-nr:issue-4222

Conversation

@jsumners-nr

Copy link
Copy Markdown
Contributor

This PR resolves #4222.

@jsumners-nr jsumners-nr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At this time, I have not explored uncovered variations of the zlib API. I am opening the PR in its most basic state so that we can discuss the ideas in it before finalizing our approach. Once we do that, I will revisit updating API coverage.

Comment on lines +27 to +35
/**
* The underlying local storage object.
*
* @see https://nodejs.org/api/async_context.html#class-asynclocalstorage
* @returns {AsyncLocalStorage}
*/
get store() {
return this._asyncLocalStorage
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I get that accessing _ prefixed fields within our code base is acceptable and the actual intention of those fields. But I think, even within our own code base, it is better to expose things via public fields. It gives users confidence that they are doing the right thing instead of the anxiety induced by utilizing conventionally private fields.

Comment on lines +50 to +62
Object.defineProperties(Tracer.prototype, {
/**
* Retrieve the AsyncLocalStorage instance.
*
* @see https://nodejs.org/api/async_context.html#class-asynclocalstorage
* @returns {AsyncLocalStorage}
*/
asyncStore: {
get () {
return this._contextManager.store
}
}
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just bubbling up the underlying getter to the interface we typically access the storage object from.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if we really need this. This comes from the work I was experimenting with around @platformatic/kafka in October of 2025. My memory of that work is hazy at best. I think my idea was to give a base to inherit from that doesn't come with any implementation detail baggage, and then refactor the existing ones atop it (e.g. dc-base and db).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This also comes from my experimentation with @platformatic/kafka, but it has been tweaked to actually do stuff. This smaller task helped me narrow in on how these classes should work. In short:

  1. TracingChannelSubscription describes the event handlers an instrumentation will require. By defining only the event methods the instrumentation needs, we don't need to update something like this.events.
  2. TracingChannelSubscriber utilizes one, or many, instances of TracingChannelSubscription to register event listeners and manage segment life cycles.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ported the shimmer wrap methods to these simple utilities. It's likely that I missed some obscure detail of the shimmer implementation.

@jsumners-nr
jsumners-nr marked this pull request as ready for review August 18, 2026 19:26
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.20986% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.38%. Comparing base (56207ec) to head (52ac80a).

Files with missing lines Patch % Lines
lib/subscribers/wrap-method.js 78.57% 27 Missing ⚠️
lib/subscribers/subscriber.js 87.09% 16 Missing ⚠️
lib/subscribers/tracing-channel-subscriber.js 97.86% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4233      +/-   ##
==========================================
- Coverage   97.52%   97.38%   -0.14%     
==========================================
  Files         521      525       +4     
  Lines       62940    63543     +603     
  Branches        1        1              
==========================================
+ Hits        61380    61883     +503     
- Misses       1560     1660     +100     
Flag Coverage Δ
integration-tests-cjs-22.x 73.80% <92.20%> (+0.17%) ⬆️
integration-tests-cjs-24.x 74.38% <92.20%> (+0.17%) ⬆️
integration-tests-cjs-26.x 74.38% <92.20%> (+0.17%) ⬆️
integration-tests-esm-22.x 54.90% <86.64%> (+0.33%) ⬆️
integration-tests-esm-24.x 56.18% <86.64%> (+0.32%) ⬆️
integration-tests-esm-26.x 56.18% <86.64%> (+0.32%) ⬆️
unit-tests-22.x 89.14% <89.03%> (-0.01%) ⬇️
unit-tests-24.x 89.09% <89.03%> (-0.01%) ⬇️
unit-tests-26.x 89.09% <89.03%> (-0.01%) ⬇️
versioned-tests-22.x 97.38% <92.20%> (-0.14%) ⬇️
versioned-tests-24.x 97.38% <92.20%> (-0.14%) ⬇️
versioned-tests-26.x 97.38% <92.20%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jsumners-nr
jsumners-nr marked this pull request as draft August 19, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs PR Review

Development

Successfully merging this pull request may close these issues.

Migrate zlib to emit events over tracing channel

2 participants