Skip to content

Commit

Permalink
Improve tracing if no command handler is found.
Browse files Browse the repository at this point in the history
Signed-off-by: Carsten Lohmann <[email protected]>
  • Loading branch information
calohmn authored and sophokles73 committed Feb 28, 2020
1 parent ff91a2b commit 910b516
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,32 @@ private void handleCommandMessage(final Message msg, final ProtonDelivery delive
delivery.disposition(rejected, true);
return;
}
final Command command = Command.from(msg, tenantId, gatewayOrDeviceId);
// command.isValid() check not done here - it is to be done in the command handler
final Tracer tracer = connection.getTracer();
// try to extract Span context from incoming message
final SpanContext spanContext = TracingHelper.extractSpanContext(tracer, msg);
final String gatewayId = gatewayOrDeviceId.equals(originalDeviceId) ? null : gatewayOrDeviceId;
final Span currentSpan = createSpan("send command", tenantId, originalDeviceId,
gatewayId, tracer, spanContext);
logReceivedCommandToSpan(command, currentSpan);

// look for a handler with the original device id first
final CommandHandlerWrapper commandHandler = getCommandHandlerOrDefault(originalDeviceId);
if (commandHandler != null) {
final Command command = Command.from(msg, tenantId, gatewayOrDeviceId);
// command.isValid() check not done here - it is to be done in the command handler
final Tracer tracer = connection.getTracer();
// try to extract Span context from incoming message
final SpanContext spanContext = TracingHelper.extractSpanContext(tracer, msg);
final String gatewayId = gatewayOrDeviceId.equals(originalDeviceId) ? null : gatewayOrDeviceId;
final Span currentSpan = createSpan("send command", tenantId, originalDeviceId,
gatewayId, tracer, spanContext);
logReceivedCommandToSpan(command, currentSpan);
commandHandler.handleCommand(CommandContext.from(command, delivery, this.receiver, currentSpan));
} else {
LOG.error("no command handler found for command with device id {}, message address device id {} [tenant-id: {}]",
gatewayOrDeviceId, originalDeviceId, tenantId);
// no command handler found
if (gatewayId != null && !containsCommandHandler(gatewayOrDeviceId) && !commandHandlers.isEmpty()) {
LOG.debug("no command handler found; target gateway {} is only subscribed for commands to other specific devices, not for device {} [tenant-id: {}]",
gatewayId, originalDeviceId, tenantId);
TracingHelper.logError(currentSpan, "no command handler found; target gateway is only subscribed for commands to other specific devices");
} else {
LOG.error("no command handler found for command targeted at device {}, gateway {} [tenant-id: {}]",
originalDeviceId, gatewayId, tenantId);
TracingHelper.logError(currentSpan, "no command handler found for command");
}
currentSpan.finish();
ProtonHelper.released(delivery, true);
}
}
Expand Down

0 comments on commit 910b516

Please sign in to comment.