-
Notifications
You must be signed in to change notification settings - Fork 277
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
...n/java/datadog/trace/instrumentation/http_url_connection/MessageHeadersInjectAdapter.java
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
.../java/datadog/trace/instrumentation/http_url_connection/SunHttpClientInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package datadog.trace.instrumentation.http_url_connection; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import io.opentracing.Span; | ||
import io.opentracing.Tracer; | ||
import io.opentracing.propagation.Format; | ||
import io.opentracing.propagation.TextMap; | ||
import io.opentracing.util.GlobalTracer; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import sun.net.www.MessageHeader; | ||
import sun.net.www.http.HttpClient; | ||
|
||
@AutoService(Instrumenter.class) | ||
public class SunHttpClientInstrumentation extends Instrumenter.Default { | ||
|
||
public SunHttpClientInstrumentation() { | ||
super("httpurlconnection"); | ||
} | ||
|
||
@Override | ||
protected boolean defaultEnabled() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public ElementMatcher typeMatcher() { | ||
return named("sun.net.www.http.HttpClient"); | ||
} | ||
|
||
@Override | ||
public String[] helperClassNames() { | ||
return new String[] { | ||
SunHttpClientInstrumentation.class.getName() + "$MessageHeadersInjectAdapter" | ||
}; | ||
} | ||
|
||
@Override | ||
public Map<ElementMatcher, String> transformers() { | ||
return Collections.<ElementMatcher, String>singletonMap( | ||
isMethod() | ||
.and(isPublic()) | ||
.and(named("writeRequests")) | ||
.and(takesArgument(0, named("sun.net.www.MessageHeader"))) | ||
// exclude the delegating method: | ||
.and(takesArguments(1).or(takesArguments(2))), | ||
InjectAdvice.class.getName()); | ||
} | ||
|
||
public static class InjectAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void inject( | ||
@Advice.Argument(0) final MessageHeader header, @Advice.This final HttpClient client) { | ||
final Tracer tracer = GlobalTracer.get(); | ||
final Span span = tracer.activeSpan(); | ||
|
||
if (span != null) { | ||
tracer.inject( | ||
span.context(), Format.Builtin.HTTP_HEADERS, new MessageHeadersInjectAdapter(header)); | ||
} | ||
} | ||
} | ||
|
||
public static class MessageHeadersInjectAdapter implements TextMap { | ||
|
||
private final MessageHeader header; | ||
|
||
public MessageHeadersInjectAdapter(final MessageHeader header) { | ||
this.header = header; | ||
} | ||
|
||
@Override | ||
public void put(final String key, final String value) { | ||
header.setIfNotSet(key, value); | ||
} | ||
|
||
@Override | ||
public Iterator<Map.Entry<String, String>> iterator() { | ||
throw new UnsupportedOperationException( | ||
"This class should be used only with tracer#inject()"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.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.
I made it threadsafe. Though I'm not sure if it's a problem synchronizing on the connection.