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

Separate span for input and output streams. #425

Merged
merged 2 commits into from Aug 7, 2018

Conversation

tylerbenson
Copy link
Contributor

@realark I've separated the input and output streams as you requested.

I also pushed the Tracer.inject point a bit deeper to HttpClient.writeRequests where we know that it's actually happening. Let me know if you'd rather I leave that how you had it.

@tylerbenson tylerbenson added this to the 0.13.0 milestone Aug 3, 2018
}
// We get here in cases where connect() is called first.
// We need to inject headers now because after connected=true no more headers can be
// added.
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I reading the code correctly and header injection is no longer happening in this class? And in fact it happens deeper so this code really doesn't control they way headers are injected anymore. In fact as far as I can see all this switch is controlling is creation of multiple spans when connect/getInputSpan/getOutputSpan are called multiple times.

If above is correct you may want to rewrite this comment to better clarify what is happening here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Is it better?

@@ -187,16 +187,9 @@ public static HttpURLState get(final HttpURLConnection connection) {
return state;
}

public boolean hasDoneIO = false;
public boolean calledOutputStream = false;
public boolean calledInputStream = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Above comment says // not thread-safe, but neither is HttpURLConnection. I think this is only partially true: sun.net.www.protocol.http.HttpURLConnection seems to be thread-safe. That's probably not a huge issue in reality, but comment may be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it threadsafe. Though I'm not sure if it's a problem synchronizing on the connection.

final Tracer tracer = GlobalTracer.get();
final Span span = tracer.activeSpan();
// Use the active span, not the one created in SpanStartAdvice,
// since we aren't sure that span will complete.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please clarify what this comment means and what is SpanStartAdvice it is referring to?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the purpose of this instrumentation to add header injection in cases where connect() is called before get*Stream()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That comment is from a previous attempt at instrumenting the sun HttpClient further. I've removed it. Sorry for the confusion.

Copy link
Contributor

@mar-kolya mar-kolya left a comment

Choose a reason for hiding this comment

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

Just couple of clarifications in comments

Copy link
Contributor

@realark realark left a comment

Choose a reason for hiding this comment

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

Nice work!

Just to confirm:

  • Do we only create connect spans on the actual connection (when the connection is not cached)?
  • Does getInputStream do header injection in cases where the connection is cached (keep-alive) and connect() is called before getInputStream()?

Copy link
Contributor

@mar-kolya mar-kolya left a comment

Choose a reason for hiding this comment

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

Thanks!

@tylerbenson tylerbenson merged commit 9d85484 into master Aug 7, 2018
@tylerbenson tylerbenson deleted the tyler/httpurlconnection branch August 7, 2018 02:33
@tylerbenson
Copy link
Contributor Author

@realark

Do we only create connect spans on the actual connection (when the connection is not cached)?

yes, it will create a connect span if connect is called. This is to ensure a span exists for propagation.

Does getInputStream do header injection in cases where the connection is cached (keep-alive) and connect() is called before getInputStream()?

It shouldn't. It only does header injection right before the headers are written out to the socket, so in your question, it would be when connect is called.

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

3 participants