public async Task SendAsync_WritesExpectedTraces() { var request = new HttpRequestMessage(HttpMethod.Get, "http://functions.com/api/testfunc?code=123"); string requestId = Guid.NewGuid().ToString(); request.Headers.Add(ScriptConstants.AntaresLogIdHeaderName, requestId); WebScriptHostHandler.SetRequestId(request); request.SetAuthorizationLevel(AuthorizationLevel.Function); await _invoker.SendAsync(request, CancellationToken.None); var traces = _traceWriter.Traces.ToArray(); Assert.Equal(3, traces.Length); // validate executing trace var trace = traces[0]; Assert.Equal(TraceLevel.Info, trace.Level); string message = Regex.Replace(trace.Message, @"\s+", string.Empty); Assert.Equal($"ExecutingHTTPrequest:{{\"requestId\":\"{requestId}\",\"method\":\"GET\",\"uri\":\"/api/testfunc\"}}", message); // validate executed trace trace = traces[1]; Assert.Equal(TraceLevel.Info, trace.Level); message = Regex.Replace(trace.Message, @"\s+", string.Empty); Assert.Equal($"ExecutedHTTPrequest:{{\"requestId\":\"{requestId}\",\"method\":\"GET\",\"uri\":\"/api/testfunc\",\"authorizationLevel\":\"Function\"}}", message); // validate response trace trace = traces[2]; Assert.Equal(TraceLevel.Info, trace.Level); message = Regex.Replace(trace.Message, @"\s+", string.Empty); Assert.Equal($"Responsedetails:{{\"requestId\":\"{requestId}\",\"status\":\"OK\"}}", message); }
public void SetRequestId_SetsExpectedValue() { // if the log header is present, it is used; var request = new HttpRequestMessage(HttpMethod.Get, "http://test.com"); string logIdValue = Guid.NewGuid().ToString(); request.Headers.Add(ScriptConstants.AntaresLogIdHeaderName, logIdValue); WebScriptHostHandler.SetRequestId(request); string requestId = request.GetRequestId(); Assert.Equal(logIdValue, requestId); // otherwise a new guid is specified request = new HttpRequestMessage(HttpMethod.Get, "http://test.com"); WebScriptHostHandler.SetRequestId(request); requestId = request.GetRequestId(); Guid.Parse(requestId); }