Skip to content

Commit e8b532f

Browse files
lbloderadinauer
andauthored
Add gradle task to start spring boot samples with agent (#3885)
* add gradle task to start jakarta-opentelemetry sample with agent attached * add bootRunWithAgent task that automatically attaches the otel agent to bootRun * remove auto init from gradle task, make sample rate overridable * add readme to boot-opentelemetry and boot-jakarta-opentelemetry samples * Update sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/README.md Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com> * Update sentry-samples/sentry-samples-spring-boot-opentelemetry/README.md Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com> --------- Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com>
1 parent 19c10ca commit e8b532f

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Sentry Sample Spring Boot 3.0+
22

3-
Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot) from version `3.0` onwards.
3+
Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot) from version `3.0` onwards and the Sentry OpenTelemetry agent.
44

55
## How to run?
66

7-
To see events triggered in this sample application in your Sentry dashboard, go to `src/main/resources/application.properties` and replace the test DSN with your own DSN.
7+
Make sure the `sentry-opentelemetry` module is built (`../../gradlew :sentry-opentelemetry:sentry-opentelemetry-agent:assemble`).
88

99
Then, execute a command from the module directory:
1010

1111
```
12-
../../gradlew bootRun
12+
SENTRY_DSN="https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563" SENTRY_DEBUG=true ../../gradlew bootRunWithAgent
1313
```
1414

15+
To see events triggered in this sample application in your Sentry dashboard, replace the `SENTRY_DSN` above with your own.
16+
17+
## Http
18+
1519
Make an HTTP request that will trigger events:
1620

1721
```

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/build.gradle.kts

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.jetbrains.kotlin.config.KotlinCompilerVersion
22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
import org.springframework.boot.gradle.tasks.run.BootRun
34

45
plugins {
56
id(Config.BuildPlugins.springBoot) version Config.springBoot3Version
@@ -79,6 +80,31 @@ configure<SourceSetContainer> {
7980
}
8081
}
8182

83+
tasks.register<BootRun>("bootRunWithAgent").configure {
84+
group = "application"
85+
86+
val mainBootRunTask = tasks.getByName<BootRun>("bootRun")
87+
mainClass = mainBootRunTask.mainClass
88+
classpath = mainBootRunTask.classpath
89+
90+
val versionName = project.properties["versionName"] as String
91+
val agentProjectId = projects.sentryOpentelemetry.sentryOpentelemetryAgent.identityPath.toString()
92+
val agentProjectPath = project(agentProjectId).projectDir.absolutePath
93+
val agentJarPath = "$agentProjectPath/build/libs/sentry-opentelemetry-agent-$versionName.jar"
94+
95+
val dsn = System.getenv("SENTRY_DSN") ?: "https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563"
96+
val tracesSampleRate = System.getenv("SENTRY_TRACES_SAMPLE_RATE") ?: "1"
97+
98+
environment("SENTRY_DSN", dsn)
99+
environment("SENTRY_TRACES_SAMPLE_RATE", tracesSampleRate)
100+
environment("OTEL_TRACES_EXPORTER", "none")
101+
environment("OTEL_METRICS_EXPORTER", "none")
102+
environment("OTEL_LOGS_EXPORTER", "none")
103+
104+
jvmArgs =
105+
listOf("-Dotel.javaagent.debug=true", "-javaagent:$agentJarPath")
106+
}
107+
82108
tasks.register<Test>("systemTest").configure {
83109
group = "verification"
84110
description = "Runs the System tests"

sentry-samples/sentry-samples-spring-boot-opentelemetry/README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Sentry Sample Spring Boot
22

3-
Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot).
3+
Sample application showing how to use Sentry with [Spring boot](http://spring.io/projects/spring-boot) and the Sentry OpenTelemetry agent.
44

5-
## How to run?
5+
## How to run?
66

7-
To see events triggered in this sample application in your Sentry dashboard, go to `src/main/resources/application.properties` and replace the test DSN with your own DSN.
7+
Make sure the `sentry-opentelemetry` module is built (`../../gradlew :sentry-opentelemetry:sentry-opentelemetry-agent:assemble`).
88

99
Then, execute a command from the module directory:
1010

1111
```
12-
../../gradlew bootRun
12+
SENTRY_DSN="https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563" SENTRY_DEBUG=true ../../gradlew bootRunWithAgent
1313
```
1414

15+
To see events triggered in this sample application in your Sentry dashboard, replace the `SENTRY_DSN` above with your own.
16+
17+
## Http
18+
1519
Make an HTTP request that will trigger events:
1620

1721
```

sentry-samples/sentry-samples-spring-boot-opentelemetry/build.gradle.kts

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.jetbrains.kotlin.config.KotlinCompilerVersion
22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
import org.springframework.boot.gradle.tasks.run.BootRun
34

45
plugins {
56
id(Config.BuildPlugins.springBoot) version Config.springBootVersion
@@ -74,6 +75,31 @@ configure<SourceSetContainer> {
7475
}
7576
}
7677

78+
tasks.register<BootRun>("bootRunWithAgent").configure {
79+
group = "application"
80+
81+
val mainBootRunTask = tasks.getByName<BootRun>("bootRun")
82+
mainClass = mainBootRunTask.mainClass
83+
classpath = mainBootRunTask.classpath
84+
85+
val versionName = project.properties["versionName"] as String
86+
val agentProjectId = projects.sentryOpentelemetry.sentryOpentelemetryAgent.identityPath.toString()
87+
val agentProjectPath = project(agentProjectId).projectDir.absolutePath
88+
val agentJarPath = "$agentProjectPath/build/libs/sentry-opentelemetry-agent-$versionName.jar"
89+
90+
val dsn = System.getenv("SENTRY_DSN") ?: "https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563"
91+
val tracesSampleRate = System.getenv("SENTRY_TRACES_SAMPLE_RATE") ?: "1"
92+
93+
environment("SENTRY_DSN", dsn)
94+
environment("SENTRY_TRACES_SAMPLE_RATE", tracesSampleRate)
95+
environment("OTEL_TRACES_EXPORTER", "none")
96+
environment("OTEL_METRICS_EXPORTER", "none")
97+
environment("OTEL_LOGS_EXPORTER", "none")
98+
99+
jvmArgs =
100+
listOf("-Dotel.javaagent.debug=true", "-javaagent:$agentJarPath")
101+
}
102+
77103
tasks.register<Test>("systemTest").configure {
78104
group = "verification"
79105
description = "Runs the System tests"

0 commit comments

Comments
 (0)