use of io.opentracing.Tracer in project hono by eclipse.
the class CacheBasedDeviceConnectionInfoTest method testGetCommandHandlingAdapterInstancesWithSuspectedAdapterInstanceContainer.
/**
* Verifies that the <em>getCommandHandlingAdapterInstances</em> operation succeeds with a result containing
* the mapping of a gateway device if the also existing mapping belonging to the *the given device* is associated
* with an adapter instance having the 'SUSPECTED_DEAD' status.
*
* @param extraUnusedViaGateways Test values.
* @param ctx The vert.x context.
*/
@ParameterizedTest(name = PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("extraUnusedViaGateways")
public void testGetCommandHandlingAdapterInstancesWithSuspectedAdapterInstanceContainer(final Set<String> extraUnusedViaGateways, final VertxTestContext ctx) {
final AdapterInstanceStatusProvider statusProvider = mock(AdapterInstanceStatusProvider.class);
info = new CacheBasedDeviceConnectionInfo(cache, tracer, statusProvider);
final String deviceId = "testDevice";
final String adapterInstance = "adapterInstance";
final String otherAdapterInstance = "otherAdapterInstance";
final String gatewayId = "gw-1";
final Set<String> viaGateways = new HashSet<>(Set.of(gatewayId));
viaGateways.addAll(extraUnusedViaGateways);
// GIVEN testDevice has no last known gateway registered
when(cache.get(CacheBasedDeviceConnectionInfo.getGatewayEntryKey(Constants.DEFAULT_TENANT, deviceId))).thenReturn(Future.succeededFuture());
// and testDevice's and gw-1's command handling adapter instances are set to
// adapterInstance and otherAdapterInstance respectively
when(cache.getAll(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKeys(Constants.DEFAULT_TENANT, deviceId, viaGateways))).thenReturn(Future.succeededFuture(Map.of(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, deviceId), adapterInstance, CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, gatewayId), otherAdapterInstance)));
when(cache.remove(anyString(), anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE));
when(statusProvider.getStatus(adapterInstance)).thenReturn(AdapterInstanceStatus.SUSPECTED_DEAD);
when(statusProvider.getStatus(otherAdapterInstance)).thenReturn(AdapterInstanceStatus.ALIVE);
info.getCommandHandlingAdapterInstances(Constants.DEFAULT_TENANT, deviceId, viaGateways, span).onComplete(ctx.succeeding(result -> {
ctx.verify(() -> {
assertNotNull(result);
assertGetInstancesResultMapping(result, gatewayId, otherAdapterInstance);
assertGetInstancesResultSize(result, 1);
// verify mapping entry for terminated adapter instance has not been removed
verify(cache, never()).remove(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, deviceId), adapterInstance);
});
ctx.completeNow();
}));
}
use of io.opentracing.Tracer in project hono by eclipse.
the class KafkaBasedTelemetrySenderTest method testThatSendTelemetryThrowsOnMissingMandatoryParameter.
/**
* Verifies that
* {@link KafkaBasedTelemetrySender#sendTelemetry(TenantObject, RegistrationAssertion, QoS, String, Buffer, Map, io.opentracing.SpanContext)}
* throws an NPE if a mandatory parameter is {@code null}.
*/
@Test
public void testThatSendTelemetryThrowsOnMissingMandatoryParameter() {
final QoS qos = QoS.AT_LEAST_ONCE;
final MockProducer<String, Buffer> mockProducer = KafkaClientUnitTestHelper.newMockProducer(true);
final CachingKafkaProducerFactory<String, Buffer> factory = CachingKafkaProducerFactory.testFactory(vertxMock, (n, c) -> KafkaClientUnitTestHelper.newKafkaProducer(mockProducer));
final Tracer tracer = NoopTracerFactory.create();
final KafkaBasedTelemetrySender sender = new KafkaBasedTelemetrySender(vertxMock, factory, kafkaProducerConfig, true, tracer);
assertThrows(NullPointerException.class, () -> sender.sendTelemetry(null, device, qos, "the-content-type", null, null, null));
assertThrows(NullPointerException.class, () -> sender.sendTelemetry(tenant, null, qos, "the-content-type", null, null, null));
assertThrows(NullPointerException.class, () -> sender.sendTelemetry(tenant, device, null, "the-content-type", null, null, null));
}
use of io.opentracing.Tracer in project hono by eclipse.
the class TracingHelper method injectSpanContext.
/**
* Injects a {@code SpanContext} into the headers of vert.x {@code DeliveryOptions}.
*
* @param tracer The Tracer to use for injecting the context.
* @param spanContext The context to inject or {@code null} if no context is available.
* @param deliveryOptions The delivery options to inject the context into.
* @throws NullPointerException if tracer or deliveryOptions is {@code null}.
*/
public static void injectSpanContext(final Tracer tracer, final SpanContext spanContext, final DeliveryOptions deliveryOptions) {
Objects.requireNonNull(tracer);
Objects.requireNonNull(deliveryOptions);
if (spanContext != null && !(spanContext instanceof NoopSpanContext)) {
final MultiMap headers = Optional.of(deliveryOptions).map(options -> options.getHeaders()).orElseGet(() -> {
final MultiMap newHeaders = MultiMap.caseInsensitiveMultiMap();
deliveryOptions.setHeaders(newHeaders);
return newHeaders;
});
tracer.inject(spanContext, Format.Builtin.TEXT_MAP, new MultiMapInjectAdapter(headers));
}
}
use of io.opentracing.Tracer in project Payara by payara.
the class SpanPropagator method internalActiveContext.
private SpanContext internalActiveContext() {
final PayaraTracingServices payaraTracingServices = new PayaraTracingServices();
final Tracer tracer = payaraTracingServices.getActiveTracer();
if (tracer == null) {
return null;
}
final Span activeSpan = tracer.activeSpan();
return activeSpan == null ? null : activeSpan.context();
}
use of io.opentracing.Tracer in project Payara by payara.
the class ContextSetupProviderImpl method startConcurrentContextSpan.
private void startConcurrentContextSpan(ComponentInvocation invocation, InvocationContext handle) {
Tracer tracer = openTracing.getTracer(openTracing.getApplicationName(Globals.getDefaultBaseServiceLocator().getService(InvocationManager.class)));
// Start a trace in the request tracing system
SpanBuilder builder = tracer.buildSpan("executeConcurrentContext");
// Check for propagated span
if (handle.getSpanContextMap() != null) {
@SuppressWarnings("unchecked") SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new MapToTextMap(handle.getSpanContextMap()));
if (spanContext != null) {
builder.asChildOf(spanContext);
// Check for the presence of a propagated parent operation name
try {
String operationName = ((RequestTraceSpanContext) spanContext).getBaggageItems().get("operation.name");
if (operationName != null) {
builder.withTag("Parent Operation Name", operationName);
}
} catch (ClassCastException cce) {
logger.log(Level.FINE, "ClassCastException caught converting Span Context", cce);
}
}
}
if (invocation != null) {
builder = builder.withTag("App Name", invocation.getAppName()).withTag("Component ID", invocation.getComponentId()).withTag("Module Name", invocation.getModuleName());
Object instance = invocation.getInstance();
if (instance != null) {
builder.withTag("Class Name", instance.getClass().getName());
}
}
builder.withTag("Thread Name", Thread.currentThread().getName());
tracer.activateSpan(builder.start());
}
Aggregations