Skip to content

Commit ec75ea7

Browse files
authored
feat(apm): Deprecate @sentry/apm package (getsentry#2844)
1 parent ee25a51 commit ec75ea7

File tree

8 files changed

+132
-33
lines changed

8 files changed

+132
-33
lines changed

packages/apm/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919

2020
## General
2121

22+
This package is deprecated and will be removed in the next major release. We recommend switching to using the `@sentry/tracing` package for the time being.
23+
2224
This package contains extensions to the `@sentry/hub` to enable APM related functionality. It also provides integrations for Browser and Node that provide a good experience out of the box.

packages/apm/src/hubextensions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function traceHeaders(this: Hub): { [key: string]: string } {
2121

2222
/**
2323
* {@see Hub.startTransaction}
24+
* @deprecated Please use the @sentry/tracing package instead
2425
*/
2526
function startTransaction(this: Hub, context: TransactionContext): Transaction {
2627
const transaction = new Transaction(context, this);
@@ -91,6 +92,7 @@ export function addExtensionMethods(): void {
9192
if (carrier.__SENTRY__) {
9293
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};
9394
if (!carrier.__SENTRY__.extensions.startTransaction) {
95+
// eslint-disable-next-line deprecation/deprecation
9496
carrier.__SENTRY__.extensions.startTransaction = startTransaction;
9597
}
9698
if (!carrier.__SENTRY__.extensions.startSpan) {

packages/apm/src/index.bundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if (_window.Sentry && _window.Sentry.Integrations) {
6969
const INTEGRATIONS = {
7070
...windowIntegrations,
7171
...BrowserIntegrations,
72+
// eslint-disable-next-line deprecation/deprecation
7273
Tracing: ApmIntegrations.Tracing,
7374
};
7475

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { Express } from './express';
2+
// eslint-disable-next-line deprecation/deprecation
23
export { Tracing } from './tracing';

packages/apm/src/integrations/tracing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable deprecation/deprecation */
12
/* eslint-disable max-lines */
23
import { Hub } from '@sentry/hub';
34
import { Event, EventProcessor, Integration, Severity, Span, SpanContext, TransactionContext } from '@sentry/types';
@@ -133,6 +134,9 @@ const defaultTracingOrigins = ['localhost', /^\//];
133134

134135
/**
135136
* Tracing Integration
137+
*
138+
* @deprecated Please use the `BrowserTracing` integration from
139+
* the `@sentry/tracing` package.
136140
*/
137141
export class Tracing implements Integration {
138142
/**

packages/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19-
"@sentry/apm": "5.21.4",
2019
"@sentry/core": "5.21.4",
2120
"@sentry/hub": "5.21.4",
21+
"@sentry/tracing": "5.21.4",
2222
"@sentry/types": "5.21.4",
2323
"@sentry/utils": "5.21.4",
2424
"cookie": "^0.4.1",

packages/node/src/handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable max-lines */
22
/* eslint-disable @typescript-eslint/no-explicit-any */
3-
import { Span } from '@sentry/apm';
43
import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core';
4+
import { Span } from '@sentry/tracing';
55
import { Event } from '@sentry/types';
66
import { forget, isPlainObject, isString, logger, normalize } from '@sentry/utils';
77
import * as cookie from 'cookie';

packages/tracing/README.md

Lines changed: 120 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,141 @@ This package contains extensions to the `@sentry/hub` to enable Sentry AM relate
2323

2424
## Migrating from @sentry/apm to @sentry/tracing
2525

26-
The `@sentry/tracing` package is the replacement to the `@sentry/apm` package. No functionality has changed between
27-
the packages, but there are some steps required for upgrade.
26+
The tracing integration for JavaScript SDKs has moved from
27+
[`@sentry/apm`](https://www.npmjs.com/package/@sentry/apm) to
28+
[`@sentry/tracing`](https://www.npmjs.com/package/@sentry/tracing). While the
29+
two packages are similar, some imports and APIs have changed slightly.
2830

29-
First, you must update your imports from the `Tracing` integration to the `BrowserTracing` integration.
31+
The old package `@sentry/apm` is deprecated in favor of `@sentry/tracing`.
32+
Future support for `@sentry/apm` is limited to bug fixes only.
3033

31-
```ts
32-
import * as Sentry from "@sentry/browser";
33-
import { Integrations } from "@sentry/tracing";
34+
## Migrating from @sentry/apm to @sentry/tracing
3435

35-
Sentry.init({
36-
integrations: [
37-
new Integrations.BrowserTracing({}),
38-
]
39-
})
36+
### Browser (CDN bundle)
37+
38+
If you were using the Browser CDN bundle, switch from the old
39+
`bundle.apm.min.js` to the new tracing bundle:
40+
41+
```html
42+
<script
43+
src="https://browser.sentry-cdn.com/{{ packages.version('sentry.javascript.browser') }}/bundle.tracing.min.js"
44+
integrity="sha384-{{ packages.checksum('sentry.javascript.browser', 'bundle.tracing.min.js', 'sha384-base64') }}"
45+
crossorigin="anonymous"
46+
></script>
47+
```
48+
49+
And then update `Sentry.init`:
50+
51+
```diff
52+
Sentry.init({
53+
- integrations: [new Sentry.Integrations.Tracing()]
54+
+ integrations: [new Sentry.Integrations.BrowserTracing()]
55+
});
56+
```
57+
58+
### Browser (npm package)
59+
60+
If you were using automatic instrumentation, update the import statement and
61+
update `Sentry.init` to use the new `BrowserTracing` integration:
62+
63+
```diff
64+
import * as Sentry from "@sentry/browser";
65+
-import { Integrations } from "@sentry/apm";
66+
+import { Integrations } from "@sentry/tracing";
67+
68+
Sentry.init({
69+
integrations: [
70+
- new Integrations.Tracing(),
71+
+ new Integrations.BrowserTracing(),
72+
]
73+
});
4074
```
4175

42-
Next, if you were using the `beforeNavigate` option, the API has changed to this type:
76+
If you were using the `beforeNavigate` option from the `Tracing` integration,
77+
the API in `BrowserTracing` has changed slightly. Instead of passing in a
78+
location and returning a string representing transaction name, `beforeNavigate`
79+
now accepts a transaction context and is expected to return a transaction
80+
context. You can now add extra tags or change the `op` based on different
81+
parameters. If you want to access the location like before, you can get it from
82+
`window.location`.
83+
84+
For example, if you had a function like so that computed a custom transaction
85+
name:
86+
87+
```javascript
88+
import * as Sentry from "@sentry/browser";
89+
import { Integrations } from "@sentry/apm";
4390

44-
```ts
45-
/**
46-
* beforeNavigate is called before a pageload/navigation transaction is created and allows for users
47-
* to set a custom transaction context.
48-
*
49-
* If undefined is returned, a pageload/navigation transaction will not be created.
50-
*/
51-
beforeNavigate(context: TransactionContext): TransactionContext | undefined;
91+
Sentry.init({
92+
integrations: [
93+
new Integrations.Tracing({
94+
beforeNavigate: location => {
95+
return getTransactionName(location);
96+
},
97+
}),
98+
],
99+
});
52100
```
53101

54-
We removed the location argument, in favour of being able to see what the transaction context is on creation. You will
55-
have to access `window.location` yourself if you want to replicate that. In addition, if you return undefined in
56-
`beforeNavigate`, the transaction will not be created.
102+
You would now leverage the context to do the same thing:
57103

58-
```ts
104+
```javascript
59105
import * as Sentry from "@sentry/browser";
60106
import { Integrations } from "@sentry/tracing";
61107

62108
Sentry.init({
63109
integrations: [
64110
new Integrations.BrowserTracing({
65-
beforeNavigate: (ctx) => {
111+
beforeNavigate: context => {
66112
return {
67-
...ctx,
68-
name: getTransactionName(ctx.name, window.location)
69-
}
70-
}
113+
...context,
114+
// Can even look at context tags or other data to adjust
115+
// transaction name
116+
name: getTransactionName(window.location),
117+
};
118+
},
71119
}),
72-
]
73-
})
120+
],
121+
});
122+
```
123+
124+
For the full diff:
125+
126+
```diff
127+
import * as Sentry from "@sentry/browser";
128+
-import { Integrations } from "@sentry/apm";
129+
+import { Integrations } from "@sentry/tracing";
130+
131+
Sentry.init({
132+
integrations: [
133+
- new Integrations.Tracing({
134+
- beforeNavigate: (location) => {
135+
- return getTransactionName(location)
136+
+ new Integrations.BrowserTracing({
137+
+ beforeNavigate: (ctx) => {
138+
+ return {
139+
+ ...ctx,
140+
+ name: getTransactionName(ctx.name, window.location)
141+
+ }
142+
}
143+
}),
144+
]
145+
});
146+
```
147+
148+
### Node
149+
150+
If you were using the Express integration for automatic instrumentation, the
151+
only necessary change is to update the import statement:
152+
153+
```diff
154+
import * as Sentry from "@sentry/node";
155+
-import { Integrations } from "@sentry/apm";
156+
+import { Integrations } from "@sentry/tracing";
157+
158+
Sentry.init({
159+
integrations: [
160+
new Integrations.Express(),
161+
]
162+
});
74163
```

0 commit comments

Comments
 (0)