Skip to content

Commit

Permalink
logging update to include status for responses (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: alianides <[email protected]>
  • Loading branch information
alexlianides and alianides authored Jul 24, 2024
1 parent de34bdf commit acbd48b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/HostServices/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static ILogger Logger {

void LinkResponseEventHandler(object? _, MessageFormats.HostServices.Link.LinkResponse eventHandlerResponse) {
if (eventHandlerResponse.ResponseHeader.TrackingId == linkRequest.RequestHeader.TrackingId) {
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId);
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId, eventHandlerResponse.ResponseHeader.Status);

if (eventHandlerResponse.ResponseHeader.Status != MessageFormats.Common.StatusCodes.Pending) {
response = eventHandlerResponse;
Expand Down Expand Up @@ -137,7 +137,7 @@ void LinkResponseEventHandler(object? _, MessageFormats.HostServices.Link.LinkRe
throw new TimeoutException($"Timed out waiting for a response from {TARGET_SERVICE_APP_ID}");
}

Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}')", nameof(LinkResponse), response.ResponseHeader.Status, linkRequest.RequestHeader.TrackingId, linkRequest.RequestHeader.CorrelationId);
Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", nameof(LinkResponse), response.ResponseHeader.Status, linkRequest.RequestHeader.TrackingId, linkRequest.RequestHeader.CorrelationId, response.ResponseHeader.Status);

return response;
});
Expand Down
8 changes: 4 additions & 4 deletions src/HostServices/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static ILogger Logger {
if (waitForResponse == true) {
void LogMessageResponseEventHandler(object? _, MessageFormats.Common.LogMessageResponse eventHandlerResponse) {
if (eventHandlerResponse.ResponseHeader.TrackingId == logMessage.RequestHeader.TrackingId) {
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId);
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId, eventHandlerResponse.ResponseHeader.Status);
response = eventHandlerResponse;
Client.LogMessageResponseEvent -= LogMessageResponseEventHandler; // Remove the callback so it's not called for future iterations
}
Expand Down Expand Up @@ -87,7 +87,7 @@ void LogMessageResponseEventHandler(object? _, MessageFormats.Common.LogMessageR
}
}

Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}')", nameof(LogMessageResponse), response.ResponseHeader.Status, logMessage.RequestHeader.TrackingId, logMessage.RequestHeader.CorrelationId);
Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", nameof(LogMessageResponse), response.ResponseHeader.Status, logMessage.RequestHeader.TrackingId, logMessage.RequestHeader.CorrelationId, response.ResponseHeader.Status);

return response;
});
Expand Down Expand Up @@ -122,7 +122,7 @@ void LogMessageResponseEventHandler(object? _, MessageFormats.Common.LogMessageR
if (waitForResponse == true) {
void TelemetryResponseEventHandler(object? _, MessageFormats.Common.TelemetryMetricResponse eventHandlerResponse) {
if (eventHandlerResponse.ResponseHeader.TrackingId == telemetryMessage.RequestHeader.TrackingId) {
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId);
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId, eventHandlerResponse.ResponseHeader.Status);

response = eventHandlerResponse;
Client.TelemetryMetricResponseEvent -= TelemetryResponseEventHandler; // Remove the callback so it's not called for future iterations
Expand Down Expand Up @@ -153,7 +153,7 @@ void TelemetryResponseEventHandler(object? _, MessageFormats.Common.TelemetryMet
}
}

Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}')", nameof(TelemetryMetricResponse), response.ResponseHeader.Status, telemetryMessage.RequestHeader.TrackingId, telemetryMessage.RequestHeader.CorrelationId);
Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", nameof(TelemetryMetricResponse), response.ResponseHeader.Status, telemetryMessage.RequestHeader.TrackingId, telemetryMessage.RequestHeader.CorrelationId, response.ResponseHeader.Status);

return response;
});
Expand Down
4 changes: 2 additions & 2 deletions src/HostServices/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static ILogger Logger {
// Create an in-line callback function to get the response for this message
void PositionResponseEventHandler(object? _, MessageFormats.HostServices.Position.PositionResponse eventHandlerResponse) {
if (eventHandlerResponse.ResponseHeader.TrackingId == positionRequest.RequestHeader.TrackingId) {
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId);
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId, eventHandlerResponse.ResponseHeader.Status);

response = eventHandlerResponse;
Client.PositionResponseEvent -= PositionResponseEventHandler; // Remove myself for next time
Expand Down Expand Up @@ -79,7 +79,7 @@ void PositionResponseEventHandler(object? _, MessageFormats.HostServices.Positio
throw new TimeoutException($"Timed out waiting for a response from {TARGET_SERVICE_APP_ID}");
}

Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}')", nameof(PositionResponse), response.ResponseHeader.Status, positionRequest.RequestHeader.TrackingId, positionRequest.RequestHeader.CorrelationId);
Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", nameof(PositionResponse), response.ResponseHeader.Status, positionRequest.RequestHeader.TrackingId, positionRequest.RequestHeader.CorrelationId, response.ResponseHeader.Status);

