Module: Alplus::ScopeMerge
- Defined in:
- lib/alplus/scope.rb
Overview
Merges an ambient Scope#snapshot with per-capture overrides. Mirrors
packages/sdk/src/core/observe/scope.ts's mergeScope: an explicit
per-call user: wins outright over the ambient one; tags/contexts
shallow-merge with the override's keys winning on collision;
breadcrumbs concatenate (ambient trail first, then any one-off
breadcrumbs passed for this one call).
user: distinguishes "not given" from "explicitly nil" via the
Alplus::UNSET sentinel default, mirroring the JS SDK's
overrides.user !== undefined check: Client passes Alplus::UNSET
through when its own user: param wasn't given by the caller, so a
caller CAN pass user: nil to clear the ambient user for one capture
rather than always falling back to it.
Class Method Summary collapse
Class Method Details
.merge(ambient:, user:, tags:, contexts:, breadcrumbs:) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/alplus/scope.rb', line 95 def merge(ambient:, user:, tags:, contexts:, breadcrumbs:) { user: user.equal?(Alplus::UNSET) ? ambient[:user] : user, tags: ambient[:tags].merge( || {}), contexts: ambient[:contexts].merge(contexts || {}), breadcrumbs: ambient[:breadcrumbs] + ( || []) } end |