Giter Site home page Giter Site logo

Comments (3)

mydea avatar mydea commented on May 10, 2024

Hello,

so just to clarify, what you are doing is: You have a library, that other users (or teams) embed in their applications. These applications have dedicated Sentry SDK setups (e.g. each has it's own init) and each app runs separately from each other. And you'd like to capture errors from the library to the host-apps Sentry.

Did I get that correctly?

If this is the case, what you should do is depend on @sentry/core and do this:

import { captureException } from '@sentry/core';

captureException(...);

This should capture to the host app. However, please bear in mind that in order for this to work, it is essential that the version of Sentry SDKs are fully aligned - e.g. if the host app uses @sentry/[email protected], the library must also use @sentry/[email protected]. Otherwise, if the versions mismatch, you may not capture stuff correctly.

from sentry-javascript.

Zandor300 avatar Zandor300 commented on May 10, 2024

@mydea Thanks! Alternative would be to init a Sentry instance for the library itself? But that would mean you have the Sentry SDK for the application running and another for the library. Then you wouldn’t have issues with version mismatches?

Will calls to captureException go to the SDK instance of the library when called from the library? Or do you need to reference the SDK instance of the library specifically to achieve that?

What would be the best approach with the least possibility of issues?

from sentry-javascript.

AbhiPrasad avatar AbhiPrasad commented on May 10, 2024

Alternative would be to init a Sentry instance for the library itself? But that would mean you have the Sentry SDK for the application running and another for the library. Then you wouldn’t have issues with version mismatches?

Yes there would be, so we recommend that the library instance does not do any global patching. We have docs around browser extensions which is basically the same scenario as this: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/

Will calls to captureException go to the SDK instance of the library when called from the library? Or do you need to reference the SDK instance of the library specifically to achieve that?

A global Sentry.captureException call will go to the currently active client, which usually is the host that wraps the library. Hence we recommend directly using a client and capturing exceptions as needed in the library.

Please note that diverging versions of an SDK will add to your bundle size! You'll have multiple versions of sentry js code loaded for your users.

from sentry-javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.