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 signals middleware #1220

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft

Add signals middleware #1220

wants to merge 25 commits into from

Conversation

silesky
Copy link
Contributor

@silesky silesky commented Jan 31, 2025

  • Allow registration of middleware to allow for dropping and modification of signals
  • Refactor to use middleware for network filter, rather than having that logic live in the network generator.
class MyMiddleware implements SignalsMiddleware {
 load(ctx: SignalsMiddlewareContext) {
   // this will block any signals from being emitted until resolved, like a segment 'before' plugin -- it will be invoked before processSignal
   // we can access ctx.unstableGlobalSettings from inside this plugin and assign it to the instance if needed
    return 
 }
  process(signal: Signal) {
    if (
      signal.type === 'network' &&
      signal.data.action === 'request' &&
      ...
    ) {
      // null = drop signal
      return null
    } else {
      return signal
    }
  }
}
const signalsPlugin = new SignalsPlugin({
  middleware: [new MyMiddleware()]
})

Copy link

changeset-bot bot commented Jan 31, 2025

🦋 Changeset detected

Latest commit: 90b27f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-signals Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 66.12903% with 21 lines in your changes missing coverage. Please review.

Project coverage is 83.52%. Comparing base (3e8d9d2) to head (90b27f6).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...e/network-signals-filter/network-signals-filter.ts 50.00% 8 Missing ⚠️
packages/signals/signals/src/core/emitter/index.ts 73.07% 7 Missing ⚠️
packages/signals/signals/src/lib/logger/index.ts 20.00% 4 Missing ⚠️
...ckages/signals/signals/src/core/signals/signals.ts 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1220      +/-   ##
==========================================
- Coverage   83.85%   83.52%   -0.33%     
==========================================
  Files         217      217              
  Lines        5798     5810      +12     
  Branches     1315     1324       +9     
==========================================
- Hits         4862     4853       -9     
- Misses        936      957      +21     
Flag Coverage Δ
browser 92.22% <ø> (ø)
core 89.86% <ø> (ø)
node 87.93% <ø> (ø)

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

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.

1 participant