* Updates the scope with provided data. Can work in three variations: * - plain object containing updatable attributes * - Scope instance that'll extract the attributes from * - callback function that'll receive the current scope as an argument and allow for modifications
(captureContext?: CaptureContext)
| 493 | * - callback function that'll receive the current scope as an argument and allow for modifications |
| 494 | */ |
| 495 | public update(captureContext?: CaptureContext): this { |
| 496 | if (!captureContext) { |
| 497 | return this; |
| 498 | } |
| 499 | |
| 500 | const scopeToMerge = typeof captureContext === 'function' ? captureContext(this) : captureContext; |
| 501 | |
| 502 | const scopeInstance = |
| 503 | scopeToMerge instanceof Scope |
| 504 | ? scopeToMerge.getScopeData() |
| 505 | : isPlainObject(scopeToMerge) |
| 506 | ? (captureContext as ScopeContext) |
| 507 | : undefined; |
| 508 | |
| 509 | const { |
| 510 | tags, |
| 511 | attributes, |
| 512 | extra, |
| 513 | user, |
| 514 | contexts, |
| 515 | level, |
| 516 | fingerprint = [], |
| 517 | propagationContext, |
| 518 | conversationId, |
| 519 | } = scopeInstance || {}; |
| 520 | |
| 521 | this._tags = { ...this._tags, ...tags }; |
| 522 | this._attributes = { ...this._attributes, ...attributes }; |
| 523 | this._extra = { ...this._extra, ...extra }; |
| 524 | this._contexts = { ...this._contexts, ...contexts }; |
| 525 | |
| 526 | if (user && Object.keys(user).length) { |
| 527 | this._user = user; |
| 528 | } |
| 529 | |
| 530 | if (level) { |
| 531 | this._level = level; |
| 532 | } |
| 533 | |
| 534 | if (fingerprint.length) { |
| 535 | this._fingerprint = fingerprint; |
| 536 | } |
| 537 | |
| 538 | if (propagationContext) { |
| 539 | this._propagationContext = propagationContext; |
| 540 | } |
| 541 | |
| 542 | if (conversationId) { |
| 543 | this._conversationId = conversationId; |
| 544 | } |
| 545 | |
| 546 | return this; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Clears the current scope and resets its properties. |
no test coverage detected