sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Investigate ways of supporting javax and jakarta for Spring and Spring Boot

Open adinauer opened this issue 2 years ago • 9 comments

Description

We've decided to duplicate sentry-servlet (javax) into sentry-servlet-jakarta (jakarta) to support both as it's only three files that rarely change.

For Spring and Spring Boot we'd like to avoid duplication so we want to find out possible ways of supporting both.

See https://github.com/getsentry/sentry-java/issues/1789

adinauer avatar Apr 12 '22 13:04 adinauer

Any news on this? We are currently running Spring Boot v3-M3 and we are unable to use the Sentry SDK at this time.

rauldeheer avatar Jun 27 '22 13:06 rauldeheer

@rauldeheer we don't have a schedule for this yet, it's very high on the backlog though.

adinauer avatar Jun 28 '22 06:06 adinauer

Current state of investigation:

Our current artifacts that depend on javax can be transformed to Jakarta namespace with Eclipse Transformer.

Manual step by step guide:

  1. Download & unzip Eclipse Transformer CLI distribution.

  2. Transform JARs:

$ java -jar org.eclipse.transformer.cli-0.5.0.jar ~/.m2/repository/io/sentry/sentry-spring-boot-starter/6.2.1/sentry-spring-boot-starter-6.2.1.jar ~/.m2/repository/io/sentry/sentry-spring-boot-starter/6.2.1/sentry-spring-boot-starter-6.2.1-jakarta.jar

$ java -jar org.eclipse.transformer.cli-0.5.0.jar ~/.m2/repository/io/sentry/sentry-spring/6.2.1/sentry-spring-6.2.1.jar ~/.m2/repository/io/sentry/sentry-spring/6.2.1/sentry-spring-6.2.1-jakarta.jar
  1. Include transformed files in pom.xml using classifier:
<dependency>
	<groupId>io.sentry</groupId>
	<artifactId>sentry-spring-boot-starter</artifactId>
	<version>6.2.1</version>
	<classifier>jakarta</classifier>
	<exclusions>
		<exclusion>
			<groupId>io.sentry</groupId>
			<artifactId>sentry-spring</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>io.sentry</groupId>
	<artifactId>sentry-spring</artifactId>
	<version>6.2.1</version>
	<classifier>jakarta</classifier>
</dependency>

This proves that Transformer works and can be used to produce Jakarta compatible artifacts, but of course we cannot recommend going through this process to our users. We need one of:

  1. Produce Jakarta compatible artifacts in our build process - that's possible (Hibernate does it), but there's not straightforward out-of-the-box working solution other than 3rd party https://github.com/sebersole/jakarta-transformer-plugin ~that I haven't tested yet~ Project is unsupported anymore.

Update: project has moved to https://github.com/hibernate/jakarta-transformer-plugin/

  1. Simplify the guide so that it's a single step process and does not require installing Jakarta artifacts to Maven repository manually (perhaps with transformer-maven-plugin).

maciejwalkowiak avatar Jul 22 '22 11:07 maciejwalkowiak

I played with jakarta-transformer-plugin and came up with following:

  1. Create a new module sentry-spring-jakarta with following build.gradle:
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.plugin.SpringBootPlugin

plugins {
    `java-library`
    kotlin("jvm")
    id("org.hibernate.jakarta-transformer") version "0.9.6"
    id(Config.BuildPlugins.springBoot) version Config.springBootVersion apply false
    id(Config.BuildPlugins.springDependencyManagement) version Config.BuildPlugins.springDependencyManagementVersion
}

the<DependencyManagementExtension>().apply {
    imports {
        mavenBom(SpringBootPlugin.BOM_COORDINATES)
    }
}

configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
    kotlinOptions.languageVersion = Config.kotlinCompatibleLanguageVersion
}

dependencies {
    // Specifying the transformer's dependencies is optional.  0.2.0 is used by default
    jakartaTransformerTool(
        "org.eclipse.transformer:org.eclipse.transformer:0.2.0",
    )
    jakartaTransformerTool("org.eclipse.transformer:org.eclipse.transformer.cli:0.2.0")
}

jakartaTransformation {
    shadow(projects.sentrySpring) {
        withJavadoc()
        withSources()
    }
}

Calling from the module directory:

$ ../gradlew clean shadow

results in artifacts:

