Skip to content

Commit

Permalink
fix: parse sentry stacktraces including kotlin code (#12938)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroslopez committed Jun 25, 2024
1 parent 39a3104 commit 190c1ec
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Optional<SentryParsedException> buildSentryExceptions(final String stackt
if (stacktrace.startsWith("Traceback (most recent call last):")) {
return buildPythonSentryExceptions(stacktrace);
}
if (stacktrace.contains("\tat ") && stacktrace.contains(".java")) {
if (stacktrace.contains("\tat ") && (stacktrace.contains(".java") || stacktrace.contains(".kt"))) {
return buildJavaSentryExceptions(stacktrace);
}
if (stacktrace.startsWith("AirbyteDbtError: ")) {
Expand Down Expand Up @@ -173,7 +173,7 @@ private static Optional<SentryParsedException> buildJavaSentryExceptions(final S
@SuppressWarnings("LineLength")
// Use a regex to grab stack trace frame information
final Pattern framePattern = Pattern.compile(
"\n\tat (?:[\\w.$/]+/)?(?<module>[\\w$.]+)\\.(?<function>[\\w<>$]+)\\((?:(?<filename>[\\w]+\\.java):(?<lineno>\\d+)\\)|(?<desc>[\\w\\s]*))");
"\n\tat (?:[\\w.$/]+/)?(?<module>[\\w$.]+)\\.(?<function>[\\w<>$]+)\\((?:(?<filename>[\\w]+\\.(?<extension>java|kt)):(?<lineno>\\d+)\\)|(?<desc>[\\w\\s]*))");
final Matcher matcher = framePattern.matcher(exceptionStr);

while (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,68 @@ void testBuildSentryExceptionsJavaChained() {
FUNCTION, "lambda$getDestinationOutputRunnable$7")));
}

@Test
void testBuildSentryExceptionsKotlin() {
final String stacktrace =
"""
io.airbyte.commons.exceptions.ConfigErrorException: Some error message
at io.airbyte.cdk.integrations.destination.staging.StagingConsumerFactory$Companion.streamDescToWriteConfig(StagingConsumerFactory.kt:226)
at io.airbyte.cdk.integrations.destination.staging.StagingConsumerFactory$Companion.access$streamDescToWriteConfig(StagingConsumerFactory.kt:159)
at io.airbyte.cdk.integrations.destination.staging.StagingConsumerFactory.createAsync(StagingConsumerFactory.kt:124)
at io.airbyte.integrations.destination.snowflake.SnowflakeDestination.getSerializedMessageConsumer(SnowflakeDestination.kt:194)
at io.airbyte.cdk.integrations.base.IntegrationRunner.run(IntegrationRunner.kt:116)
at io.airbyte.cdk.integrations.base.adaptive.AdaptiveDestinationRunner$Runner.run(AdaptiveDestinationRunner.kt:68)
at io.airbyte.integrations.destination.snowflake.SnowflakeDestinationKt.main(SnowflakeDestination.kt:279)
""";

final Optional<SentryParsedException> optionalSentryExceptions = exceptionHelper.buildSentryExceptions(stacktrace);
Assertions.assertTrue(optionalSentryExceptions.isPresent());

final SentryParsedException parsedException = optionalSentryExceptions.get();
final List<SentryException> exceptionList = parsedException.exceptions();
Assertions.assertEquals(SentryExceptionPlatform.JAVA, parsedException.platform());
Assertions.assertEquals(1, exceptionList.size());

assertExceptionContent(exceptionList.get(0), "io.airbyte.commons.exceptions.ConfigErrorException", "Some error message",
List.of(
Map.of(
FILENAME, "SnowflakeDestination.kt",
LINE_NO, 279,
MODULE, "io.airbyte.integrations.destination.snowflake.SnowflakeDestinationKt",
FUNCTION, "main"),
Map.of(
FILENAME, "AdaptiveDestinationRunner.kt",
LINE_NO, 68,
MODULE, "io.airbyte.cdk.integrations.base.adaptive.AdaptiveDestinationRunner$Runner",
FUNCTION, "run"),
Map.of(
FILENAME, "IntegrationRunner.kt",
LINE_NO, 116,
MODULE, "io.airbyte.cdk.integrations.base.IntegrationRunner",
FUNCTION, "run"),
Map.of(
FILENAME, "SnowflakeDestination.kt",
LINE_NO, 194,
MODULE, "io.airbyte.integrations.destination.snowflake.SnowflakeDestination",
FUNCTION, "getSerializedMessageConsumer"),
Map.of(
FILENAME, "StagingConsumerFactory.kt",
LINE_NO, 124,
MODULE, "io.airbyte.cdk.integrations.destination.staging.StagingConsumerFactory",
FUNCTION, "createAsync"),
Map.of(
FILENAME, "StagingConsumerFactory.kt",
LINE_NO, 159,
MODULE, "io.airbyte.cdk.integrations.destination.staging.StagingConsumerFactory$Companion",
FUNCTION, "access$streamDescToWriteConfig"),
Map.of(
FILENAME, "StagingConsumerFactory.kt",
LINE_NO, 226,
MODULE, "io.airbyte.cdk.integrations.destination.staging.StagingConsumerFactory$Companion",
FUNCTION, "streamDescToWriteConfig")));

}

@Test
void testBuildSentryExceptionsJavaMultilineValue() {
final String stacktrace =
Expand Down

0 comments on commit 190c1ec

Please sign in to comment.