Skip to content

Commit 3074735

Browse files
AbhiPrasadconstantinius
authored andcommitted
feat(logs): Add java empty state onboarding for logs (#98204)
resolves https://linear.app/getsentry/issue/LOGS-315/add-empty-state-onboarding-for-java-sdks <img width="1217" height="790" alt="image" src="https://github.com/user-attachments/assets/91d42f56-766a-47cc-a58d-36c1d1ed5927" />
1 parent c3a9f2e commit 3074735

File tree

6 files changed

+496
-0
lines changed

6 files changed

+496
-0
lines changed

static/app/data/platformCategories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ export const withLoggingOnboarding: Set<PlatformKey> = new Set([
321321
'go-iris',
322322
'go-martini',
323323
'go-negroni',
324+
'java',
325+
'java-log4j2',
326+
'java-logback',
327+
'java-spring',
328+
'java-spring-boot',
324329
'javascript',
325330
'javascript-angular',
326331
'javascript-astro',

static/app/gettingStartedDocs/java/java.tsx

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,106 @@ Sentry.captureUserFeedback(userFeedback)`,
453453
nextSteps: () => [],
454454
};
455455

456+
const logsOnboarding: OnboardingConfig = {
457+
install: () => [
458+
{
459+
type: StepType.INSTALL,
460+
content: [
461+
{
462+
type: 'text',
463+
text: tct(
464+
"To start using logs, make sure your application uses Sentry Java SDK version [code:8.12.0] or higher. If you're on an older major version of the SDK, follow our [link:migration guide] to upgrade.",
465+
{
466+
code: <code />,
467+
link: (
468+
<ExternalLink href="https://docs.sentry.io/platforms/java/migration/" />
469+
),
470+
}
471+
),
472+
},
473+
],
474+
},
475+
],
476+
configure: params => [
477+
{
478+
type: StepType.CONFIGURE,
479+
content: [
480+
{
481+
type: 'text',
482+
text: tct(
483+
'To enable logging, you need to initialize the SDK with the [code:logs.enabled] option set to [code:true].',
484+
{
485+
code: <code />,
486+
}
487+
),
488+
},
489+
{
490+
type: 'code',
491+
tabs: [
492+
{
493+
label: 'Java',
494+
language: 'java',
495+
code: `import io.sentry.Sentry;
496+
497+
Sentry.init(options -> {
498+
options.setDsn("${params.dsn.public}");
499+
options.getLogs().setEnabled(true);
500+
});`,
501+
},
502+
{
503+
label: 'Kotlin',
504+
language: 'kotlin',
505+
code: `import io.sentry.Sentry
506+
507+
Sentry.init { options ->
508+
options.dsn = "${params.dsn.public}"
509+
options.logs.enabled = true
510+
}`,
511+
},
512+
],
513+
},
514+
],
515+
},
516+
],
517+
verify: () => [
518+
{
519+
type: StepType.VERIFY,
520+
content: [
521+
{
522+
type: 'text',
523+
text: t('Send a test log from your app to verify logs are arriving in Sentry.'),
524+
},
525+
{
526+
type: 'code',
527+
tabs: [
528+
{
529+
label: 'Java',
530+
language: 'java',
531+
code: `import io.sentry.Sentry;
532+
533+
Sentry.logger().info("A simple log message");
534+
Sentry.logger().error("A %s log message", "formatted");`,
535+
},
536+
{
537+
label: 'Kotlin',
538+
language: 'kotlin',
539+
code: `import io.sentry.Sentry
540+
541+
Sentry.logger().info("A simple log message")
542+
Sentry.logger().error("A %s log message", "formatted")`,
543+
},
544+
],
545+
},
546+
],
547+
},
548+
],
549+
};
550+
456551
const docs: Docs<PlatformOptions> = {
457552
platformOptions,
458553
feedbackOnboardingCrashApi: feedbackOnboardingCrashApiJava,
459554
crashReportOnboarding: feedbackOnboardingCrashApiJava,
555+
logsOnboarding,
460556
onboarding,
461557
};
462558

static/app/gettingStartedDocs/java/log4j2.tsx

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,133 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
429429
],
430430
};
431431

432+
const logsOnboarding: OnboardingConfig = {
433+
install: () => [
434+
{
435+
type: StepType.INSTALL,
436+
content: [
437+
{
438+
type: 'text',
439+
text: tct(
440+
"To start using logs, make sure your application uses Sentry Java SDK version [code:8.16.0] or higher. If you're on an older major version of the SDK, follow our [link:migration guide] to upgrade.",
441+
{
442+
code: <code />,
443+
link: (
444+
<ExternalLink href="https://docs.sentry.io/platforms/java/guides/log4j2/migration/" />
445+
),
446+
}
447+
),
448+
},
449+
],
450+
},
451+
],
452+
configure: params => [
453+
{
454+
type: StepType.CONFIGURE,
455+
content: [
456+
{
457+
type: 'text',
458+
text: tct(
459+
'To enable logging, you need to initialize the SDK with the [code:logs.enabled] option in your [code:sentry.properties] file or when you call [code:Sentry.init].',
460+
{
461+
code: <code />,
462+
}
463+
),
464+
},
465+
{
466+
type: 'code',
467+
tabs: [
468+
{
469+
label: 'sentry.properties',
470+
language: 'properties',
471+
code: `logs.enabled=true`,
472+
},
473+
{
474+
label: 'Java',
475+
language: 'java',
476+
code: `import io.sentry.Sentry;
477+
478+
Sentry.init(options -> {
479+
options.setDsn("${params.dsn.public}");
480+
options.getLogs().setEnabled(true);
481+
});`,
482+
},
483+
{
484+
label: 'Kotlin',
485+
language: 'kotlin',
486+
code: `import io.sentry.Sentry
487+
488+
Sentry.init { options ->
489+
options.dsn = "${params.dsn.public}"
490+
options.logs.enabled = true
491+
}`,
492+
},
493+
],
494+
},
495+
{
496+
type: 'text',
497+
text: tct(
498+
'You may also set [code:minimumLevel] in [code:log4j2.xml] to configure which log messages are sent to Sentry.',
499+
{
500+
code: <code />,
501+
}
502+
),
503+
},
504+
{
505+
type: 'code',
506+
tabs: [
507+
{
508+
label: 'log4j2.xml',
509+
language: 'xml',
510+
code: `<Sentry
511+
name="Sentry"
512+
dsn="${params.dsn.public}"
513+
minimumLevel="DEBUG"
514+
/>
515+
`,
516+
},
517+
],
518+
},
519+
],
520+
},
521+
],
522+
verify: () => [
523+
{
524+
type: StepType.VERIFY,
525+
content: [
526+
{
527+
type: 'text',
528+
text: tct(
529+
'Once the handler is configured with logging enabled, any logs at or above the [code:minimumLevel] will be sent to Sentry.',
530+
{
531+
code: <code />,
532+
}
533+
),
534+
},
535+
{
536+
type: 'code',
537+
language: 'java',
538+
code: `import org.apache.logging.log4j.LogManager;
539+
import org.apache.logging.log4j.Logger;
540+
541+
public class SentryLog4jExample {
542+
public static void main(String[] args) {
543+
Logger logger = LogManager.getRootLogger();
544+
logger.info("A %s test log message", "formatted");
545+
}
546+
}`,
547+
},
548+
],
549+
},
550+
],
551+
};
552+
432553
const docs: Docs<PlatformOptions> = {
433554
platformOptions,
434555
feedbackOnboardingCrashApi: feedbackOnboardingCrashApiJava,
435556
crashReportOnboarding: feedbackOnboardingCrashApiJava,
436557
onboarding,
558+
logsOnboarding,
437559
};
438560

439561
export default docs;

static/app/gettingStartedDocs/java/logback.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,99 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
452452
],
453453
};
454454

455+
const logsOnboarding: OnboardingConfig = {
456+
install: () => [
457+
{
458+
type: StepType.INSTALL,
459+
content: [
460+
{
461+
type: 'text',
462+
text: tct(
463+
"To start using logs, make sure your application uses Sentry Java SDK version [code:8.15.0] or higher. If you're on an older major version of the SDK, follow our [link:migration guide] to upgrade.",
464+
{
465+
code: <code />,
466+
link: (
467+
<ExternalLink href="https://docs.sentry.io/platforms/java/guides/logback/migration/" />
468+
),
469+
}
470+
),
471+
},
472+
],
473+
},
474+
],
475+
configure: params => [
476+
{
477+
type: StepType.CONFIGURE,
478+
content: [
479+
{
480+
type: 'text',
481+
text: tct(
482+
'To enable logging, you need to configure the enabled logs option in the appender configuration. You may also set [code:minimumLevel] to configure which log messages are sent to Sentry.',
483+
{
484+
code: <code />,
485+
}
486+
),
487+
},
488+
{
489+
type: 'code',
490+
tabs: [
491+
{
492+
label: 'logback.xml',
493+
language: 'xml',
494+
code: `<appender name="sentry" class="io.sentry.logback.SentryAppender">
495+
<options>
496+
<dsn>${params.dsn.public}</dsn>
497+
<logs>
498+
<enabled>true</enabled>
499+
</logs>
500+
</options>
501+
<!-- Default for Log Events is INFO -->
502+
<minimumLevel>DEBUG</minimumLevel>
503+
</appender>`,
504+
},
505+
],
506+
},
507+
],
508+
},
509+
],
510+
verify: () => [
511+
{
512+
type: StepType.VERIFY,
513+
content: [
514+
{
515+
type: 'text',
516+
text: tct(
517+
'Once the handler is configured with logging enabled, any logs at or above the [code:minimumLevel] will be sent to Sentry.',
518+
{
519+
code: <code />,
520+
}
521+
),
522+
},
523+
{
524+
type: 'code',
525+
language: 'java',
526+
code: `import org.slf4j.Logger;
527+
import org.slf4j.LoggerFactory;
528+
529+
public class SentryLogbackExample {
530+
private static Logger logger = LoggerFactory.getLogger(SentryLogbackExample.class);
531+
532+
public static void main(String[] args) {
533+
logger.info("A test log message");
534+
}
535+
}`,
536+
},
537+
],
538+
},
539+
],
540+
};
541+
455542
const docs: Docs<PlatformOptions> = {
456543
onboarding,
457544
feedbackOnboardingCrashApi: feedbackOnboardingCrashApiJava,
458545
crashReportOnboarding: feedbackOnboardingCrashApiJava,
459546
platformOptions,
547+
logsOnboarding,
460548
};
461549

462550
export default docs;

0 commit comments

Comments
 (0)