Skip to content

docs(replay): Update README.md for lazy integrations #7704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/gitflow-sync-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@ jobs:
# This token is scoped to Daniel Griesser
github_token: ${{ secrets.REPO_SCOPED_TOKEN }}

# https://github.com/marketplace/actions/enable-pull-request-automerge
- name: Enable automerge for PR
if: steps.open-pr.outputs.pr_number != ''
uses: peter-evans/enable-pull-request-automerge@v2
with:
pull-request-number: ${{ steps.open-pr.outputs.pr_number }}
merge-method: merge
run: gh pr merge --merge --auto "1"

# https://github.com/marketplace/actions/auto-approve
- name: Auto approve PR
Expand Down
22 changes: 16 additions & 6 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,24 @@ export function TraceMethodDecorator(): MethodDecorator {
* child route with its parent to produce the complete parameterized URL of the activated route.
* This happens recursively until the last child (i.e. the end of the URL) is reached.
*
* @param route the ActivatedRouteSnapshot of which its path and its child's path is concantenated
* @param route the ActivatedRouteSnapshot of which its path and its child's path is concatenated
*
* @returns the concatenated parameterzited route string
* @returns the concatenated parameterized route string
*/
export function getParameterizedRouteFromSnapshot(route?: ActivatedRouteSnapshot | null): string {
const path = route && route.firstChild && route.firstChild.routeConfig && route.firstChild.routeConfig.path;
if (!path) {
return '/';
const parts: string[] = [];

let currentRoute = route && route.firstChild;
while (currentRoute) {
const path = currentRoute && currentRoute.routeConfig && currentRoute.routeConfig.path;
if (path === null || path === undefined) {
break;
}

parts.push(path);
currentRoute = currentRoute.firstChild;
}
return `/${path}${getParameterizedRouteFromSnapshot(route && route.firstChild)}`;

const fullPath = parts.filter(part => part).join('/');
return fullPath ? `/${fullPath}/` : '/';
}
26 changes: 25 additions & 1 deletion packages/angular/test/tracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ describe('Angular Tracing', () => {

describe('getParameterizedRouteFromSnapshot', () => {
it.each([
['returns `/` empty object if the route no children', {}, '/'],
['returns `/` if the route has no children', {}, '/'],
[
'returns `/` if the route has an empty child',
{
firstChild: { routeConfig: { path: '' } },
},
'/',
],
[
'returns the route of a snapshot without children',
{
Expand All @@ -76,6 +83,21 @@ describe('Angular Tracing', () => {
},
'/orgs/:orgId/projects/:projId/overview/',
],
[
'returns the route of a snapshot without children but with empty paths',
{
firstChild: {
routeConfig: { path: 'users' },
firstChild: {
routeConfig: { path: '' },
firstChild: {
routeConfig: { path: ':id' },
},
},
},
},
'/users/:id/',
],
])('%s', (_, routeSnapshot, expectedParams) => {
expect(getParameterizedRouteFromSnapshot(routeSnapshot as unknown as ActivatedRouteSnapshot)).toEqual(
expectedParams,
Expand Down Expand Up @@ -345,6 +367,7 @@ describe('Angular Tracing', () => {
public ngOnInit() {
origNgOnInitMock();
}

public ngAfterViewInit() {
origNgAfterViewInitMock();
}
Expand Down Expand Up @@ -398,6 +421,7 @@ describe('Angular Tracing', () => {
public ngOnInit() {
origNgOnInitMock();
}

@TraceMethodDecorator()
public ngAfterViewInit() {
origNgAfterViewInitMock();
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
},
"volta": {
"extends": "../../package.json"
}
},
"sideEffects": false
}
20 changes: 16 additions & 4 deletions packages/replay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ If you do not want to start Replay immediately (e.g. if you want to lazy-load it
you can also use `addIntegration` to load it later:

```js
import * as Sentry from "@sentry/react";
import { BrowserClient } from "@sentry/browser";

Sentry.init({
// Do not load it initially
integrations: []
});

// Sometime later
const { Replay } = await import('@sentry/browser');
getCurrentHub().getClient().addIntegration(new Replay());
const client = Sentry.getCurrentHub().getClient<BrowserClient>();

// Client can be undefined
client?.addIntegration(new Replay());
```

### Identifying Users
Expand All @@ -76,6 +82,7 @@ If you have only followed the above instructions to setup session replays, you w

```javascript
import * as Sentry from "@sentry/browser";

Sentry.setUser({ email: "[email protected]" });
```

Expand All @@ -84,17 +91,22 @@ Sentry.setUser({ email: "[email protected]" });
Replay recording only starts when it is included in the `integrations` array when calling `Sentry.init` or calling `addIntegration` from the a Sentry client instance. To stop recording you can call the `stop()`.

```js
import * as Sentry from "@sentry/react";
import { BrowserClient } from "@sentry/browser";

const replay = new Replay();

Sentry.init({
integrations: [replay]
});

const client = getClient();
const client = Sentry.getCurrentHub().getClient<BrowserClient>();

// Add replay integration, will start recoring
client.addIntegration(replay);
client?.addIntegration(replay);

replay.stop(); // Stop recording
// Stop recording
replay.stop();
```

## Loading Replay as a CDN Bundle
Expand Down