pinpoint-apm / pinpoint

APM, (Application Performance Management) tool for large-scale distributed systems.
https://pinpoint-apm.gitbook.io/
Apache License 2.0
13.29k stars 3.75k forks source link

Can I add the Pinpoint-TraceID header to the response header through the pinpoint agent? #9223

Open linux0x5c opened 1 year ago

linux0x5c commented 1 year ago

I want to see the TraceID of pinpoint through the client browser. Can I add this response header through the pinpoint agent configuration? If not, is there any API interface that can obtain the TraceID of this request?

emeroad commented 1 year ago

Currently there is no such feature, It probably won't be difficult to develop.

public class ServletResponseListener<RESP> {
    public void destroyed(RESP response, final Throwable throwable, final int statusCode) {
        //~~~
        final Trace trace = this.traceContext.currentRawTraceObject();
        if (trace == null) {
            return;
        }

        if (trace.canSampled()) {
            final SpanRecorder spanRecorder = trace.getSpanRecorder();
            this.httpStatusCodeRecorder.record(spanRecorder, statusCode);
            this.serverResponseHeaderRecorder.recordHeader(spanRecorder, response);
            // Dump traceId to Response
            if (enableDump) {
                TraceId traceId = trace.getTraceId();
                // Add setHeader API
                serverResponseHeaderRecorder.setHeader(response, "Pinpoint-Response-TraceID", traceId.toString());
            }
        }
    }
}

How about developing this feature?

linux0x5c commented 1 year ago

@emeroad This is an exciting feature that extracts Trace-IDs directly from the browser's debug mode, allowing us to quickly locate problems,thanks.