Skip to content

Commit 3dc88a6

Browse files
committed
delete deprecated browserTracingInstrumentation
1 parent 5ccc813 commit 3dc88a6

File tree

11 files changed

+285
-652
lines changed

11 files changed

+285
-652
lines changed

dev-packages/e2e-tests/test-applications/angular-17/src/app/app.routes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { Routes } from '@angular/router';
2+
import { cancelGuard } from './cancel-guard.guard';
3+
import { CancelComponent } from './cancel/cancel.components';
4+
import { ComponentTrackingComponent } from './component-tracking/component-tracking.components';
25
import { HomeComponent } from './home/home.component';
36
import { UserComponent } from './user/user.component';
47

@@ -11,6 +14,15 @@ export const routes: Routes = [
1114
path: 'home',
1215
component: HomeComponent,
1316
},
17+
{
18+
path: 'cancel',
19+
component: CancelComponent,
20+
canActivate: [cancelGuard],
21+
},
22+
{
23+
path: 'component-tracking',
24+
component: ComponentTrackingComponent,
25+
},
1426
{
1527
path: 'redirect1',
1628
redirectTo: '/redirect2',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ActivatedRouteSnapshot, CanActivateFn, RouterStateSnapshot } from '@angular/router';
2+
3+
export const cancelGuard: CanActivateFn = (_next: ActivatedRouteSnapshot, _state: RouterStateSnapshot) => {
4+
return false;
5+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-cancel',
5+
standalone: true,
6+
template: `<div></div>`,
7+
})
8+
export class CancelComponent {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { AfterViewInit, Component, OnInit } from '@angular/core';
2+
import { TraceClassDecorator, TraceMethodDecorator, TraceModule } from '@sentry/angular-ivy';
3+
import { SampleComponent } from '../sample-component/sample-component.components';
4+
5+
@Component({
6+
selector: 'app-cancel',
7+
standalone: true,
8+
imports: [TraceModule, SampleComponent],
9+
template: `<app-sample-component [trace]="'sample-component'"></app-sample-component>`,
10+
})
11+
@TraceClassDecorator()
12+
export class ComponentTrackingComponent implements OnInit, AfterViewInit {
13+
@TraceMethodDecorator()
14+
ngOnInit() {}
15+
16+
@TraceMethodDecorator()
17+
ngAfterViewInit() {}
18+
}

dev-packages/e2e-tests/test-applications/angular-17/src/app/home/home.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { RouterLink } from '@angular/router';
1111
<ul>
1212
<li> <a id="navLink" [routerLink]="['/users', '123']">Visit User 123</a> </li>
1313
<li> <a id="redirectLink" [routerLink]="['/redirect1']">Redirect</a> </li>
14+
<li> <a id="cancelLink" [routerLink]="['/cancel']">Cancel</a> </li>
15+
<li> <a id="nonExistentLink" [routerLink]="['/non-existent']">Error</a> </li>
16+
<li> <a id="componentTracking" [routerLink]="['/component-tracking']">Error</a> </li>
1417
</ul>
1518
<button id="errorBtn" (click)="throwError()">Throw error</button>
1619
</main>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-sample-component',
5+
standalone: true,
6+
template: `<div></div>`,
7+
})
8+
export class SampleComponent implements OnInit {
9+
ngOnInit() {
10+
console.log('SampleComponent');
11+
}
12+
}

dev-packages/e2e-tests/test-applications/angular-17/tests/performance.test.ts

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
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';
24
import { waitForTransaction } from '../event-proxy-server';
35

46
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 }) => {
126128
expect(routingSpan).toBeDefined();
127129
expect(routingSpan?.description).toBe('/redirect1');
128130
});
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+
});

packages/angular/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ export { createErrorHandler, SentryErrorHandler } from './errorhandler';
77
export {
88
// eslint-disable-next-line deprecation/deprecation
99
getActiveTransaction,
10-
// eslint-disable-next-line deprecation/deprecation
11-
instrumentAngularRouting, // new name
12-
// eslint-disable-next-line deprecation/deprecation
13-
routingInstrumentation, // legacy name
1410
browserTracingIntegration,
1511
TraceClassDecorator,
1612
TraceMethodDecorator,

0 commit comments

Comments
 (0)