|
1 | 1 | import { expect, test } from '@playwright/test';
|
| 2 | +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/browser'; |
| 3 | +import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core/src'; |
2 | 4 | import { waitForTransaction } from '../event-proxy-server';
|
3 | 5 |
|
4 | 6 | test('sends a pageload transaction with a parameterized URL', async ({ page }) => {
|
@@ -126,3 +128,154 @@ test('groups redirects within one navigation root span', async ({ page }) => {
|
126 | 128 | expect(routingSpan).toBeDefined();
|
127 | 129 | expect(routingSpan?.description).toBe('/redirect1');
|
128 | 130 | });
|
| 131 | + |
| 132 | +test.describe('finish routing span', () => { |
| 133 | + test('finishes routing span on navigation cancel', async ({ page }) => { |
| 134 | + const navigationTxnPromise = waitForTransaction('angular-17', async transactionEvent => { |
| 135 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 136 | + }); |
| 137 | + |
| 138 | + await page.goto(`/`); |
| 139 | + |
| 140 | + // immediately navigate to a different route |
| 141 | + const [_, navigationTxn] = await Promise.all([page.locator('#cancelLink').click(), navigationTxnPromise]); |
| 142 | + |
| 143 | + expect(navigationTxn).toMatchObject({ |
| 144 | + contexts: { |
| 145 | + trace: { |
| 146 | + op: 'navigation', |
| 147 | + origin: 'auto.navigation.angular', |
| 148 | + }, |
| 149 | + }, |
| 150 | + transaction: '/cancel', |
| 151 | + transaction_info: { |
| 152 | + source: 'url', |
| 153 | + }, |
| 154 | + }); |
| 155 | + |
| 156 | + const routingSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.routing'); |
| 157 | + |
| 158 | + expect(routingSpan).toBeDefined(); |
| 159 | + expect(routingSpan?.description).toBe('/cancel'); |
| 160 | + }); |
| 161 | + |
| 162 | + test('finishes routing span on navigation error', async ({ page }) => { |
| 163 | + const navigationTxnPromise = waitForTransaction('angular-17', async transactionEvent => { |
| 164 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 165 | + }); |
| 166 | + |
| 167 | + await page.goto(`/`); |
| 168 | + |
| 169 | + // immediately navigate to a different route |
| 170 | + const [_, navigationTxn] = await Promise.all([page.locator('#nonExistentLink').click(), navigationTxnPromise]); |
| 171 | + |
| 172 | + expect(navigationTxn).toMatchObject({ |
| 173 | + contexts: { |
| 174 | + trace: { |
| 175 | + op: 'navigation', |
| 176 | + origin: 'auto.navigation.angular', |
| 177 | + }, |
| 178 | + }, |
| 179 | + transaction: '/non-existent', |
| 180 | + transaction_info: { |
| 181 | + source: 'url', |
| 182 | + }, |
| 183 | + }); |
| 184 | + |
| 185 | + const routingSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.routing'); |
| 186 | + |
| 187 | + expect(routingSpan).toBeDefined(); |
| 188 | + expect(routingSpan?.description).toBe('/nonExistentLink'); |
| 189 | + }); |
| 190 | +}); |
| 191 | + |
| 192 | +test.describe('TraceDirective', () => { |
| 193 | + test('creates a child tracingSpan with component name as span name on ngOnInit', async ({ page }) => { |
| 194 | + const navigationTxnPromise = waitForTransaction('angular-17', async transactionEvent => { |
| 195 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 196 | + }); |
| 197 | + |
| 198 | + await page.goto(`/`); |
| 199 | + |
| 200 | + // immediately navigate to a different route |
| 201 | + const [_, navigationTxn] = await Promise.all([page.locator('#componentTracking').click(), navigationTxnPromise]); |
| 202 | + |
| 203 | + const traceDirectiveSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.init'); |
| 204 | + |
| 205 | + expect(traceDirectiveSpan).toBeDefined(); |
| 206 | + expect(traceDirectiveSpan).toEqual( |
| 207 | + expect.objectContaining({ |
| 208 | + description: '<sample-component>', |
| 209 | + attributes: { |
| 210 | + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.init', |
| 211 | + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_directive', |
| 212 | + }, |
| 213 | + op: 'ui.angular.init', |
| 214 | + origin: 'auto.ui.angular.trace_directive', |
| 215 | + }), |
| 216 | + ); |
| 217 | + }); |
| 218 | + |
| 219 | + test('finishes tracingSpan after ngAfterViewInit', () => { |
| 220 | + // todo |
| 221 | + }); |
| 222 | +}); |
| 223 | + |
| 224 | +test.describe('TraceClassDecorator', () => { |
| 225 | + test('adds init span for decorated class', async ({ page }) => { |
| 226 | + const navigationTxnPromise = waitForTransaction('angular-17', async transactionEvent => { |
| 227 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 228 | + }); |
| 229 | + |
| 230 | + await page.goto(`/`); |
| 231 | + |
| 232 | + // immediately navigate to a different route |
| 233 | + const [_, navigationTxn] = await Promise.all([page.locator('#componentTracking').click(), navigationTxnPromise]); |
| 234 | + |
| 235 | + const initSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.init'); |
| 236 | + |
| 237 | + expect(initSpan).toBeDefined(); |
| 238 | + }); |
| 239 | +}); |
| 240 | + |
| 241 | +test.describe('TraceMethodDecorator', () => { |
| 242 | + test('instruments decorated methods (`ngOnInit` and `ngAfterViewInit`)', async ({ page }) => { |
| 243 | + const navigationTxnPromise = waitForTransaction('angular-17', async transactionEvent => { |
| 244 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 245 | + }); |
| 246 | + |
| 247 | + await page.goto(`/`); |
| 248 | + |
| 249 | + // immediately navigate to a different route |
| 250 | + const [_, navigationTxn] = await Promise.all([page.locator('#componentTracking').click(), navigationTxnPromise]); |
| 251 | + |
| 252 | + const ngInitSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.ngOnInit'); |
| 253 | + const ngAfterViewInitSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.ngAfterViewInit'); |
| 254 | + |
| 255 | + expect(ngInitSpan).toBeDefined(); |
| 256 | + expect(ngInitSpan).toEqual( |
| 257 | + expect.objectContaining({ |
| 258 | + description: '<ComponentTrackingComponent>', |
| 259 | + op: 'ui.angular.ngOnInit', |
| 260 | + attributes: { |
| 261 | + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.ngOnInit', |
| 262 | + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_class_decorator', |
| 263 | + }, |
| 264 | + }), |
| 265 | + ); |
| 266 | + |
| 267 | + expect(ngAfterViewInitSpan).toBeDefined(); |
| 268 | + expect(ngAfterViewInitSpan).toEqual( |
| 269 | + expect.objectContaining({ |
| 270 | + description: '<ComponentTrackingComponent>', |
| 271 | + op: 'ui.angular.ngAfterViewInit', |
| 272 | + attributes: { |
| 273 | + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.ngOnInit', |
| 274 | + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_method_decorator', |
| 275 | + }, |
| 276 | + startTimestamp: expect.any(Number), |
| 277 | + endTimestamp: expect.any(Number), |
| 278 | + }), |
| 279 | + ); |
| 280 | + }); |
| 281 | +}); |
0 commit comments