public void channelRead()

in apm-sniffer/optional-plugins/netty-http-4.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/netty/http/handler/NettyHttpRequestDecoderTracingHandler.java [64:99]


    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        try {
            if (TypeUtils.isFullHttpRequest(msg)) {
                FullHttpRequest request = (FullHttpRequest) msg;
                AbstractSpan span = createEntrySpan(ctx, request);
                if (NettyHttpPluginConfig.Plugin.NettyHttp.COLLECT_REQUEST_BODY) {
                    HttpDataCollectUtils.collectHttpRequestBody(request.headers(), request.content(), span);
                }
            } else if (TypeUtils.isHttpRequest(msg)) {
                // if headers before body arrive
                createEntrySpan(ctx, (HttpRequest) msg);
                ctx.channel().attr(AttributeKeys.HTTP_REQUEST_HEADER).set(((HttpRequest) msg).headers());
            } else if (TypeUtils.isLastHttpContent(msg)) {
                AbstractSpan span = ctx.channel().attr(AttributeKeys.HTTP_SERVER_SPAN).get();
                HttpHeaders headers = ctx.channel().attr(AttributeKeys.HTTP_REQUEST_HEADER).getAndSet(null);
                if (NettyHttpPluginConfig.Plugin.NettyHttp.COLLECT_REQUEST_BODY) {
                    HttpDataCollectUtils.collectHttpRequestBody(headers, ((LastHttpContent) msg).content(), span);
                }
            }
        } catch (Exception e) {
            LOGGER.error("Fail to trace netty http request", e);
        } finally {
            try {
                ctx.fireChannelRead(msg);
            } catch (Throwable throwable) {
                AbstractSpan span = ctx.channel().attr(AttributeKeys.HTTP_SERVER_SPAN).getAndSet(null);
                if (span != null) {
                    span.errorOccurred();
                    span.log(throwable);
                    Tags.HTTP_RESPONSE_STATUS_CODE.set(span, 500);
                    span.asyncFinish();
                }
                throw throwable;
            }
        }
    }