Skip to content

refactor: gate SAP statistics hooks at registration, not per request - #568

Merged
sjvans merged 3 commits into
developfrom
refactor/sap-statistics-gate-at-registration
Oct 29, 2026
Merged

sjvans merged 3 commits into
developfrom
refactor/sap-statistics-gate-at-registration

Conversation

@sjvans

@sjvans sjvans commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

What

Hoists the isSapStatisticsEnabled() gate out of the per-request responseHook and up to instrumentation registration time in _getInstrumentations(). Also promotes the ./tracing/sap_statistics import from a lazy in-loop require to a module-level one.

Why

The sap_statistics config is static: _getConfig() reads cds.env.requires.telemetry?.tracing?.sap_statistics once and memoizes it, and cds.env doesn't change at runtime. So evaluating the gate once while building the instrumentations is equivalent to the former per-request check — registration already runs after env resolution (the same function reads cds.env.requires.telemetry.logging unconditionally).

Net effect:

  • Feature off (default): the responseHook wrappers are no longer installed at all — previously a wrapper ran on every HTTP client response just to call the gate and return.
  • Feature on: the per-request gate call is gone from the hot path; the hook does its real work directly.

No behavior change for users — the feature already couldn't be toggled after setup (memoized config), so taking the snapshot at registration rather than first request is not a regression. Pure internal cleanup of the beta feature added in #547, so no changelog entry.

Test plan

  • Existing sap_statistics tests pass (both http and undici paths, all modes)

The sap_statistics config is static (read once from cds.env and memoized),
so evaluating isSapStatisticsEnabled() once while building the
instrumentations is equivalent to the former per-request check. When the
feature is off (default) the responseHook wrappers are no longer installed
at all; when on, the per-request gate call is gone from the hot path.

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 PR Review — refactor: gate SAP statistics hooks at registration, not per request

✅ Looks good! No issues found.


PR Bot Information

Version: 1.33.17

  • Correlation ID: ed508ee0-d39a-11f1-87c9-caed7fe19ec3
  • Event Trigger: pull_request.ready_for_review
  • File Content Strategy: Full file content
  • Experiment Variant: treatment
  • LLM: gpt-5.6-sol

@sjvans
sjvans marked this pull request as ready for review October 29, 2026 13:16
@sjvans
sjvans requested a review from a team as a code owner October 29, 2026 13:16
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Gate SAP Statistics Hooks During Instrumentation Setup

Refactor

♻️ Move SAP statistics enablement checks from the per-request response path to instrumentation registration. Disabled configurations no longer install response hook wrappers, while enabled configurations avoid repeated gate checks without changing runtime behavior.

Changes

  • lib/index.js: Promoted the SAP statistics module import to module scope.
  • lib/index.js: Registers HTTP and undici response hooks only when SAP statistics are enabled.
  • lib/index.js: Preserves project-defined response hooks and undici header normalization while removing unnecessary per-request overhead.
  • No changelog entry is required because this is an internal optimization of the existing beta feature.

Test Plan

  • Verify existing SAP statistics tests pass for HTTP and undici across all supported modes.

Related Pull Request

  • #547: SAP performance statistics on HTTP client spans

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.33.17

@sjvans
sjvans merged commit 65adb17 into develop Oct 29, 2026
8 checks passed
@sjvans
sjvans deleted the refactor/sap-statistics-gate-at-registration branch October 29, 2026 13:16
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