Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add OkHttp client application interceptor #1330

Merged
merged 13 commits into from Mar 18, 2021

Conversation

marandaneto
Copy link
Contributor

@marandaneto marandaneto commented Mar 16, 2021

馃摐 Description

Create spans and add breadcrumbs
A sort of guideline: getsentry/develop#254

馃挕 Motivation and Context

馃挌 How did you test it?

Unit tests, sample project.

馃摑 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

馃敭 Next steps

Resolve TODOs in the code.


val breadcrumb = Breadcrumb.http(request.url.toString(), request.method, code)
request.body?.contentLength().ifHasValidLength {
breadcrumb.setData("requestBodySize", it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how really valuable this information is, both for requests and responses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: collect ideas
// https://github.com/square/okhttp/blob/master/okhttp-logging-interceptor/src/main/kotlin/okhttp3/logging/HttpLoggingInterceptor.kt
// TODO: add package to options? how do we get options? does it even make sense?
// sdkVersion?.addPackage("maven:io.sentry:sentry-android-timber", BuildConfig.VERSION_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do it through Hub#getOptions but I somehow doubt it makes sense to add it for each and every instrumentation we do. I am not the one with access to reporting tools though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for debugging (when there are events, we know each packages were being used).
or usage of our packages to take decisions like dropping a version or stuff like this.

true, forgot about Hub#getOptions, let's add then :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerns:

  • we would need to add it to all events and transactions
  • since packages on sdkVersions is a list (not set) creating multiple interceptors would add multiple same packages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, lets keep without it for now then and only do it when the OkHttp integration is able to captureEvent then, which would be then an integration for now it just works as an interceptor.

@maciejwalkowiak maciejwalkowiak changed the title Feat: okhttp integration Feat: Add OkHttp client application interceptor Mar 17, 2021
@maciejwalkowiak maciejwalkowiak marked this pull request as ready for review March 17, 2021 12:18
@maciejwalkowiak
Copy link
Contributor

@marandaneto I left the TODOs you created as they are more like open questions. Other than that, interceptor is working, breadcrumbs are added, everything is tested.

span?.finish(SpanStatus.fromHttpStatusCode(code, SpanStatus.INTERNAL_ERROR))
}

val breadcrumb = Breadcrumb.http(request.url.toString(), request.method, code)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if it makes sense to call Breadcrumb.http without code if its -1, otherwise its adding -1 which does not make sense, or Breadcrumb.http inside of it checks if its -1, or changing it to Integer and check if its null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃憤 +1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to always add breadcrumb even if call fails with network error.

@marandaneto
Copy link
Contributor Author

@maciejwalkowiak run apiDump and we are good

@marandaneto
Copy link
Contributor Author

I cannot approve my own PR but you have my amen

@maciejwalkowiak maciejwalkowiak merged commit fa1b8b7 into main Mar 18, 2021
@maciejwalkowiak maciejwalkowiak deleted the feat/okhttp-integration branch March 18, 2021 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants