|
20 | 20 | ## General |
21 | 21 |
|
22 | 22 | This package contains extensions to the `@sentry/hub` to enable Sentry AM related functionality. It also provides integrations for Browser and Node that provide a good experience out of the box. |
| 23 | + |
| 24 | +## Migrating from @sentry/apm to @sentry/tracing |
| 25 | + |
| 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. |
| 28 | + |
| 29 | +First, you must update your imports from the `Tracing` integration to the `BrowserTracing` integration. |
| 30 | + |
| 31 | +```ts |
| 32 | +import * as Sentry from "@sentry/browser"; |
| 33 | +import { Integrations } from "@sentry/tracing"; |
| 34 | + |
| 35 | +Sentry.init({ |
| 36 | + integrations: [ |
| 37 | + new Integrations.BrowserTracing({}), |
| 38 | + ] |
| 39 | +}) |
| 40 | +``` |
| 41 | + |
| 42 | +Next, if you were using the `beforeNavigate` option, the API has changed to this type: |
| 43 | + |
| 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; |
| 52 | +``` |
| 53 | + |
| 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. |
| 57 | + |
| 58 | +```ts |
| 59 | +import * as Sentry from "@sentry/browser"; |
| 60 | +import { Integrations } from "@sentry/tracing"; |
| 61 | + |
| 62 | +Sentry.init({ |
| 63 | + integrations: [ |
| 64 | + new Integrations.BrowserTracing({ |
| 65 | + beforeNavigate: (ctx) => { |
| 66 | + return { |
| 67 | + ...ctx, |
| 68 | + name: getTransactionName(ctx.name, window.location) |
| 69 | + } |
| 70 | + } |
| 71 | + }), |
| 72 | + ] |
| 73 | +}) |
| 74 | +``` |
0 commit comments