sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Ensure. `Sentry.captureUserFeedback(feedback)` is exported from node packages

Open alexavil opened this issue 1 year ago • 6 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.106.1

Framework Version

No response

Link to Sentry event

No response

SDK Setup

  Sentry.init({
    dsn: "https://d7c06763ec24990c168e4ad0db91e360@o4504711913340928.ingest.sentry.io/4505981661151232",
    tracesSampleRate: 1.0,
    profilesSampleRate: 1.0,
    integrations: [
      new Sentry.Integrations.Http({ tracing: true }),
      new nodeProfilingIntegration(),
    ],
    environment: debug ? "testing" : "production",
    release: "3.0",
  });

Steps to Reproduce

I copied the following example from the Node.js documentation page for User Feedback:

import * as Sentry from "@sentry/node";

const eventId = Sentry.captureMessage("User Feedback");
// OR: const eventId = Sentry.lastEventId();

const userFeedback = {
  event_id: eventId,
  name: "John Doe",
  email: "[email protected]",
  comments: "I really like your App, thanks!",
};
Sentry.captureUserFeedback(userFeedback);

Expected Result

User Feedback should be captured properly.

Actual Result

TypeError: Sentry.captureUserFeedback is not a function

Looks like this function is missing from the @sentry/node package, but the documentation says Node.js is supported.

alexavil avatar Mar 13 '24 08:03 alexavil

Hey,

yes you are right, this is not exported right now from node - sorry about the confusion! We'll add an export for this in an upcoming release - we are generally overhauling user feedback right now, so while working on this I'll try to make sure to export it everywhere we need it!

mydea avatar Mar 13 '24 09:03 mydea

@mydea Thanks, any workaround until the new release?

alexavil avatar Mar 13 '24 12:03 alexavil

@mydea Thanks, any workaround until the new release?

Sadly, not really, as this currently only lives in the browser package. We probably should "fix" the docs until we have a better solution for this 😬

mydea avatar Mar 13 '24 12:03 mydea

Hey @mydea, I see that captureFeedback is now exported from @sentry/node in version 8.4.0.

But seems it doesn't work with multiple sentry instances setup. My setup:

const sentryClient = new NodeClient({ /* ... */ });
const sentryScope = new Scope();

sentryScope.setClient(sentryClient);
sentryClient.init();

sentryClient.captureFeedback() isn't available and I need to do something like this:

import { NodeClient, Scope, captureFeedback } from '@sentry/node';

const sentryClient = new NodeClient({ /* ... */ });
const sentryScope = new Scope();

sentryScope.setClient(sentryClient);
sentryClient.init();

captureFeedback({ message: 'test' });

But captureFeedback doesn't work. Probably because it relies on getCurrentScope() which doen't work with multiple sentry instances setup. https://github.com/getsentry/sentry-javascript/blob/805c577b71d2f5b7299746e12250223681eaa71f/packages/core/src/feedback.ts#L35

Is it possible to add captureFeedback to BaseClient?

fantua avatar May 24 '24 11:05 fantua

Hey, I can see that. We don't want to add this to the client for bundle size reasons, but I'll make a PR to allow to pass a client to captureFeedback so you can still do this yourself!

mydea avatar May 24 '24 13:05 mydea

That should work! Thank you

fantua avatar May 24 '24 15:05 fantua

Closing because captureUserFeedback is deprecated. Feel free to ping us here if there are any things left to solve!

lforst avatar Nov 20 '24 15:11 lforst