diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/InstanceConfig.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/InstanceConfig.java index 88e18173a8..dd918939ea 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/InstanceConfig.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/InstanceConfig.java @@ -5,7 +5,6 @@ import com.appsmith.server.helpers.InstanceConfigHelper; import com.appsmith.server.repositories.CacheableRepositoryHelper; import com.appsmith.server.services.ConfigService; import io.micrometer.observation.annotation.Observed; -import io.sentry.Sentry; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationReadyEvent; @@ -71,7 +70,6 @@ public class InstanceConfig implements ApplicationListener object before diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/ObservabilityLogger.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/ObservabilityLogger.java new file mode 100644 index 0000000000..fac8e458a9 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/ObservabilityLogger.java @@ -0,0 +1,39 @@ +package com.appsmith.server.exceptions.util; + +import com.appsmith.external.exceptions.AppsmithErrorAction; +import com.appsmith.external.exceptions.BaseException; +import lombok.extern.slf4j.Slf4j; + +import java.io.PrintWriter; +import java.io.StringWriter; + +@Slf4j +public class ObservabilityLogger { + public static void doLog(Throwable error) { + if (error instanceof BaseException baseException && baseException.isHideStackTraceInLogs()) { + log.error(baseException.getClass().getSimpleName() + ": " + baseException.getMessage()); + } else { + log.error("", error); + } + + StringWriter stringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stringWriter); + error.printStackTrace(printWriter); + String stringStackTrace = stringWriter.toString(); + + // Log stack trace for debugging + log.error("Stack Trace: {}", stringStackTrace); + + if (error instanceof BaseException) { + BaseException baseError = (BaseException) error; + if (baseError.getErrorAction() == AppsmithErrorAction.LOG_EXTERNALLY) { + // Log additional context for external logging + log.error( + "Downstream Error - Message: {}, Code: {}", + baseError.getDownstreamErrorMessage(), + baseError.getDownstreamErrorCode()); + baseError.getContextMap().forEach((key, value) -> log.error("Context - {}: {}", key, value)); + } + } + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/SentryLogger.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/SentryLogger.java deleted file mode 100644 index 9e07c04216..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/util/SentryLogger.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.appsmith.server.exceptions.util; - -import com.appsmith.external.constants.MDCConstants; -import com.appsmith.external.exceptions.AppsmithErrorAction; -import com.appsmith.external.exceptions.BaseException; -import io.sentry.Sentry; -import io.sentry.SentryLevel; -import io.sentry.protocol.User; -import lombok.extern.slf4j.Slf4j; - -import java.io.PrintWriter; -import java.io.StringWriter; - -@Slf4j -public class SentryLogger { - public static void doLog(Throwable error) { - if (error instanceof BaseException baseException && baseException.isHideStackTraceInLogs()) { - log.error(baseException.getClass().getSimpleName() + ": " + baseException.getMessage()); - } else { - log.error("", error); - } - - StringWriter stringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stringWriter); - error.printStackTrace(printWriter); - String stringStackTrace = stringWriter.toString(); - - Sentry.configureScope(scope -> { - /** - * Send stack trace as a string message. This is a work around till it is figured out why raw - * stack trace is not visible on Sentry dashboard. - * */ - scope.setExtra("Stack Trace", stringStackTrace); - scope.setLevel(SentryLevel.ERROR); - scope.setTag("source", "appsmith-internal-server"); - }); - - if (error instanceof BaseException) { - BaseException baseError = (BaseException) error; - if (baseError.getErrorAction() == AppsmithErrorAction.LOG_EXTERNALLY) { - Sentry.configureScope(scope -> { - baseError.getContextMap().forEach(scope::setTag); - scope.setExtra("downstreamErrorMessage", baseError.getDownstreamErrorMessage()); - scope.setExtra("downstreamErrorCode", baseError.getDownstreamErrorCode()); - }); - final User user = new User(); - user.setEmail(baseError.getContextMap().getOrDefault(MDCConstants.USER_EMAIL, "unknownUser")); - Sentry.setUser(user); - Sentry.captureException(error); - } - } else { - Sentry.captureException(error); - } - } -}