-
-
Notifications
You must be signed in to change notification settings - Fork 454
Add Ktor client integration #4527
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
base: main
Are you sure you want to change the base?
Conversation
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
c3b3ac8 | 433.74 ms | 490.08 ms | 56.34 ms |
f316c06 | 427.39 ms | 464.94 ms | 37.55 ms |
bc4c3ab | 420.27 ms | 462.92 ms | 42.65 ms |
64151fc | 417.40 ms | 436.90 ms | 19.50 ms |
94e993e | 404.49 ms | 439.62 ms | 35.13 ms |
1fa99ff | 371.94 ms | 406.67 ms | 34.74 ms |
df1fbd1 | 407.84 ms | 424.93 ms | 17.09 ms |
ec32652 | 354.67 ms | 385.71 ms | 31.04 ms |
1df63ce | 429.52 ms | 485.02 ms | 55.50 ms |
9647976 | 403.48 ms | 420.36 ms | 16.88 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
c3b3ac8 | 1.58 MiB | 2.09 MiB | 518.90 KiB |
f316c06 | 1.58 MiB | 2.09 MiB | 519.08 KiB |
bc4c3ab | 1.58 MiB | 2.09 MiB | 518.90 KiB |
64151fc | 1.58 MiB | 2.09 MiB | 519.31 KiB |
94e993e | 1.58 MiB | 2.09 MiB | 519.31 KiB |
1fa99ff | 1.58 MiB | 2.09 MiB | 519.27 KiB |
df1fbd1 | 1.58 MiB | 2.09 MiB | 519.08 KiB |
ec32652 | 1.58 MiB | 2.09 MiB | 518.89 KiB |
1df63ce | 1.58 MiB | 2.09 MiB | 518.90 KiB |
9647976 | 1.58 MiB | 2.09 MiB | 519.31 KiB |
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
sentry-ktor/src/main/java/io/sentry/ktor/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
afb2f01
to
8b75851
Compare
7945398
to
8499b5d
Compare
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.
LGTM, but there's one caveat we have to consider: If someone uses ktor with the OkHttp engine, we'd be potentially double-instrumenting the http calls, especially with SAGP in place. Could be a follow up PR, but I guess we have to add some protection against that case (like checking if engine == OkHttp and platform == Android then don't instrument OR retrieve the list of interceptors/eventListner from OkHttp client if possible, and check if ours are already there)
Good call. Working on this and trying to keep the extra dependencies at a minimum. I think we'll need to bring in the library containing the OkHttp client engine at least, which probably also depends on OkHttp itself. |
@sentry review |
PR DescriptionThis pull request introduces a new integration for the Sentry error monitoring platform with the Ktor HTTP client. The goal is to automatically capture unhandled exceptions, create breadcrumbs for HTTP requests, and support distributed tracing for applications using Ktor's client. Click to see moreKey Technical ChangesThe key technical changes include: 1. Creation of a Architecture DecisionsThe architectural decisions include: 1. Using Ktor's Dependencies and InteractionsThis integration depends on the Ktor HTTP client library, the Sentry Java SDK, and the kotlinx.coroutines library. It interacts with the Sentry SDK to capture exceptions, create breadcrumbs, and manage spans. It also interacts with the Ktor client pipeline to intercept requests and responses. Risk ConsiderationsPotential risks include: 1. Performance overhead due to span creation and breadcrumb generation. 2. Memory issues if response bodies are too large when capturing errors. 3. Thread safety issues if scopes are accessed concurrently. 4. Compatibility issues with future versions of Ktor or the Sentry SDK. 5. Incorrect configuration leading to excessive error reporting or missed errors. Notable Implementation DetailsNotable implementation details include: 1. The use of |
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt
Outdated
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Show resolved
Hide resolved
sentry-samples/sentry-samples-ktor-client/src/main/java/io/sentry/samples/ktorClient/Main.kt
Outdated
Show resolved
Hide resolved
sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt
Outdated
Show resolved
Hide resolved
28e039a
to
bb52a1b
Compare
10fa401
to
8a42315
Compare
@romtsn Please let me know what you think about this approach: The approach is still not perfect because if the config block has some side effects, we would trigger them when creating the fake client. As a next step I want to set up an app using ProGuard and SAGP to ensure this works as intended. |
📜 Description
Add a Ktor client integration.
Functionality, options and tests are similar to our OkHttp integration.
💡 Motivation and Context
Part of #2684
💚 How did you test it?
End to end and manual tests
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps