Closed lfzm closed 6 years ago
@aqa510415008 See wiki https://github.com/TomPallister/Ocelot/wiki/RequestId client sending a request id in the form of a header,This is a sample ,Http header RequestId is OcelotRequestId http://api.xx.com/api/right/useroperations?systemid=25&username=xxxx HTTP/1.1 Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjZCN0FDQzUyMDMwNUJGREI0RjcyNTJEQUVCMjE3N0NDMDkxRkFBRTEiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJhM3JNVWdNRnY5dFBjbExhNnlGM3pBa2ZxdUUifQ.eyJuYmYiOjE0OTQ1NTk1NDEsImV4cCI6MTQ5NzE1MTU0MSwiaXNzIjoiaHR0cDovLzEwLjEyNS4zMi4xMjE6NTAwMCIsImF1ZCI6WyJodHRwOi8vMTAuMTI1LjMyLjEyMTo1MDAwL3Jlc291cmNlcyIsImxtY29yZSJdLCJjbGllbnRfaWQiOiI1OTdjMjQyOWY0YjI3ZDc0Iiwic2NvcGUiOlsibG1jb3JlIl19.WgXKcNjniclV0ZgXfU9KiQoHb3E00FHQkxL2djacE8T_YqDa6Z0HvCDdGM0x-xvkiGW0fQubF40rOmR_6x4Sb0It5QNT238thkmnEfmo9galLafTRUdeKNxsqBMxlbEIVVhNaT6ZzAVmnEXcgf8uVRuADaUY4b2-pssX1PYjWxs0nQFHLV_KG8kjL5e4y49zBPlHpkqBTsEwrfU-ccYnRXVp7SDxTQC-xFl1Piz2gtOtiAuynGdFYpZe3UaNXAdkU0P45tN9CCjrvqYpNJY9WEO1oIFZ0Pazn-cPwsmxt-hcVq6VCOcOHpDjt4yuMwF5rLt6tj82BfhvoLI5U6Ag client_id: 597c2429f4b27d74 RequestId: e2d38067-3fff-4844-920e-f566aad6c71c
@geffzhang Thank you, you mean, RequestId need to go with the client head with it?
@aqa510415008 yes,"Requestidkey" in the Global configuration: "RequestID", which tells the gateway to find a header and use its value as a request/correlation identifier for the requested trace
@aqa510415008 thanks for the question.
@geffzhang thank you for helping! I really appreciate the support.
@TomPallister @geffzhang Thank you for your answer。 1、What is the difference between "Requestidkey" and RequestIdMiddleware set in the global configuration? I debug found that the middleware can get the RequestID。 2、In the client did not give "RequestId", why do not set the gateway "RequestId". But in the log print as "OcelotRequestId - not set"? This is not easy to query the log. 3、The client sends "RequestId" at the Http header (below the head), and the result is the same as "OcelotRequestId - not set". I analyzed the Ocelot code found "HttpDataRepository.Add ()" This class did not put "RequestId" into it.
GET /test1/1 HTTP/1.1
Host: localhost:56388
RequestId: e2d38067-3fff-4844-920e-f566aad6c71c
client_id: 123123
Cache-Control: no-cache
Postman-Token: a3835f54-718d-bc58-b248-91338fe6f482
private void SetOcelotRequestId(HttpContext context)
{
// if get request ID is set on upstream request then retrieve it
var key = DownstreamRoute.ReRoute.RequestIdKey ?? DefaultRequestIdKey.Value;
StringValues upstreamRequestIds;
if (context.Request.Headers.TryGetValue(key, out upstreamRequestIds))
{
context.TraceIdentifier = upstreamRequestIds.First();
}
// set request ID on downstream request, if required
var requestId = new RequestId(DownstreamRoute?.ReRoute?.RequestIdKey, context.TraceIdentifier);
if (ShouldAddRequestId(requestId, DownstreamRequest.Headers))
{
AddRequestIdHeader(requestId, DownstreamRequest);
}
}
@aqa510415008 did you ever get this working?
@TomPallister @binarymash @geffzhang Why "OcelotRequestId - not set"? Will OcelotRequestId set up where?
I did not find that place added RequestId?