Comments (3)
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.
@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.
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)
- React ErrorBoundary component is not type safe HOT 6
- Backport `7.112.0` HOT 2
- Remove ember-auto-import 1.12.1 DependencyTrack HOT 2
- Ember Canary ember-release Test Failed
- nextjs-app-dir (canary) Test Failed
- After configuring the https.status_code in Alert Rules, it does not take effect. HOT 1
- Tracking Issue: Things to do based on observations in example apps
- Opentelemetry http server responses not rendered with correct span description
- [Flaky CI]: Node 21 Integration Tests -> suites/tracing/metric-summaries/test.ts HOT 1
- Error was not tracked on Sentry HOT 3
- Build fails when using nodePolyfills from rollup-plugin-polyfill-node HOT 5
- captureConsoleIntegration cannot be added as integration HOT 4
- Events not recorded HOT 4
- node-cron and node-schedule fire checkin only on app start
- TypeError when ANR is enabled in a bundled application HOT 6
- Cannot use the "latest" keyword for Sentry Lambda layer in serverless files. HOT 1
- Improve distributed tracing custom instrumentation HOT 1
- Make `@sentry/google-cloud-serverless` ESM compat
- Add runtime warning for profiling-node bindings with Node 23
- Issue with captureMessage signature change and errors from non-standard exceptions in Sentry JavaScript SDK HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentry-javascript.