|
1 | 1 | /* eslint-disable max-lines */ // TODO: We might want to split this file up
|
2 | 2 | import { EventType, record } from '@sentry-internal/rrweb';
|
3 | 3 | import { captureException, getCurrentHub } from '@sentry/core';
|
4 |
| -import type { Breadcrumb, ReplayRecordingMode } from '@sentry/types'; |
| 4 | +import type { Breadcrumb, ReplayRecordingMode, Transaction } from '@sentry/types'; |
5 | 5 | import { logger } from '@sentry/utils';
|
6 | 6 |
|
7 | 7 | import {
|
@@ -68,6 +68,12 @@ export class ReplayContainer implements ReplayContainerInterface {
|
68 | 68 | */
|
69 | 69 | public recordingMode: ReplayRecordingMode = 'session';
|
70 | 70 |
|
| 71 | + /** |
| 72 | + * The current or last active transcation. |
| 73 | + * This is only available when performance is enabled. |
| 74 | + */ |
| 75 | + public lastTransaction?: Transaction; |
| 76 | + |
71 | 77 | /**
|
72 | 78 | * These are here so we can overwrite them in tests etc.
|
73 | 79 | * @hidden
|
@@ -614,6 +620,19 @@ export class ReplayContainer implements ReplayContainerInterface {
|
614 | 620 | return res;
|
615 | 621 | }
|
616 | 622 |
|
| 623 | + /** |
| 624 | + * This will get the parametrized route name of the current page. |
| 625 | + * This is only available if performance is enabled, and if an instrumented router is used. |
| 626 | + */ |
| 627 | + public getCurrentRoute(): string | undefined { |
| 628 | + const lastTransaction = this.lastTransaction || getCurrentHub().getScope().getTransaction(); |
| 629 | + if (!lastTransaction || !['route', 'custom'].includes(lastTransaction.metadata.source)) { |
| 630 | + return undefined; |
| 631 | + } |
| 632 | + |
| 633 | + return lastTransaction.name; |
| 634 | + } |
| 635 | + |
617 | 636 | /**
|
618 | 637 | * Initialize and start all listeners to varying events (DOM,
|
619 | 638 | * Performance Observer, Recording, Sentry SDK, etc)
|
|
0 commit comments