Add getBrowserAgentLoader() API and hasToRemoveLoaderScript option to getBrowserTimingHeader()#4061
Open
Andreyco wants to merge 1 commit into
Open
Add getBrowserAgentLoader() API and hasToRemoveLoaderScript option to getBrowserTimingHeader()#4061Andreyco wants to merge 1 commit into
Andreyco wants to merge 1 commit into
Conversation
79b161a to
97b20f7
Compare
Splits the browser monitoring output into two independently deliverable pieces: the static loader script (getBrowserAgentLoader) and the per-request config blob (getBrowserTimingHeader with hasToRemoveLoaderScript: true). This enables deployments where the loader is served through a caching proxy or CDN while only the lightweight config blob is injected per request — without losing APM-driven transaction correlation. Extracts shared <script> tag wrapping logic into _wrapScriptTag so both methods handle nonce and hasToRemoveScriptWrapper consistently.
97b20f7 to
34e9680
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
The existing
getBrowserTimingHeader()returns a single<script>block combining two conceptually distinct things:Bundling them together forces both to be delivered through the same path, which is either uncacheable (correct for config, wasteful for the loader) or cached (correct for the loader, incorrect for config).
What this changes
New method:
api.getBrowserAgentLoader(options)Returns only the static loader script, optionally wrapped in a
<script>tag (with nonce support). Because the loader never changes between requests, it can be served through a CDN or long-lived cache, or inlined once into a layout template.New option:
getBrowserTimingHeader({ hasToRemoveLoaderScript: true })Returns only the per-request
NREUMconfig block — no loader body. This is the piece that must be injected dynamically on each response (e.g. via a reverse proxy inserting it into , or a server-side template). Change is opt in and non breaking.Internal refactor:
_wrapScriptTag(content, options)The
<script>wrapping logic (plain / nonce / unwrapped) was duplicated between _generateRUMHeader and the new method. Extracted into a shared private helper.Why this matters
This split enables deployment patterns that weren't previously possible with a single APM-connected Node.js agent:
The existing getBrowserTimingHeader() behaviour is unchanged — callers that don't opt in to either new option get the same combined output as before.