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

Add option to create span on new netty connection #3707

Merged
merged 8 commits into from
Jul 30, 2021

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Jul 28, 2021

Resolves #3319
Currently we create a zero length span when netty fails to connect and not inside a client span. This pr adds an option to capture a span around netty establishing connection.

Copy link
Contributor

@iNikem iNikem left a comment

Choose a reason for hiding this comment

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

Do I understand correctly:

  • If always-create-connect-span=true then we create span both for successful and failed connections and their durations are "true", not 0ms?
  • if always-create-connect-span=false we still create span for failed connection with 0 duration?

@laurit
Copy link
Contributor Author

laurit commented Jul 28, 2021

@iNikem yes that is correct.

@@ -52,7 +53,7 @@ public Context startSpan(Context parentContext, ChannelHandlerContext ctx, HttpR
}

public void connectionFailure(Context parentContext, Channel channel, Throwable throwable) {
SpanBuilder spanBuilder = spanBuilder(parentContext, "CONNECT", CLIENT);
SpanBuilder spanBuilder = spanBuilder(parentContext, "CONNECT", INTERNAL);
Copy link
Member

Choose a reason for hiding this comment

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

why INTERNAL over CLIENT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we always create connection span it could be nested under a client span so using INTERNAL. When creating connection span only for failure it could be kept as CLIENT though as the connection failed it shouldn't have a child SERVER span so changed this also to INTERNAL.

Copy link
Contributor

Choose a reason for hiding this comment

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

As we currently suppress nested CLIENT spans, we cannot have these new spans as CLIENT. Because they will be suppressed almost always. So we should have them INTERNAL for now.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to keep this one here as CLIENT, and the other one can be INTERNAL for now until we support nested CLIENT spans in #3691.

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#spankind:

CLIENT - Indicates that the span describes a request to some remote service
INTERNAL - Indicates that the span represents an internal operation within an application

SocketAddress remoteAddress,
Channel channel,
Throwable throwable) {
if (context != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: using alwaysCreateConnectSpan will probably allow JIT to skip the else part easily when that property is true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added alwaysCreateConnectSpan check, though I suspect that it won't change much for jit as I believe it speculatively removes branches that have not executed anyway.

@@ -25,6 +32,9 @@
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isConstructor(), BootstrapInstrumentation.class.getName() + "$InitAdvice");
transformer.applyAdviceToMethod(
named("doConnect").and(takesArgument(0, named("java.net.SocketAddress"))),
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
named("doConnect").and(takesArgument(0, named("java.net.SocketAddress"))),
named("doConnect").and(takesArgument(0, SocketAddress.class)),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed.

}

def cleanupSpec() {
eventLoopGroup?.shutdownGracefully()
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for eventLoopGroup to be null? Is that ? needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it, I guess I have developed a habit of adding too many of these to cleanupSpec as npe in cleanupSpec is fairly common when something fails during initialization

import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class ReactorNettyTracer extends BaseTracer {
Copy link
Member

Choose a reason for hiding this comment

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

can you change this to Instrumenter, or add it to #2713?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to #2713

@iNikem iNikem merged commit a04a7a6 into open-telemetry:main Jul 30, 2021
@laurit laurit deleted the netty-connect-span branch July 30, 2021 10:22
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.

Create spans on new Netty connection
4 participants