Skip to content

Commit

Permalink
updated logging for responses to include status (#10)
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 23, 2024
1 parent 1a80c5d commit 41ef5b2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
14 changes: 7 additions & 7 deletions src/MessageHandlers/LinkResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ private void InboxToOutbox(MessageFormats.HostServices.Link.LinkRequest? linkReq

private void SendFileToApp(MessageFormats.HostServices.Link.LinkResponse? message) {

_logger.LogInformation("Processing {messageType} for potential additional file transfer.(trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Processing {messageType} for potential additional file transfer.(trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

string? sourcePayloadAppId = message.LinkRequest.RequestHeader.Metadata.FirstOrDefault((_item) => _item.Key == "SOURCE_PAYLOAD_APP_ID").Value;

// If the LinkRequest was sent by platform-mts itself, does not contain the required SOURCE_PAYLOAD_APP_ID metadata field, or was successful in it's file transfer? drop the LinkResponse
if (message.LinkRequest.RequestHeader.AppId == $"platform-{MessageFormats.Common.PlatformServices.Mts}".ToLower() || string.IsNullOrWhiteSpace(sourcePayloadAppId) || message.ResponseHeader.Status != MessageFormats.Common.StatusCodes.Successful) return;

_logger.LogInformation("Detected '{messageType}' associated with LinkRequest for payload-app file. (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Detected '{messageType}' associated with LinkRequest for payload-app file. (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

InboxToOutbox(message.LinkRequest);

var filePath = Path.Combine(Core.GetXFerDirectories().Result.inbox_directory, message.LinkRequest.FileName);

if (!string.IsNullOrWhiteSpace(message.LinkRequest.Subdirectory)) filePath = Path.Combine(Core.GetXFerDirectories().Result.inbox_directory, message.LinkRequest.Subdirectory, message.LinkRequest.FileName);

_logger.LogInformation("{methodRequest}: Found SOURCE_PAYLOAD_APP_ID metadata {sourcePayloadAppID} and found file at '{filePath}'. Sending LinkRequest to '{destinationAppId}'. (TrackingId: {trackingId}, CorrelationId: {correlationId})",
nameof(SendFileToApp), sourcePayloadAppId, filePath, sourcePayloadAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("{methodRequest}: Found SOURCE_PAYLOAD_APP_ID metadata {sourcePayloadAppID} and found file at '{filePath}'. Sending LinkRequest to '{destinationAppId}'. (trackingId: {trackingId} / correlationId: {correlationId} / status: '{status}')",
nameof(SendFileToApp), sourcePayloadAppId, filePath, sourcePayloadAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);


// Modify the original LinkRequest to transfer the file to SOURCE_PAYLOAD_APP_ID
Expand All @@ -54,7 +54,7 @@ private void LinkResponseHandler(MessageFormats.HostServices.Link.LinkResponse?
if (message == null) return;

using (var scope = _serviceProvider.CreateScope()) {
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

// Deployment Scenario: No Plugins
// No plugins are loaded. Process LinkResponse to see if the file requires an additional transfer
Expand All @@ -76,15 +76,15 @@ private void LinkResponseHandler(MessageFormats.HostServices.Link.LinkResponse?
}

// Deployment Plugin Scenario:
_logger.LogDebug("Passing message '{messageType}' to plugins (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogDebug("Passing message '{messageType}' to plugins (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);


MessageFormats.HostServices.Link.LinkResponse? pluginResult =
_pluginLoader.CallPlugins<MessageFormats.HostServices.Link.LinkResponse?, Plugins.PluginBase>(
orig_request: message,
pluginDelegate: _pluginDelegates.LinkResponse);

_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);
};
}
}
10 changes: 5 additions & 5 deletions src/MessageHandlers/PositionUpdateResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ public partial class MessageHandler<T> {
private void PositionUpdateResponseHandler(MessageFormats.HostServices.Position.PositionUpdateResponse? message, MessageFormats.Common.DirectToApp fullMessage) {
if (message == null) return;
using (var scope = _serviceProvider.CreateScope()) {
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

_logger.LogDebug("Passing message '{messageType}' to plugins (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogDebug("Passing message '{messageType}' to plugins (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);


MessageFormats.HostServices.Position.PositionUpdateResponse? pluginResult =
_pluginLoader.CallPlugins<MessageFormats.HostServices.Position.PositionUpdateResponse?, Plugins.PluginBase>(
orig_request: message,
pluginDelegate: _pluginDelegates.PositionUpdateResponse);

_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

if (pluginResult == null) {
_logger.LogInformation("Plugins nullified '{messageType}'. Dropping Message (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Plugins nullified '{messageType}'. Dropping Message (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);
return;
}

_logger.LogInformation("Sending message '{messageType}' to local event handler (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Sending message '{messageType}' to local event handler (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);
_messageRouter.CallEventHandlers<MessageFormats.HostServices.Position.PositionUpdateResponse>(pluginResult, fullMessage.SourceAppId, _messageRouter.PositionUpdateResponseReceivedEvent);
};
}
Expand Down
10 changes: 5 additions & 5 deletions src/MessageHandlers/SensorDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ public partial class MessageHandler<T> {
private void SensorDataHandler(MessageFormats.HostServices.Sensor.SensorData? message, MessageFormats.Common.DirectToApp fullMessage) {
if (message == null) return;
using (var scope = _serviceProvider.CreateScope()) {
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

_logger.LogDebug("Passing message '{messageType}' to plugins (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogDebug("Passing message '{messageType}' to plugins (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

MessageFormats.HostServices.Sensor.SensorData? pluginResult =
_pluginLoader.CallPlugins<MessageFormats.HostServices.Sensor.SensorData?, Plugins.PluginBase>(
orig_request: message,
pluginDelegate: _pluginDelegates.SensorData);

_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

if (pluginResult == null) {
_logger.LogInformation("Plugins nullified '{messageType}'. Dropping Message (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Plugins nullified '{messageType}'. Dropping Message (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);
return;
}

_logger.LogInformation("Routing message type '{messageType}' to '{appId}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, $"hostsvc-{nameof(MessageFormats.Common.HostServices.Sensor)}", message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Routing message type '{messageType}' to '{appId}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, $"hostsvc-{nameof(MessageFormats.Common.HostServices.Sensor)}", message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);
_client.DirectToApp(appId: $"hostsvc-{nameof(MessageFormats.Common.HostServices.Sensor)}", message: pluginResult);
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/MessageHandlers/SensorsAvailableResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ public partial class MessageHandler<T> {
private void SensorsAvailableResponseHandler(MessageFormats.HostServices.Sensor.SensorsAvailableResponse? message, MessageFormats.Common.DirectToApp fullMessage) {
if (message == null) return;
using (var scope = _serviceProvider.CreateScope()) {
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Processing message type '{messageType}' from '{sourceApp}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, fullMessage.SourceAppId, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

MessageFormats.HostServices.Sensor.SensorsAvailableResponse? pluginResult =
_pluginLoader.CallPlugins<MessageFormats.HostServices.Sensor.SensorsAvailableResponse?, Plugins.PluginBase>(
orig_request: message,
pluginDelegate: _pluginDelegates.SensorsAvailableResponse);

_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogDebug("Plugins finished processing '{messageType}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);

if (pluginResult == null) {
_logger.LogInformation("Plugins nullified '{messageType}'. Dropping Message (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Plugins nullified '{messageType}'. Dropping Message (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);
return;
} else {
_logger.LogInformation("Sending message '{messageType}' to '{appId}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", message.GetType().Name, MessageFormats.Common.HostServices.Sensor, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId);
_logger.LogInformation("Sending message '{messageType}' to '{appId}' (trackingId: '{trackingId}' / correlationId: '{correlationId}' / status: '{status}')", message.GetType().Name, MessageFormats.Common.HostServices.Sensor, message.ResponseHeader.TrackingId, message.ResponseHeader.CorrelationId, message.ResponseHeader.Status);
_client.DirectToApp(appId: $"hostsvc-{MessageFormats.Common.HostServices.Sensor}", message: pluginResult);
}
};
Expand Down
Loading

0 comments on commit 41ef5b2

Please sign in to comment.