Search in sources :

Example 1 with ChannelOperations

use of reactor.netty.channel.ChannelOperations in project pinpoint by naver.

the class HttpClientHandlerRequestWithBodyInterceptor method doInBeforeTrace.

@Override
public void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContext, Object target, Object[] args) {
    if (ArrayUtils.isEmpty(args)) {
        // Skip
        return;
    }
    // Set HttpClientOptions
    if (args[0] instanceof AsyncContextAccessor) {
        ((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
    }
    // Set hostname
    if (args[0] instanceof ChannelOperations) {
        try {
            final ChannelOperations channelOperations = (ChannelOperations) args[0];
            final InetSocketAddress inetSocketAddress = (InetSocketAddress) channelOperations.channel().remoteAddress();
            if (inetSocketAddress != null) {
                final String hostName = SocketAddressUtils.getHostNameFirst(inetSocketAddress);
                if (hostName != null) {
                    recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, HostAndPort.toHostAndPortString(hostName, inetSocketAddress.getPort()));
                }
            }
        } catch (Exception ignore) {
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) ChannelOperations(reactor.netty.channel.ChannelOperations)

Example 2 with ChannelOperations

use of reactor.netty.channel.ChannelOperations in project pinpoint by naver.

the class HttpClientRequestWrapper method toRemoteHost.

private String toRemoteHost() {
    if (request instanceof ChannelOperations) {
        try {
            final ChannelOperations channelOperations = (ChannelOperations) request;
            final InetSocketAddress inetSocketAddress = (InetSocketAddress) channelOperations.channel().remoteAddress();
            if (inetSocketAddress != null) {
                final StringBuilder sb = new StringBuilder();
                final String hostName = SocketAddressUtils.getHostNameFirst(inetSocketAddress);
                if (hostName != null) {
                    sb.append(hostName).append(":").append(inetSocketAddress.getPort());
                }
                return sb.toString();
            }
        } catch (Exception ignored) {
        }
    }
    return null;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ChannelOperations(reactor.netty.channel.ChannelOperations)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 ChannelOperations (reactor.netty.channel.ChannelOperations)2 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1