-rw-r--r--  1 maciej  staff    261 Jul 22 15:52 sentry-spring-jakarta-6.3.0-javadoc.jar
-rw-r--r--  1 maciej  staff    261 Jul 22 15:52 sentry-spring-jakarta-6.3.0-sources.jar
-rw-r--r--  1 maciej  staff  54071 Jul 22 15:52 sentry-spring-jakarta-6.3.0.jar

But running gradlew build produces:

Execution failed for task ':sentry-spring-jakarta:publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'mavenLocal'
   > Invalid publication 'maven': multiple artifacts with the identical extension and classifier ('jar', 'sources').

So this part would need to be solved.

Running plugin with the latest version of Eclipse Transformer 0.5.0 results in error (https://github.com/hibernate/jakarta-transformer-plugin/issues/4)

This for now ends my investigation. I think this provides enough research and groundwork to finish the implementation, as it will be mostly playing and configuring Gradle.

maciejwalkowiak avatar Jul 22 '22 13:07 maciejwalkowiak

New module is committed to branch: https://github.com/getsentry/sentry-java/tree/gh-1984

maciejwalkowiak avatar Jul 22 '22 14:07 maciejwalkowiak

Any news on this? We've also had to stop using Sentry due to lack of support.

TomBeckett avatar Aug 31 '22 14:08 TomBeckett

@TomBeckett we're looking to add support in the near future - no detailed timeline yet but we plan to have support for the release at the latest.

adinauer avatar Aug 31 '22 14:08 adinauer

@adinauer Thanks for update. Anything the community can do to assist?

TomBeckett avatar Aug 31 '22 14:08 TomBeckett

@TomBeckett I guess @maciejwalkowiak has already done a lot of the ground work. At this point I assume we can make it work. Maybe we'll need help if we can't figure out a way around issues like the one linked by Maciej above. We'll post here once we know more.

adinauer avatar Sep 01 '22 06:09 adinauer

Do you need any help? Please let us know. @adinauer @maciejwalkowiak

rauldeheer avatar Sep 23 '22 06:09 rauldeheer

Thanks for the offer @rauldeheer . We're planning to take a look at this in the coming weeks. Will let you know as soon as we have specific things we need help with.

adinauer avatar Sep 26 '22 06:09 adinauer

Spring Boot 3 RC1 is aiming to be ready around 20th October.

Would it be possible to have Sentry available for testing against that RC? @adinauer

TomBeckett avatar Oct 06 '22 14:10 TomBeckett

@TomBeckett work on it has begun. Can't state a specific release date yet.

adinauer avatar Oct 06 '22 15:10 adinauer

@TomBeckett @rauldeheer we've just released 6.7.0-alpha.1 which has separate modules for supporting Spring 6 (sentry-spring-jakarta) and Spring Boot 3 (sentry-spring-boot-starter-jakarta). We also have samples for them available Spring and Spring Boot. If you decide to give it a try, any feedback is very welcome :-)

adinauer avatar Oct 19 '22 08:10 adinauer

@adinauer Are these available on maven? Do I need both sentry-servlet-jakarta and sentry-spring-boot-starter ?

TomBeckett avatar Oct 19 '22 12:10 TomBeckett

Hey @TomBeckett , I assume it takes a bit until the packages arrive at the different Maven mirrors. I see it here: https://repo1.maven.org/maven2/io/sentry/sentry-spring-boot-starter-jakarta/6.7.0-alpha.1/

Do I need both sentry-servlet-jakarta and sentry-spring-boot-starter ?

Actually none of those. You want sentry-spring-boot-starter-jakarta for Spring Boot or sentry-spring-jakarta for Spring. Note the jakarta in the name.

adinauer avatar Oct 19 '22 12:10 adinauer

We've been running this for a few hours in our dev environment - so far so good. I'll open any issues as I see them but early signs are good.

Please pass on my thanks for the team @adinauer (with a big shout out to @lbloder!) for getting it done early before the RC. It really helps us get ready internally 👍

TomBeckett avatar Oct 19 '22 14:10 TomBeckett

@adinauer Just one last update - No issues encountered using this beta build.

FYI it's been good to get Sentry back - it really is a fantastic product.

Thanks again for releasing an early version for us to use 👍

TomBeckett avatar Oct 28 '22 15:10 TomBeckett

@TomBeckett that's great to hear. Thanks for the kind words ❤️

adinauer avatar Oct 31 '22 12:10 adinauer

Closing this now as version 3.0.0 of Spring Boot has been released and it seems to be working. Version has just been bumped in https://github.com/getsentry/sentry-java/pull/2389

adinauer avatar Nov 25 '22 10:11 adinauer