return response;
});
Expand Down
12 changes: 6 additions & 6 deletions src/HostServices/Sensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static ILogger Logger {

void SensorsAvailableResponseEventHandler(object? _, MessageFormats.HostServices.Sensor.SensorsAvailableResponse eventHandlerResponse) {
if (eventHandlerResponse.ResponseHeader.TrackingId == sensorsAvailableRequest.RequestHeader.TrackingId) {
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId);
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId, eventHandlerResponse.ResponseHeader.Status);
response = eventHandlerResponse;
Client.SensorsAvailableResponseEvent -= SensorsAvailableResponseEventHandler;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ void SensorsAvailableResponseEventHandler(object? _, MessageFormats.HostServices
throw new TimeoutException($"Timed out waiting for a response from {TARGET_SERVICE_APP_ID}");
}

Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}')", nameof(SensorsAvailableResponse), response.ResponseHeader.Status, sensorsAvailableRequest.RequestHeader.TrackingId, sensorsAvailableRequest.RequestHeader.CorrelationId);
Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", nameof(SensorsAvailableResponse), response.ResponseHeader.Status, sensorsAvailableRequest.RequestHeader.TrackingId, sensorsAvailableRequest.RequestHeader.CorrelationId, response.ResponseHeader.Status);

return response;
});
Expand Down Expand Up @@ -126,7 +126,7 @@ void SensorsAvailableResponseEventHandler(object? _, MessageFormats.HostServices

void TaskingPreCheckResponseEventHandler(object? _, MessageFormats.HostServices.Sensor.TaskingPreCheckResponse eventHandlerResponse) {
if (eventHandlerResponse.ResponseHeader.TrackingId == taskingPreCheckRequest.RequestHeader.TrackingId) {
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId);
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId, eventHandlerResponse.ResponseHeader.Status);

response = eventHandlerResponse;
Client.SensorsTaskingPreCheckResponseEvent -= TaskingPreCheckResponseEventHandler;
Expand Down Expand Up @@ -155,7 +155,7 @@ void TaskingPreCheckResponseEventHandler(object? _, MessageFormats.HostServices.
throw new TimeoutException($"Timed out waiting for a response from {TARGET_SERVICE_APP_ID}");
}

Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}')", nameof(TaskingPreCheckResponse), response.ResponseHeader.Status, taskingPreCheckRequest.RequestHeader.TrackingId, taskingPreCheckRequest.RequestHeader.CorrelationId);
Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", nameof(TaskingPreCheckResponse), response.ResponseHeader.Status, taskingPreCheckRequest.RequestHeader.TrackingId, taskingPreCheckRequest.RequestHeader.CorrelationId, response.ResponseHeader.Status);


return response;
Expand Down Expand Up @@ -201,7 +201,7 @@ void TaskingPreCheckResponseEventHandler(object? _, MessageFormats.HostServices.

void TaskingResponseEventHandler(object? _, MessageFormats.HostServices.Sensor.TaskingResponse eventHandlerResponse) {
if (eventHandlerResponse.ResponseHeader.TrackingId == taskingRequest.RequestHeader.TrackingId) {
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId);
Logger.LogDebug("Message response received for '{messageType}'. Status: '{status}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", eventHandlerResponse.GetType().Name, eventHandlerResponse.ResponseHeader.Status, eventHandlerResponse.ResponseHeader.TrackingId, eventHandlerResponse.ResponseHeader.CorrelationId, eventHandlerResponse.ResponseHeader.Status);

response = eventHandlerResponse;
Client.SensorsTaskingResponseEvent -= TaskingResponseEventHandler;
Expand Down Expand Up @@ -231,7 +231,7 @@ void TaskingResponseEventHandler(object? _, MessageFormats.HostServices.Sensor.T
throw new TimeoutException($"Timed out waiting for a response from {TARGET_SERVICE_APP_ID}");
}

Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}')", nameof(TaskingResponse), response.ResponseHeader.Status, taskingRequest.RequestHeader.TrackingId, taskingRequest.RequestHeader.CorrelationId);
Logger.LogDebug("Returning '{messageType}' with status '{status}' to payload app (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", nameof(TaskingResponse), response.ResponseHeader.Status, taskingRequest.RequestHeader.TrackingId, taskingRequest.RequestHeader.CorrelationId, response.ResponseHeader.Status);


return response;
Expand Down

0 comments on commit acbd48b

Please sign in to comment.