setup.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import * as Sentry from "@sentry/react";
  2. import { Integrations } from "@sentry/tracing";
  3. import Cohere from "cohere-js";
  4. import CohereSentry from "cohere-sentry";
  5. const SENTRY_DSN = process.env.SENTRY_DSN;
  6. const SENTRY_ENV = process.env.SENTRY_ENV || "development";
  7. const COHERE_INTEGRATION = process.env.ENABLE_COHERE
  8. ? [new CohereSentry()]
  9. : [];
  10. export const SetupSentry = () => {
  11. if (!SENTRY_DSN) {
  12. return;
  13. }
  14. Sentry.init({
  15. dsn: SENTRY_DSN,
  16. integrations: [new Integrations.BrowserTracing(), ...COHERE_INTEGRATION],
  17. environment: SENTRY_ENV,
  18. // Check out https://docs.sentry.io/platforms/javascript/guides/react/configuration/sampling/ for a more refined sample rate
  19. tracesSampleRate: 1,
  20. });
  21. if (process.env.ENABLE_COHERE) {
  22. const sessionUrlListener = (sessionUrl: string) => {
  23. Sentry.configureScope((scope) => {
  24. scope.addEventProcessor((event) => {
  25. event.tags = {
  26. ...event.tags,
  27. cohere_link: `${sessionUrl}${
  28. event.timestamp ? `?ts=${event.timestamp * 1000}` : ""
  29. }`,
  30. };
  31. return event;
  32. });
  33. });
  34. };
  35. Cohere.addSessionUrlListener(sessionUrlListener);
  36. }
  37. };