private void propagateRequestSideLog(RequestLog child) { child.addListener(log -> startRequest0(log.channel(), log.sessionProtocol(), null, log.requestStartTimeNanos(), log.requestStartTimeMicros(), true), REQUEST_START); child.addListener(log -> serializationFormat(log.serializationFormat()), SCHEME); child.addListener(log -> requestFirstBytesTransferred(log.requestFirstBytesTransferredTimeNanos()), REQUEST_FIRST_BYTES_TRANSFERRED); child.addListener(log -> requestHeaders(log.requestHeaders()), REQUEST_HEADERS); child.addListener(log -> requestContent(log.requestContent(), log.rawRequestContent()), REQUEST_CONTENT); child.addListener(log -> endRequest0(log.requestCause(), log.requestEndTimeNanos()), REQUEST_END); }
@Override public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Exception { final Span span = tracer.nextSpan(); injector.inject(span.context(), req.headers()); // For no-op spans, we only need to inject into headers and don't set any other attributes. if (span.isNoop()) { return delegate().execute(ctx, req); } final String method = ctx.method().name(); span.kind(Kind.CLIENT).name(method); ctx.log().addListener(log -> SpanContextUtil.startSpan(span, log), RequestLogAvailability.REQUEST_START); // Ensure the trace context propagates to children ctx.onChild(RequestContextCurrentTraceContext::copy); ctx.log().addListener(log -> { SpanTags.logWireSend(span, log.requestFirstBytesTransferredTimeNanos(), log); SpanTags.logWireReceive(span, log.responseFirstBytesTransferredTimeNanos(), log); finishSpan(span, log); }, RequestLogAvailability.COMPLETE); try (SpanInScope ignored = tracer.withSpanInScope(span)) { return delegate().execute(ctx, req); } }
@Override public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception { final TraceContextOrSamplingFlags contextOrFlags = extractor.extract(req.headers()); final Span span = contextOrFlags.context() != null ? tracer.joinSpan(contextOrFlags.context()) : tracer.nextSpan(contextOrFlags); // For no-op spans, nothing special to do. if (span.isNoop()) { return delegate().serve(ctx, req); } final String method = ctx.method().name(); span.kind(Kind.SERVER).name(method); ctx.log().addListener(log -> SpanContextUtil.startSpan(span, log), RequestLogAvailability.REQUEST_START); // Ensure the trace context propagates to children ctx.onChild(RequestContextCurrentTraceContext::copy); ctx.log().addListener(log -> { SpanTags.logWireReceive(span, log.requestFirstBytesTransferredTimeNanos(), log); SpanTags.logWireSend(span, log.responseFirstBytesTransferredTimeNanos(), log); SpanContextUtil.closeSpan(span, log); }, RequestLogAvailability.COMPLETE); try (SpanInScope ignored = tracer.withSpanInScope(span)) { return delegate().serve(ctx, req); } } }