-
Notifications
You must be signed in to change notification settings - Fork 879
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
Implement HTTP resend spec for Reactor Netty (excl CONNECT spans) #8111
Merged
mateuszrzeszutek
merged 10 commits into
open-telemetry:main
from
mateuszrzeszutek:reactor-netty-resend-poc
Jul 21, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bd53c89
Implement HTTP resend spec for Reactor Netty (excl CONNECT spans)
e978350
fix tests
65a0d8a
more stable trace ordering
c7290cc
Fix broken span ordering
3457d7e
fix tests
d1ff9c6
errorprone
e8a61c3
add private
70be753
Merge remote-tracking branch 'upstream/main' into reactor-netty-resen…
trask 9ca0c17
Spotless
trask 5c267fb
Merge branch 'main' into reactor-netty-resend-poc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
77 changes: 77 additions & 0 deletions
77
...io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/InstrumentationContexts.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,77 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0; | ||
|
||
import static io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0.ReactorNettySingletons.instrumenter; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientResend; | ||
import java.util.Queue; | ||
import java.util.concurrent.ArrayBlockingQueue; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.annotation.Nullable; | ||
import reactor.netty.http.client.HttpClientRequest; | ||
import reactor.netty.http.client.HttpClientResponse; | ||
|
||
final class InstrumentationContexts { | ||
|
||
private static final Logger logger = Logger.getLogger(InstrumentationContexts.class.getName()); | ||
|
||
private volatile Context parentContext; | ||
// on retries, reactor-netty starts the next resend attempt before it ends the previous one (i.e. | ||
// it calls the callback functions in that order); thus for a short moment there can be 2 | ||
// coexisting HTTP client spans | ||
private final Queue<RequestAndContext> clientContexts = new ArrayBlockingQueue<>(2, true); | ||
|
||
void initialize(Context parentContext) { | ||
this.parentContext = HttpClientResend.initialize(parentContext); | ||
} | ||
|
||
Context getParentContext() { | ||
return parentContext; | ||
} | ||
|
||
@Nullable | ||
Context getClientContext() { | ||
RequestAndContext requestAndContext = clientContexts.peek(); | ||
return requestAndContext == null ? null : requestAndContext.context; | ||
} | ||
|
||
@Nullable | ||
Context startClientSpan(HttpClientRequest request) { | ||
Context parentContext = this.parentContext; | ||
Context context = null; | ||
if (instrumenter().shouldStart(parentContext, request)) { | ||
context = instrumenter().start(parentContext, request); | ||
if (!clientContexts.offer(new RequestAndContext(request, context))) { | ||
// should not ever happen in reality | ||
String message = | ||
"Could not instrument HTTP client request; not enough space in the request queue"; | ||
logger.log(Level.FINE, message); | ||
breedx-splk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
instrumenter().end(context, request, null, new IllegalStateException(message)); | ||
} | ||
} | ||
return context; | ||
} | ||
|
||
void endClientSpan(@Nullable HttpClientResponse response, @Nullable Throwable error) { | ||
RequestAndContext requestAndContext = clientContexts.poll(); | ||
if (requestAndContext != null) { | ||
breedx-splk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
instrumenter().end(requestAndContext.context, requestAndContext.request, response, error); | ||
} | ||
} | ||
|
||
static final class RequestAndContext { | ||
final HttpClientRequest request; | ||
final Context context; | ||
|
||
RequestAndContext(HttpClientRequest request, Context context) { | ||
this.request = request; | ||
this.context = context; | ||
} | ||
} | ||
} |
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
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.
Here's where the connection span will be added -- similar to the
ConnectionErrorSpanInterceptor
in the OkHttp instrumentation, it's only emitted on error and when there were no HTTP requests made.