-
Notifications
You must be signed in to change notification settings - Fork 828
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
Reactor Netty: emit actual HTTP client spans spans on connection errors #9063
Merged
trask
merged 3 commits into
open-telemetry:main
from
mateuszrzeszutek:reactor-netty-part-2
Aug 2, 2023
Merged
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions
20
...y/instrumentation/netty/v4/common/internal/client/NettyConnectionInstrumentationFlag.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,20 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.netty.v4.common.internal.client; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public enum NettyConnectionInstrumentationFlag { | ||
ENABLED, | ||
ERROR_ONLY, | ||
DISABLED; | ||
|
||
public static NettyConnectionInstrumentationFlag enabledOrErrorOnly(boolean b) { | ||
return b ? ENABLED : ERROR_ONLY; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...telemetry/instrumentation/netty/v4/common/internal/client/NoopConnectionInstrumenter.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,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.netty.v4.common.internal.client; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.netty.channel.Channel; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.netty.common.internal.NettyConnectionRequest; | ||
import javax.annotation.Nullable; | ||
|
||
enum NoopConnectionInstrumenter implements NettyConnectionInstrumenter { | ||
INSTANCE; | ||
|
||
@Override | ||
public boolean shouldStart(Context parentContext, NettyConnectionRequest request) { | ||
return false; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
@Override | ||
public Context start(Context parentContext, NettyConnectionRequest request) { | ||
return parentContext; | ||
} | ||
|
||
@Override | ||
public void end( | ||
Context context, | ||
NettyConnectionRequest request, | ||
Channel channel, | ||
@Nullable Throwable error) {} | ||
} |
28 changes: 28 additions & 0 deletions
28
...io/opentelemetry/instrumentation/netty/v4/common/internal/client/NoopSslInstrumenter.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,28 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.netty.v4.common.internal.client; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.opentelemetry.context.Context; | ||
import javax.annotation.Nullable; | ||
|
||
enum NoopSslInstrumenter implements NettySslInstrumenter { | ||
INSTANCE; | ||
|
||
@Override | ||
public boolean shouldStart(Context parentContext, NettySslRequest request) { | ||
return false; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
@Override | ||
public Context start(Context parentContext, NettySslRequest request) { | ||
return parentContext; | ||
} | ||
|
||
@Override | ||
public void end(Context context, NettySslRequest request, @Nullable Throwable error) {} | ||
} |
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
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
92 changes: 92 additions & 0 deletions
92
...ntelemetry/javaagent/instrumentation/reactornetty/v1_0/FailedRequestWithUrlMakerTest.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,92 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import reactor.netty.http.client.HttpClientConfig; | ||
import reactor.netty.http.client.HttpClientRequest; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class FailedRequestWithUrlMakerTest { | ||
|
||
@Mock HttpClientConfig config; | ||
@Mock HttpClientRequest originalRequest; | ||
|
||
@Test | ||
void shouldUseAbsoluteUri() { | ||
when(config.uri()).thenReturn("https://opentelemetry.io"); | ||
|
||
HttpClientRequest request = FailedRequestWithUrlMaker.create(config, originalRequest); | ||
|
||
assertThat(request.resourceUrl()).isEqualTo("https://opentelemetry.io"); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"https://opentelemetry.io", "https://opentelemetry.io/"}) | ||
void shouldPrependBaseUrl(String baseUrl) { | ||
when(config.baseUrl()).thenReturn(baseUrl); | ||
when(config.uri()).thenReturn("/docs"); | ||
|
||
HttpClientRequest request = FailedRequestWithUrlMaker.create(config, originalRequest); | ||
|
||
assertThat(request.resourceUrl()).isEqualTo("https://opentelemetry.io/docs"); | ||
} | ||
|
||
@Test | ||
void shouldPrependRemoteAddress() { | ||
when(config.baseUrl()).thenReturn("/"); | ||
when(config.uri()).thenReturn("/docs"); | ||
Supplier<InetSocketAddress> remoteAddress = | ||
() -> InetSocketAddress.createUnresolved("opentelemetry.io", 8080); | ||
doReturn(remoteAddress).when(config).remoteAddress(); | ||
when(config.isSecure()).thenReturn(true); | ||
|
||
HttpClientRequest request = FailedRequestWithUrlMaker.create(config, originalRequest); | ||
|
||
assertThat(request.resourceUrl()).isEqualTo("https://opentelemetry.io:8080/docs"); | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(DefaultPortsArguments.class) | ||
void shouldSkipDefaultPorts(int port, boolean isSecure) { | ||
when(config.baseUrl()).thenReturn("/"); | ||
when(config.uri()).thenReturn("/docs"); | ||
Supplier<InetSocketAddress> remoteAddress = | ||
() -> InetSocketAddress.createUnresolved("opentelemetry.io", port); | ||
doReturn(remoteAddress).when(config).remoteAddress(); | ||
when(config.isSecure()).thenReturn(isSecure); | ||
|
||
HttpClientRequest request = FailedRequestWithUrlMaker.create(config, originalRequest); | ||
|
||
assertThat(request.resourceUrl()) | ||
.isEqualTo((isSecure ? "https" : "http") + "://opentelemetry.io/docs"); | ||
} | ||
|
||
static final class DefaultPortsArguments implements ArgumentsProvider { | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { | ||
return Stream.of(arguments(80, false), arguments(443, true)); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
Why does this one not use the config?
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.
It's a library instrumentation, I think it just can't implement the connection telemetry stuff.