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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: OkHttp callback for Customising the Span #1478

Merged
merged 7 commits into from
May 25, 2021
Merged

Conversation

maciejwalkowiak
Copy link
Contributor

📜 Description

OkHttp callback for Customising the Span

💡 Motivation and Context

Fixes #1365

💚 How did you test it?

Unit tests.

📝 Checklist

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

@maciejwalkowiak maciejwalkowiak marked this pull request as ready for review May 17, 2021 14:02
import io.sentry.SpanStatus
import java.io.IOException
import okhttp3.Interceptor
import okhttp3.Response

class SentryOkHttpInterceptor(
private val hub: IHub = HubAdapter.getInstance()
private val hub: IHub = HubAdapter.getInstance(),
private val spanCustomizer: (span: ISpan) -> Unit = { }
Copy link
Contributor

Choose a reason for hiding this comment

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

what's about using a name that sort of matches our beforeSend and beforeBreadcrumb callbacks?
eg beforeSpan? cc @bruno-garcia

I believe this could also be an interface already available in the sentry package, it may be reused in other integrations, I'd not add to options though, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

2nd thing is that using Unit isn't the best definition if using it on Java, but as OkHttp is already written in Kotlin, I guess it's just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed with naming. I think Unit can stay.

@marandaneto
Copy link
Contributor

as @bruno-garcia came up with this callback after talking to a few people, let's get his review before merging it, looks good to me.

@@ -39,6 +41,7 @@ class SentryOkHttpInterceptor(
}
throw e
} finally {
span?.apply(beforeSpan)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way we can drop the span? Similar to how we do beforeSend and beforeBreadcrumb?

We would also need to pass some context to the callback, like the request (and resposne?) objects.

Some context: We're trying to add a way for a user to do:

if (request.url == "/health" || response.status == 200) {
return null;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point about dropping the span. url and status can be obtained from span but in less convenient way than with plain request and response. I'll change the implementation.

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.

OkHttp callback for Customising the Span
3 participants