import {Fragment} from 'react';
import ExternalLink from 'sentry/components/links/externalLink';
import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
import {t, tct} from 'sentry/locale';
// Configuration Start
const introduction = (
{tct(
"There are two variants of Sentry available for Spring. If you're using Spring 5, use [sentrySpringLink:sentry-spring]. If you're using Spring 6, use [sentrySpringJakartaLink:sentry-spring-jakarta] instead. Sentry's integration with Spring supports Spring Framework 5.1.2 and above to report unhandled exceptions and optional user information. If you're on an older version, use [legacyIntegrationLink:our legacy integration].",
{
sentrySpringLink: (
),
sentrySpringJakartaLink: (
),
legacyIntegrationLink: (
),
}
)}
);
export const steps = ({
dsn,
}: {
dsn?: string;
} = {}): LayoutProps['steps'] => [
{
type: StepType.INSTALL,
description: t(
"Install Sentry's integration with Spring using either Maven or Gradle:"
),
configurations: [
{
description: {t('Maven')}
,
configurations: [
{
language: 'xml',
description: {t('Spring 5')},
code: `
io.sentry
sentry-spring
6.27.0
`,
},
{
language: 'xml',
description: {t('Spring 6')},
code: `
io.sentry
sentry-spring-jakarta
6.27.0
`,
},
],
},
],
},
{
type: StepType.CONFIGURE,
description: (
{t("Configure Sentry as soon as possible in your application's lifecycle:")}
{tct(
'The [codeSentrySpring:sentry-spring] and [codeSentrySpringJakarta:sentry-spring-jakarta] libraries provide an [codeEnableSentry:@EnableSentry] annotation that registers all required Spring beans. [codeEnableSentry:@EnableSentry] can be placed on any class annotated with [configurationLink:@Configuration] including the main entry class in Spring Boot applications annotated with [springBootApplicationLink:@SpringBootApplication].',
{
codeSentrySpring:
,
codeSentrySpringJakarta:
,
codeEnableSentry:
,
configurationLink: (
),
springBootApplicationLink: (
),
}
)}
),
configurations: [
{
description: {t('Java')}
,
configurations: [
{
language: 'java',
description: {t('Spring 5')},
code: `
import io.sentry.spring.EnableSentry;
@EnableSentry(dsn = "${dsn}")
@Configuration
class SentryConfiguration {
}
`,
},
{
language: 'java',
description: {t('Spring 6')},
code: `
import io.sentry.spring.jakarta.EnableSentry;
@EnableSentry(dsn = "${dsn}")
@Configuration
class SentryConfiguration {
}
`,
},
],
},
{
description: {t('Kotlin')}
,
configurations: [
{
language: 'java',
description: {t('Spring 5')},
code: `
import io.sentry.spring.EnableSentry
import org.springframework.core.Ordered
@EnableSentry(
dsn = "${dsn}",
exceptionResolverOrder = Ordered.LOWEST_PRECEDENCE
)
`,
},
{
language: 'java',
description: {t('Spring 6')},
code: `
import io.sentry.spring.jakarta.EnableSentry
import org.springframework.core.Ordered
@EnableSentry(
dsn = "${dsn}",
exceptionResolverOrder = Ordered.LOWEST_PRECEDENCE
)
`,
},
],
},
{
description: {t('Source Context')}
,
configurations: [
{
language: 'xml',
description: t(
'To upload your source code to Sentry so it can be shown in stack traces, use our Maven plugin.'
),
code: `
io.sentry
sentry-maven-plugin
0.0.3
true
/path/to/sentry-cli
___ORG_SLUG___
___PROJECT_SLUG___
env.SENTRY_AUTH_TOKEN
generate-resources
uploadSourceBundle
...
`,
},
],
},
{
description: {t('Graddle')}
,
configurations: [
{
description: {t('Spring 5')},
language: 'groovy',
code: `implementation 'io.sentry:sentry-spring:6.27.0'`,
},
{
description: {t('Spring 6')},
language: 'groovy',
code: `implementation 'io.sentry:sentry-spring-jakarta:6.27.0'`,
},
],
},
],
},
{
type: StepType.VERIFY,
description: t(
'Last, create an intentional error, so you can test that everything is working:'
),
configurations: [
{
description: Java
,
language: 'java',
code: `
import java.lang.Exception;
import io.sentry.Sentry;
try {
throw new Exception("This is a test.");
} catch (Exception e) {
Sentry.captureException(e);
}
`,
},
{
description: Kotlin
,
language: 'java',
code: `
import java.lang.Exception
import io.sentry.Sentry
try {
throw Exception("This is a test.")
} catch (e: Exception) {
Sentry.captureException(e)
}
`,
},
],
additionalInfo: (
{t(
"If you're new to Sentry, use the email alert to access your account and complete a product tour."
)}
{t(
"If you're an existing user and have disabled alerts, you won't receive this email."
)}
),
},
{
title: t('Source Context'),
configurations: [
{
language: 'groovy',
description: t(
'To upload your source code to Sentry so it can be shown in stack traces, use our Gradle plugin.'
),
code: `
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id "io.sentry.jvm.gradle" version "3.11.1"
}
sentry {
// Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
// This enables source context, allowing you to see your source
// code as part of your stack traces in Sentry.
includeSourceContext = true
org = "___ORG_SLUG___"
projectName = "___PROJECT_SLUG___"
authToken = "your-sentry-auth-token"
}
`,
},
],
additionalInfo: (
{tct(
'For other dependency managers see the [mavenRepositorySpring5Link:central Maven repository (Spring 5)] and [mavenRepositorySpring6Link:central Maven repository (Spring 6)].',
{
mavenRepositorySpring5Link: (
),
mavenRepositorySpring6Link: (
),
}
)}
),
},
{
title: t('Measure Performance'),
description: (
{tct(
'Check out [link:the documentation] to learn how to configure and use Sentry Performance Monitoring with Spring.',
{
link: (
),
}
)}
),
},
];
// Configuration End
export function GettingStartedWithSpring({dsn, ...props}: ModuleProps) {
return ;
}
export default GettingStartedWithSpring;