private void ProcessStopEvent(object eventValue, TRequest request, Uri requestUrl) { Logger.Trace()?.Log("Processing stop event... Request URL: {RequestUrl}", Http.Sanitize(requestUrl)); if (!ProcessingRequests.TryRemove(request, out var span)) { // if we don't find the request in the dictionary and current transaction is null, then this is not a big deal - // it was probably not captured in Start either - so we skip with a debug log if (_agent.Tracer.CurrentTransaction == null) { Logger.Debug() ?.Log("{eventName} called with no active current transaction, url: {url} - skipping event", nameof(ProcessStopEvent), Http.Sanitize(requestUrl)); } // otherwise it's strange and it deserves a warning else { Logger.Warning() ?.Log("Failed capturing request (failed to remove from ProcessingRequests) - " + "This Span will be skipped in case it wasn't captured before. " + "Request: method: {HttpMethod}, URL: {RequestUrl}", RequestGetMethod(request), Http.Sanitize(requestUrl)); } return; } // if span.Context.Http == null that means the transaction is not sampled (see ProcessStartEvent) if (span.Context.Http != null) { //TODO: response can be null if for example the request Task is Faulted. //E.g. writing this from an airplane without internet, and requestTaskStatus is "Faulted" and response is null //How do we report this? There is no response code in that case. var responseObject = eventValue.GetType().GetTypeInfo().GetDeclaredProperty(EventResponsePropertyName)?.GetValue(eventValue); if (responseObject != null) { if (responseObject is TResponse response) { span.Context.Http.StatusCode = ResponseGetStatusCode(response); if (span.Context.Http.StatusCode < 400) { span.Outcome = Outcome.Success; } else { span.Outcome = Outcome.Failure; } } else { Logger.Trace() ?.Log("Actual type of object ({EventResponsePropertyActualType}) in event's {EventResponsePropertyName} property " + "doesn't match the expected type ({EventResponsePropertyExpectedType})", responseObject.GetType().FullName, EventResponsePropertyName, typeof(TResponse).FullName); } } } span.End(); }
private void ProcessStopEvent(object eventValue, TRequest request, Uri requestUrl) { _logger.Trace()?.Log("Processing stop event... Request URL: {RequestUrl}", requestUrl); if (!ProcessingRequests.TryRemove(request, out var span)) { _logger.Warning() ?.Log("Failed capturing request (failed to remove from ProcessingRequests) - " + "This Span will be skipped in case it wasn't captured before. " + "Request: method: {HttpMethod}, URL: {RequestUrl}", RequestGetMethod(request), requestUrl); return; } // if span.Context.Http == null that means the transaction is not sampled (see ProcessStartEvent) if (span.Context.Http != null) { //TODO: response can be null if for example the request Task is Faulted. //E.g. writing this from an airplane without internet, and requestTaskStatus is "Faulted" and response is null //How do we report this? There is no response code in that case. var responseObject = eventValue.GetType().GetTypeInfo().GetDeclaredProperty(EventResponsePropertyName)?.GetValue(eventValue); if (responseObject != null) { var response = responseObject as TResponse; if (response == null) { _logger.Trace() ?.Log("Actual type of object ({EventResponsePropertyActualType}) in event's {EventResponsePropertyName} property " + "doesn't match the expected type ({EventResponsePropertyExpectedType})", responseObject.GetType().FullName, EventResponsePropertyName, typeof(TResponse).FullName); } else { span.Context.Http.StatusCode = ResponseGetStatusCode(response); } } } span.End(); }