Skip to content

Commit 52cc527

Browse files
committed
delete deprecated browserTracingInstrumentation
1 parent 5ccc813 commit 52cc527

File tree

11 files changed

+275
-652
lines changed

11 files changed

+275
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { CanActivateFn } from '@angular/core';
2+
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
3+
4+
export const cancelGuard: CanActivateFn = (_next: ActivatedRouteSnapshot, _state: RouterStateSnapshot) => {
5+
return false;
6+
};
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: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, test } from '@playwright/test';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/browser';
23
import { waitForTransaction } from '../event-proxy-server';
34

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

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)