|
|
@@ -1,19 +1,47 @@
|
|
|
import * as Sentry from "@sentry/react";
|
|
|
+import Cohere from "cohere-js";
|
|
|
+import { isEmpty } from "lodash";
|
|
|
|
|
|
-type LogFunction = (error: Error) => void;
|
|
|
+type LogFunction = (error: Error, tags?: { [key: string]: string }) => void;
|
|
|
type LogFunctions = {
|
|
|
[key in Sentry.Severity]: LogFunction;
|
|
|
};
|
|
|
|
|
|
-const logFunctionBuilder = (scope: string, severity: Sentry.Severity) => (
|
|
|
- error: Error
|
|
|
+type LogFunctionBuilder = (
|
|
|
+ scope: string,
|
|
|
+ severity: Sentry.Severity
|
|
|
+) => LogFunction;
|
|
|
+
|
|
|
+const logFunctionBuilder: LogFunctionBuilder = (scope, severity) => (
|
|
|
+ error,
|
|
|
+ tags
|
|
|
) => {
|
|
|
- Sentry.withScope((sentryScope) => {
|
|
|
- sentryScope.setTag("scope", scope);
|
|
|
- sentryScope.setLevel(severity);
|
|
|
+ if (process.env.ENABLE_COHERE) {
|
|
|
+ Cohere.getSessionUrl((sessionUrl) => {
|
|
|
+ Sentry.withScope((sentryScope) => {
|
|
|
+ sentryScope.setTag("scope", scope);
|
|
|
+ sentryScope.setTag("cohere_link", sessionUrl);
|
|
|
+ sentryScope.setLevel(severity);
|
|
|
+
|
|
|
+ if (!isEmpty(tags)) {
|
|
|
+ sentryScope.setTags(tags);
|
|
|
+ }
|
|
|
+
|
|
|
+ Sentry.captureException(error);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Sentry.withScope((sentryScope) => {
|
|
|
+ sentryScope.setTag("scope", scope);
|
|
|
+ sentryScope.setLevel(severity);
|
|
|
+
|
|
|
+ if (!isEmpty(tags)) {
|
|
|
+ sentryScope.setTags(tags);
|
|
|
+ }
|
|
|
|
|
|
- Sentry.captureException(error);
|
|
|
- });
|
|
|
+ Sentry.captureException(error);
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
function buildLogger(scope: string = "global") {
|