Skip to content
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

Typescript: ReplayCanvas integration type doesn't have "snapshot" method #11971

Closed
3 tasks done
pahuta opened this issue May 10, 2024 · 1 comment · Fixed by #11995
Closed
3 tasks done

Typescript: ReplayCanvas integration type doesn't have "snapshot" method #11971

pahuta opened this issue May 10, 2024 · 1 comment · Fixed by #11995

Comments

@pahuta
Copy link

pahuta commented May 10, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

7.114.0

Framework Version

7.114.0

Link to Sentry event

No response

SDK Setup

Sentry.init({
    dsn: config.SENTRY_DSN as string,
    integrations: [
      Sentry.browserTracingIntegration(),
      Sentry.replayIntegration({
        minReplayDuration: 1000,
        networkDetailAllowUrls: [
          config.API_URL as string,
        ],
        networkCaptureBodies: true,
        maskAllText: false,
        maskAllInputs: false,
        blockAllMedia: false,
      }),
      // The following is all you need to enable canvas recording with Replay
      Sentry.replayCanvasIntegration({
        enableManualSnapshot: true,
      }),
    ],
    // adjust in case of too many samples
    tracesSampleRate: 0.2,

    // This sets the sample rate to be 0%. You may want this to be 100% while
    // in development and sample at a lower rate in production
    replaysSessionSampleRate: 0,

    // If the entire session is not sampled, use the below sample rate to sample
    // sessions when an error occurs.
    replaysOnErrorSampleRate: 1.0,
  });

Steps to Reproduce

I use modified code snippet from documentation, step 2:

export const sendCanvasSnapshotToSentry = (canvasEl: HTMLCanvasElement) => {
  const sentryClient = Sentry.getClient();

  if (!sentryClient) {
    return;
  }

  const replayCanvasIntegration = sentryClient.getIntegrationByName('ReplayCanvas');

  if (!replayCanvasIntegration) {
    return;
  }

  replayCanvasIntegration.snapshot(canvasEl); // replayCanvasIntegration has interface "Integration"
};
Screenshot 2024-05-10 at 11 40 53

typescript@5.3.3

Expected Result

Sentry provides interface like ReplayCanvasIntegration which extends interface Integration and defines methods of integrations (I guess the same as _replayCanvasIntegration from @sentry-internal/replay-canvas/types/canvas.d.ts). Then I'll be able to use it as a generic type like:

      const replayCanvasIntegration = sentryClient.getIntegrationByName<ReplayCanvasIntegration>('ReplayCanvas');

Actual Result

Method snapshot is not defined in replay canvas integration, can't use it in a type safe way.

@mydea
Copy link
Member

mydea commented May 13, 2024

Hey,

thank you for bringing this up! This is indeed not properly exported, I will adjust this so this has the snapshot method correctly.

The way this will work in v8 is:

import { getClient, replayCanvasIntegration } from '@sentry/browser';

const canvas = getClient()?.getIntegrationByName<ReturnType<typeof replayCanvasIntegration>>('ReplayCanvas');
canvas.snapshot();

I'll keep you posted in this issue when this is released!

mydea added a commit that referenced this issue May 13, 2024
`snapshot` is a public API.

I think the other methods we do not need to expose (?).

With this, usage will be:

```ts
const canvas = getClient()?.getIntegrationByName<ReturnType<typeof replayCanvasIntegration>>('ReplayCanvas');
await canvas.snapshot();
```

Closes #11971
andreiborza pushed a commit that referenced this issue May 16, 2024
`snapshot` is a public API.

I think the other methods we do not need to expose (?).

With this, usage will be:

```ts
const canvas = getClient()?.getIntegrationByName<ReturnType<typeof replayCanvasIntegration>>('ReplayCanvas');
await canvas.snapshot();
```

Closes #11971
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants