-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] Integrate Sentry with Opentelemetry agent to send server error alert #112
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
Changes from all commits
4068212
6ce4e28
aead9ca
74bd2d9
6ea7c87
7d46d85
60051aa
c6b6e78
3e4483e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| FROM alpine:latest AS agent-downloader | ||
| RUN wget -O /sentry-opentelemetry-agent.jar https://get.sentry.io/sentry-opentelemetry-agent.jar | ||
|
|
||
| FROM amazoncorretto:21 | ||
| ENV TZ="Asia/Seoul" | ||
|
|
||
| RUN mkdir -p /service/pida | ||
| RUN mkdir -p /service/pida /opt/sentry | ||
| COPY --from=agent-downloader /sentry-opentelemetry-agent.jar /opt/sentry/agent.jar | ||
| COPY pida-core/core-api/build/libs/core-api-0.0.1.jar /service/pida/core-api-0.0.1.jar | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| CMD java -jar -Xmx2048m /service/pida/core-api-0.0.1.jar | ||
| CMD java \ | ||
| -javaagent:/opt/sentry/agent.jar \ | ||
| -Dsentry.auto.init=false \ | ||
| -Xmx2048m \ | ||
| -jar /service/pida/core-api-0.0.1.jar | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,20 @@ | ||
| FROM alpine:latest AS agent-downloader | ||
| RUN wget -O /sentry-opentelemetry-agent.jar https://get.sentry.io/sentry-opentelemetry-agent.jar | ||
|
|
||
| FROM amazoncorretto:21 | ||
| ENV TZ="Asia/Seoul" | ||
|
|
||
| ARG PROFILE | ||
| ENV PROFILE=${PROFILE} | ||
|
|
||
| RUN mkdir -p /service/pida | ||
|
|
||
| RUN mkdir -p /service/pida /opt/sentry | ||
| COPY --from=agent-downloader /sentry-opentelemetry-agent.jar /opt/sentry/agent.jar | ||
| COPY pida-core/core-api/build/libs/core-api-0.0.1.jar /service/pida/core-api-0.0.1.jar | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| CMD java \ | ||
| -javaagent:/opt/sentry/agent.jar \ | ||
| -Dsentry.auto.init=false \ | ||
| -Dspring.profiles.active=${PROFILE} \ | ||
| -jar /service/pida/core-api-0.0.1.jar |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,18 @@ | ||
| plugins { | ||
| id("io.sentry.jvm.gradle") | ||
| } | ||
|
|
||
| val hasSentryToken = System.getenv("SENTRY_AUTH_TOKEN") != null | ||
|
|
||
| sentry { | ||
| includeSourceContext.set(hasSentryToken) | ||
| org.set("pida-za") | ||
| projectName.set("pida") | ||
| authToken.set(System.getenv("SENTRY_AUTH_TOKEN")) | ||
| } | ||
|
|
||
| val sentryAgent: Configuration by configurations.creating | ||
|
|
||
| tasks.getByName("bootJar") { | ||
| enabled = true | ||
| } | ||
|
|
@@ -6,7 +21,18 @@ tasks.getByName("jar") { | |
| enabled = false | ||
| } | ||
|
|
||
| tasks.register<Copy>("copySentryAgent") { | ||
| from(sentryAgent) | ||
| into(layout.buildDirectory.dir("agent")) | ||
| rename { "sentry-opentelemetry-agent.jar" } | ||
| } | ||
|
|
||
| tasks.named("build") { | ||
| dependsOn("copySentryAgent") | ||
| } | ||
|
Comment on lines
+24
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Gradle task copies the agent to Pick one approach:
๐ค Prompt for AI Agents |
||
|
|
||
| dependencies { | ||
| sentryAgent(libs.sentry.opentelemetry.agent) | ||
| implementation(libs.spring.boot.starter.web) | ||
| implementation(libs.spring.boot.starter.aop) | ||
| implementation(libs.spring.boot.starter.validation) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| dependencies { | ||
| implementation(libs.spring.boot.starter.actuator) | ||
| implementation(libs.micrometer.registry.prometheus) | ||
| implementation(libs.sentry.spring.boot.starter.jakarta) | ||
| implementation(project(":pida-core:core-domain")) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.pida.monitoring.sentry | ||
|
|
||
| import com.pida.support.error.AuthenticationErrorException | ||
| import com.pida.support.error.ErrorException | ||
| import io.sentry.Hint | ||
| import io.sentry.SentryEvent | ||
| import io.sentry.SentryOptions | ||
| import org.springframework.stereotype.Component | ||
|
|
||
| @Component | ||
| class SentryFingerprintCallback : SentryOptions.BeforeSendCallback { | ||
| override fun execute( | ||
| event: SentryEvent, | ||
| hint: Hint, | ||
| ): SentryEvent { | ||
| val exception = event.throwable ?: return event | ||
|
|
||
| val fingerprint = resolveFingerprint(exception) | ||
| if (fingerprint != null) { | ||
| event.fingerprints = fingerprint | ||
| } | ||
|
|
||
| return event | ||
| } | ||
|
|
||
| private fun resolveFingerprint(exception: Throwable): List<String>? = | ||
| when (exception) { | ||
| is ErrorException -> | ||
| listOf( | ||
| "ErrorException", | ||
| exception.errorType.kind.name, | ||
| exception.errorType.name, | ||
| ) | ||
|
|
||
| is AuthenticationErrorException -> | ||
| listOf( | ||
| "AuthenticationErrorException", | ||
| exception.authenticationErrorType.kind.name, | ||
| exception.authenticationErrorType.name, | ||
| ) | ||
|
|
||
| else -> null | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.