-
-
Notifications
You must be signed in to change notification settings - Fork 459
Fix profiling init for Spring and Spring Boot w Agent auto-init #4815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
lbloder
wants to merge
7
commits into
main
Choose a base branch
from
feat/profiling-w-spring-otel-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+553
−48
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4ce01a
also load converter at sentry initialization time and hold in sentry-…
lbloder 39225ff
use InitUtil to initialize profiler and converter
lbloder 40395fb
add new configuration class to spring and spring4 variants
lbloder f8f253f
add tests for profiler and converter init
lbloder c02c3dd
format code
lbloder d180c19
add test for auto profiler config
lbloder 5e75584
bump api
lbloder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ry-async-profiler/src/test/java/io/sentry/asyncprofiler/init/AsyncProfilerInitUtilTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import io.sentry.ILogger | ||
| import io.sentry.ISentryExecutorService | ||
| import io.sentry.NoOpContinuousProfiler | ||
| import io.sentry.NoOpProfileConverter | ||
| import io.sentry.SentryOptions | ||
| import io.sentry.asyncprofiler.profiling.JavaContinuousProfiler | ||
| import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider | ||
| import io.sentry.util.InitUtil | ||
| import kotlin.test.Test | ||
| import org.mockito.kotlin.mock | ||
|
|
||
| class AsyncProfilerInitUtilTest { | ||
|
|
||
| @Test | ||
| fun `initialize Profiler returns no-op profiler if profiling disabled`() { | ||
| val options = SentryOptions() | ||
| val profiler = InitUtil.initializeProfiler(options) | ||
| assert(profiler is NoOpContinuousProfiler) | ||
| } | ||
|
|
||
| @Test | ||
| fun `initialize Converter returns no-op profiler if profiling disabled`() { | ||
| val options = SentryOptions() | ||
| val converter = InitUtil.initializeProfileConverter(options) | ||
| assert(converter is NoOpProfileConverter) | ||
| } | ||
|
|
||
| @Test | ||
| fun `initialize Profiler returns no-op profiler if profiler already initialized`() { | ||
| val options = | ||
| SentryOptions().also { | ||
| it.setProfileSessionSampleRate(1.0) | ||
| it.tracesSampleRate = 1.0 | ||
| it.setContinuousProfiler( | ||
| JavaContinuousProfiler(mock<ILogger>(), "", 10, mock<ISentryExecutorService>()) | ||
| ) | ||
| } | ||
|
|
||
| val profiler = InitUtil.initializeProfiler(options) | ||
| assert(profiler is NoOpContinuousProfiler) | ||
| } | ||
|
|
||
| @Test | ||
| fun `initialize converter returns no-op converter if converter already initialized`() { | ||
| val options = | ||
| SentryOptions().also { | ||
| it.setProfileSessionSampleRate(1.0) | ||
| it.tracesSampleRate = 1.0 | ||
| it.profilerConverter = AsyncProfilerProfileConverterProvider.AsyncProfilerProfileConverter() | ||
| } | ||
|
|
||
| val converter = InitUtil.initializeProfileConverter(options) | ||
| assert(converter is NoOpProfileConverter) | ||
| } | ||
|
|
||
| @Test | ||
| fun `initialize Profiler returns JavaContinuousProfiler if profiling enabled but profiler not yet initialized`() { | ||
| val options = | ||
| SentryOptions().also { | ||
| it.setProfileSessionSampleRate(1.0) | ||
| it.tracesSampleRate = 1.0 | ||
| } | ||
| val profiler = InitUtil.initializeProfiler(options) | ||
| assert(profiler is JavaContinuousProfiler) | ||
| } | ||
|
|
||
| @Test | ||
| fun `initialize Profiler returns AsyncProfilerProfileConverterProvider if profiling enabled but profiler not yet initialized`() { | ||
| val options = | ||
| SentryOptions().also { | ||
| it.setProfileSessionSampleRate(1.0) | ||
| it.tracesSampleRate = 1.0 | ||
| } | ||
| val converter = InitUtil.initializeProfileConverter(options) | ||
| assert(converter is AsyncProfilerProfileConverterProvider.AsyncProfilerProfileConverter) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
sentry-spring-7/src/main/java/io/sentry/spring7/SentryProfilerConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package io.sentry.spring7; | ||
|
|
||
| import com.jakewharton.nopen.annotation.Open; | ||
| import io.sentry.IContinuousProfiler; | ||
| import io.sentry.IProfileConverter; | ||
| import io.sentry.NoOpContinuousProfiler; | ||
| import io.sentry.NoOpProfileConverter; | ||
| import io.sentry.Sentry; | ||
| import io.sentry.SentryOptions; | ||
| import io.sentry.util.InitUtil; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| /** | ||
| * Handles late initialization of the profiler if the application is run with the OTEL Agent in | ||
| * auto-init mode. In that case the agent cannot initialize the profiler yet and falls back to No-Op | ||
| * implementations. This Configuration sets the profiler and converter on the options if that was | ||
| * the case. | ||
| */ | ||
| @Configuration(proxyBeanMethods = false) | ||
| @Open | ||
| public class SentryProfilerConfiguration { | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean(name = "sentryOpenTelemetryProfilerConfiguration") | ||
| public IContinuousProfiler sentryOpenTelemetryProfilerConfiguration() { | ||
| SentryOptions options = Sentry.getGlobalScope().getOptions(); | ||
| IContinuousProfiler profiler = NoOpContinuousProfiler.getInstance(); | ||
|
|
||
| if (Sentry.isEnabled()) { | ||
| return InitUtil.initializeProfiler(options); | ||
| } else { | ||
| return profiler; | ||
| } | ||
| } | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean(name = "sentryOpenTelemetryProfilerConverterConfiguration") | ||
| public IProfileConverter sentryOpenTelemetryProfilerConverterConfiguration() { | ||
| SentryOptions options = Sentry.getGlobalScope().getOptions(); | ||
| IProfileConverter converter = NoOpProfileConverter.getInstance(); | ||
|
|
||
| if (Sentry.isEnabled()) { | ||
| return InitUtil.initializeProfileConverter(options); | ||
| } else { | ||
| return converter; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...y-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryProfilerAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package io.sentry.spring.boot4; | ||
|
|
||
| import com.jakewharton.nopen.annotation.Open; | ||
| import io.sentry.spring7.SentryProfilerConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| @Configuration(proxyBeanMethods = false) | ||
| @ConditionalOnClass(name = {"io.sentry.opentelemetry.agent.AgentMarker"}) | ||
| @Open | ||
| @Import(SentryProfilerConfiguration.class) | ||
| public class SentryProfilerAutoConfiguration {} |
1 change: 1 addition & 0 deletions
1
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| io.sentry.spring.boot4.SentryAutoConfiguration | ||
| io.sentry.spring.boot4.SentryProfilerAutoConfiguration | ||
| io.sentry.spring.boot4.SentryLogbackAppenderAutoConfiguration | ||
| io.sentry.spring.boot4.SentryWebfluxAutoConfiguration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryProfilerAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package io.sentry.spring.boot.jakarta; | ||
|
|
||
| import com.jakewharton.nopen.annotation.Open; | ||
| import io.sentry.spring.jakarta.SentryProfilerConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| @Configuration(proxyBeanMethods = false) | ||
| @ConditionalOnClass(name = {"io.sentry.opentelemetry.agent.AgentMarker"}) | ||
| @Open | ||
| @Import(SentryProfilerConfiguration.class) | ||
| public class SentryProfilerAutoConfiguration {} | ||
1 change: 1 addition & 0 deletions
1
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| io.sentry.spring.boot.jakarta.SentryAutoConfiguration | ||
| io.sentry.spring.boot.jakarta.SentryProfilerAutoConfiguration | ||
| io.sentry.spring.boot.jakarta.SentryLogbackAppenderAutoConfiguration | ||
| io.sentry.spring.boot.jakarta.SentryWebfluxAutoConfiguration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryProfilerAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package io.sentry.spring.boot; | ||
|
|
||
| import com.jakewharton.nopen.annotation.Open; | ||
| import io.sentry.spring.SentryProfilerConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| @Configuration(proxyBeanMethods = false) | ||
| @ConditionalOnClass(name = {"io.sentry.opentelemetry.agent.AgentMarker"}) | ||
| @Open | ||
| @Import(SentryProfilerConfiguration.class) | ||
| public class SentryProfilerAutoConfiguration {} |
1 change: 1 addition & 0 deletions
1
sentry-spring-boot/src/main/resources/META-INF/spring.factories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it conditional on the async profiler class too