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

httpurlconnection create one span per io #386

Merged
merged 6 commits into from
Jul 27, 2018
Merged

Conversation

realark
Copy link
Contributor

@realark realark commented Jul 18, 2018

  • Use the same operationName for all httpurlconnection calls
  • use the connected field and helper hash map to determine if io has occurred
  • Add a test for spring rest template
  • Skipped instrumentation for a wrapper class which does not update its connected field

The way we're using connected is an implementation detail of HttpURLConnection. There's no way to cleanly do this at the api level (that I know of). Not great, but it works for all builtin implementations of HttpURLConnection.

Note that this will also not capture additional reads of the stream after the response stream is returned.

@gary-huang @tylerbenson Let me know what you think. Any concerns or anything you can think of to break this?

@realark realark added the tag: do not merge Do not merge changes label Jul 18, 2018
@realark realark added this to the 0.11.0 milestone Jul 18, 2018
@realark realark force-pushed the ark/httpurlconnection branch 4 times, most recently from c7c41c5 to f43c4d6 Compare July 19, 2018 01:42
@realark realark removed the tag: do not merge Do not merge changes label Jul 19, 2018
Copy link
Contributor

@gary-huang gary-huang left a comment

Choose a reason for hiding this comment

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

Looks good to me, just left a thought on potential problems, could be nothing.

try {
// response code field is sometimes not populated until the getResponseCode method is explicitly called.
// Calling getResponseCode() here will not trigger additional instrumentation because we have not reset the depth map.
Tags.HTTP_STATUS.set(span, thiz.getResponseCode());
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this cause a side affect to the users by calling getResponseCode prematurely?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also concerned about this... getResponseCode() has some unfortunate side-effects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getResponseCode() causes the response to be parsed, caching the result in the responseCode field. Is the concern the additional work done to parse and cache the response code, or is there something else to consider?

Copy link
Contributor

Choose a reason for hiding this comment

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

@realark: I think we may have been there before, e.g. 9ff09b9

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 to know, thanks. I'll revert back to using the field. We'll backlog some additional work to better handle some of the doOutput=true corner cases.

@mar-kolya mar-kolya modified the milestones: 0.11.0, 0.12.0 Jul 19, 2018
@realark
Copy link
Contributor Author

realark commented Jul 19, 2018

@gary-huang @tylerbenson Ran into some trouble in the case where connect() is called first. There doesn't seem to be an easy to way to capture capture the bulk of the i/o and do distributed tracing.

Solution for now:

  • In connect() first cases, create two spans. One for connect() and one for i/o
  • Disable httpurlconnection as a top-level span (the two-span case would cause confusion at the top-level).
  • Use a weak-key map to store httpurlconnection state.

}
}
span(2) {
operationName "http.request"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there two spans for a single request?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the case where connect() is called before getInputStream(). We can change the instrumentation to only trace getInputStream(), but we won't be able to inject headers at that point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should the two spans have different operation names (or some other way to distinguish them) in that case?

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 idea. I used http.request.connect for those cases.

In the future I think we can handle this use-case without creating two spans but it will require some follow-on work.

@tylerbenson
Copy link
Contributor

:shipit:

@realark realark force-pushed the ark/httpurlconnection branch 2 times, most recently from 5241a37 to 9d0f343 Compare July 25, 2018 15:31
@realark realark merged commit af2f07c into master Jul 27, 2018
@realark realark deleted the ark/httpurlconnection branch July 27, 2018 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants