@Override public void onFailure(final Throwable throwable, final HttpServerResponse response, final Span span) { LOG.trace("logging failed processing of request"); TracingHelper.logError(span, throwable); } }
@Override public void onFailure(final Throwable throwable, final HttpServerResponse response, final Span span) { LOG.trace("logging failed processing of request"); TracingHelper.logError(span, throwable); } }
/** * Marks an <em>OpenTracing</em> span as erroneous and logs a message. * <p> * This method does <em>not</em> finish the span. * * @param span The span to mark. * @param message The message to log on the span. * @throws NullPointerException if message is {@code null}. */ public static void logError(final Span span, final String message) { if (span != null) { Objects.requireNonNull(message); logError(span, Collections.singletonMap(Fields.MESSAGE, message)); } }
/** * Marks an <em>OpenTracing</em> span as erroneous and logs a message. * <p> * This method does <em>not</em> finish the span. * * @param span The span to mark. * @param message The message to log on the span. * @throws NullPointerException if message is {@code null}. */ public static void logError(final Span span, final String message) { if (span != null) { Objects.requireNonNull(message); logError(span, Collections.singletonMap(Fields.MESSAGE, message)); } }
/** * Marks an <em>OpenTracing</em> span as erroneous and logs an exception. * <p> * This method does <em>not</em> finish the span. * * @param span The span to mark. * @param error The exception that has occurred. * @throws NullPointerException if error is {@code null}. */ public static void logError(final Span span, final Throwable error) { if (span != null) { logError(span, getErrorLogItems(error)); } }
/** * Marks an <em>OpenTracing</em> span as erroneous and logs an exception. * <p> * This method does <em>not</em> finish the span. * * @param span The span to mark. * @param error The exception that has occurred. * @throws NullPointerException if error is {@code null}. */ public static void logError(final Span span, final Throwable error) { if (span != null) { logError(span, getErrorLogItems(error)); } }
/** * Cancels an outstanding request with a given result. * * @param correlationId The correlation id of the request to cancel. * @param result The result to pass to the request's result handler. * @throws NullPointerException if any of the parameters is {@code null}. * @throws IllegalArgumentException if the result has not failed. */ protected final void cancelRequest(final Object correlationId, final AsyncResult<R> result) { Objects.requireNonNull(correlationId); Objects.requireNonNull(result); if (result.succeeded()) { throw new IllegalArgumentException("result must be failed"); } else { final TriTuple<Handler<AsyncResult<R>>, Object, Span> handler = replyMap.remove(correlationId); if (handler == null) { // response has already been processed } else { LOG.debug("canceling request [target: {}, correlation ID: {}]: {}", targetAddress, correlationId, result.cause().getMessage()); TracingHelper.logError(handler.three(), result.cause()); handler.one().handle(result); } } }
/** * Marks an <em>OpenTracing</em> span as erroneous and logs an exception. * <p> * This method does <em>not</em> finish the span. * * @param span The span to mark. * @param error The exception that has occurred. If the exception is a * {@link ServiceInvocationException} then a {@link Tags#HTTP_STATUS} * tag is added containing the exception's error code property value. * @throws NullPointerException if error is {@code null}. */ protected final void logError(final Span span, final Throwable error) { if (span != null) { if (ServiceInvocationException.class.isInstance(error)) { final ServiceInvocationException e = (ServiceInvocationException) error; Tags.HTTP_STATUS.set(span, e.getErrorCode()); } TracingHelper.logError(span, error); } }
TracingHelper.logError(span, "no credentials found for tenant"); resultHandler.handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else { TracingHelper.logError(span, "no credentials found for device"); resultHandler.handle(Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_NOT_FOUND))); } else {
TenantResult<JsonObject> getTenantResult(final String tenantId, final Span span) { final TenantObject tenant = tenants.get(tenantId); if (tenant == null) { TracingHelper.logError(span, "tenant not found"); return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } else { return TenantResult.from( HttpURLConnection.HTTP_OK, JsonObject.mapFrom(tenant), CacheDirective.maxAgeDirective(MAX_AGE_GET_TENANT)); } }
private TenantResult<JsonObject> getForCertificateAuthority(final X500Principal subjectDn, final Span span) { if (subjectDn == null) { TracingHelper.logError(span, "missing subject DN"); return TenantResult.from(HttpURLConnection.HTTP_BAD_REQUEST); } else { final TenantObject tenant = getByCa(subjectDn); if (tenant == null) { TracingHelper.logError(span, "no tenant found for subject DN"); return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND); } else { return TenantResult.from(HttpURLConnection.HTTP_OK, JsonObject.mapFrom(tenant), CacheDirective.maxAgeDirective(MAX_AGE_GET_TENANT)); } } }
/** * Settles the command message with the <em>rejected</em> outcome * and flows credit to the peer. * <p> * This method also finishes the OpenTracing span returned by * {@link #getCurrentSpan()}. * * @param errorCondition The error condition to send in the disposition frame (may be {@code null}). * @param credit The number of credits to flow to the peer. * @throws IllegalArgumentException if credit is negative. */ public void reject(final ErrorCondition errorCondition, final int credit) { final Rejected rejected = new Rejected(); final Map<String, Object> items = new HashMap<>(2); items.put(Fields.EVENT, "rejected command for device"); if (errorCondition != null) { rejected.setError(errorCondition); Optional.ofNullable(errorCondition.getDescription()).ifPresent(s -> items.put(Fields.MESSAGE, s)); } TracingHelper.logError(currentSpan, items); delivery.disposition(rejected, true); if (credit > 0) { flow(credit); } currentSpan.finish(); }
final Future<EventBusMessage> resultFuture; if (tenantId == null && payload == null) { TracingHelper.logError(span, "request does not contain any query parameters"); log.debug("request does not contain any query parameters"); resultFuture = Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST)); TracingHelper.logError(span, "request does not contain any query parameters"); log.debug("payload does not contain any query parameters"); resultFuture = Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
TracingHelper.logError(currentSpan, e); completer.handle(Future.failedFuture(e));
CacheDirective.maxAgeDirective(assertionFactory.getAssertionLifetime())); } else { TracingHelper.logError(span, "device not enabled"); return RegistrationResult.from(HttpURLConnection.HTTP_NOT_FOUND);
/** * Composes the given future so that the given <em>OpenTracing</em> span is finished when the future completes. * <p> * The result or exception of the given future will be used to set a {@link Tags#HTTP_STATUS} tag on the span * and to set a {@link Tags#ERROR} tag in case of an exception or a result with error status. * * @param span The span to finish. * @param resultFuture The future to be composed. * @return The composed future. */ protected Future<EventBusMessage> finishSpanOnFutureCompletion(final Span span, final Future<EventBusMessage> resultFuture) { return resultFuture.compose(eventBusMessage -> { Tags.HTTP_STATUS.set(span, eventBusMessage.getStatus()); if (eventBusMessage.hasErrorStatus()) { Tags.ERROR.set(span, true); } span.finish(); return Future.succeededFuture(eventBusMessage); }).recover(t -> { Tags.HTTP_STATUS.set(span, ServiceInvocationException.extractStatusCode(t)); TracingHelper.logError(span, t); span.finish(); return Future.failedFuture(t); }); } }
private Future<EventBusMessage> processGetByCaRequest(final EventBusMessage request, final String subjectDn, final Span span) { try { final X500Principal dn = new X500Principal(subjectDn); log.debug("retrieving tenant [subject DN: {}]", subjectDn); final Future<TenantResult<JsonObject>> getResult = Future.future(); get(dn, span, getResult.completer()); return getResult.map(tr -> { final EventBusMessage response = request.getResponse(tr.getStatus()) .setJsonPayload(tr.getPayload()) .setCacheDirective(tr.getCacheDirective()); if (tr.isOk() && tr.getPayload() != null) { final String tenantId = getTypesafeValueForField(String.class, tr.getPayload(), TenantConstants.FIELD_PAYLOAD_TENANT_ID); span.setTag(MessageHelper.APP_PROPERTY_TENANT_ID, tenantId); response.setTenant(tenantId); } return response; }); } catch (final IllegalArgumentException e) { TracingHelper.logError(span, "illegal subject DN provided by client: " + subjectDn); // the given subject DN is invalid log.debug("cannot parse subject DN [{}] provided by client", subjectDn); return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST)); } }
/** * {@inheritDoc} */ @Override public Future<Void> sendOneWayCommand(final String command, final String contentType, final Buffer data, final Map<String, Object> properties) { Objects.requireNonNull(command); final Span currentSpan = newChildSpan(null, command); if (sender.isOpen()) { final Future<BufferResult> responseTracker = Future.future(); final Message request = ProtonHelper.message(); AbstractHonoClient.setApplicationProperties(request, properties); final String messageId = createMessageId(); request.setMessageId(messageId); request.setSubject(command); MessageHelper.setPayload(request, contentType, data); sendRequest(request, responseTracker.completer(), null, currentSpan); return responseTracker.map(ignore -> null); } else { TracingHelper.logError(currentSpan, "sender link is not open"); return Future.failedFuture(new ServerErrorException( HttpURLConnection.HTTP_UNAVAILABLE, "sender link is not open")); } }
private Future<EventBusMessage> processAssertRequest(final EventBusMessage request) { final String tenantId = request.getTenant(); final String deviceId = request.getDeviceId(); final String gatewayId = request.getGatewayId(); final SpanContext spanContext = request.getSpanContext(); final Span span = newChildSpan(SPAN_NAME_ASSERT_DEVICE_REGISTRATION, spanContext, tenantId, deviceId, gatewayId); final Future<EventBusMessage> resultFuture; if (tenantId == null || deviceId == null) { TracingHelper.logError(span, "missing tenant and/or device"); resultFuture = Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST)); } else { final Future<RegistrationResult> result = Future.future(); if (gatewayId == null) { log.debug("asserting registration of device [{}] with tenant [{}]", deviceId, tenantId); assertRegistration(tenantId, deviceId, span, result.completer()); } else { log.debug("asserting registration of device [{}] with tenant [{}] for gateway [{}]", deviceId, tenantId, gatewayId); assertRegistration(tenantId, deviceId, gatewayId, span, result.completer()); } resultFuture = result.map(res -> { return request.getResponse(res.getStatus()) .setDeviceId(deviceId) .setJsonPayload(res.getPayload()) .setCacheDirective(res.getCacheDirective()); }); } return finishSpanOnFutureCompletion(span, resultFuture); }