* Adds a breadcrumb to the scope. * By default, the last 100 breadcrumbs are kept.
(breadcrumb: Breadcrumb, maxBreadcrumbs?: number)
| 579 | * By default, the last 100 breadcrumbs are kept. |
| 580 | */ |
| 581 | public addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): this { |
| 582 | const maxCrumbs = typeof maxBreadcrumbs === 'number' ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS; |
| 583 | |
| 584 | // No data has been changed, so don't notify scope listeners |
| 585 | if (maxCrumbs <= 0) { |
| 586 | return this; |
| 587 | } |
| 588 | |
| 589 | const mergedBreadcrumb: Breadcrumb = { |
| 590 | timestamp: dateTimestampInSeconds(), |
| 591 | ...breadcrumb, |
| 592 | // Breadcrumb messages can theoretically be infinitely large and they're held in memory so we truncate them not to leak (too much) memory |
| 593 | message: breadcrumb.message ? truncate(breadcrumb.message, 2048) : breadcrumb.message, |
| 594 | }; |
| 595 | |
| 596 | this._breadcrumbs.push(mergedBreadcrumb); |
| 597 | if (this._breadcrumbs.length > maxCrumbs) { |
| 598 | this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs); |
| 599 | this._client?.recordDroppedEvent('buffer_overflow', 'log_item'); |
| 600 | } |
| 601 | |
| 602 | this._notifyScopeListeners(); |
| 603 | |
| 604 | return this; |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Get the last breadcrumb of the scope. |
no test coverage detected