use of io.opentracing.SpanContext in project hono by eclipse.
the class MongoDbBasedCredentialsDao method delete.
@Override
public Future<Void> delete(final String tenantId, final SpanContext tracingContext) {
Objects.requireNonNull(tenantId);
final Span span = tracer.buildSpan("delete Credentials of all of Tenant's Devices").addReference(References.CHILD_OF, tracingContext).withTag(TracingHelper.TAG_TENANT_ID, tenantId).start();
final JsonObject removeCredentialsQuery = MongoDbDocumentBuilder.builder().withTenantId(tenantId).document();
return mongoClient.removeDocuments(collectionName, removeCredentialsQuery).compose(result -> {
span.log("successfully deleted credentials");
LOG.debug("successfully deleted credentials for devices of tenant [tenant-id: {}]", tenantId);
return Future.succeededFuture((Void) null);
}).recover(error -> {
LOG.debug("error deleting credentials", error);
TracingHelper.logError(span, "error deleting credentials", error);
return mapError(error);
}).onComplete(r -> span.finish());
}
use of io.opentracing.SpanContext in project hono by eclipse.
the class MongoDbBasedCredentialsDao method create.
/**
* {@inheritDoc}
*/
@Override
public Future<String> create(final CredentialsDto credentials, final SpanContext tracingContext) {
Objects.requireNonNull(credentials);
final Span span = tracer.buildSpan("add Credentials").addReference(References.CHILD_OF, tracingContext).withTag(TracingHelper.TAG_TENANT_ID, credentials.getTenantId()).withTag(TracingHelper.TAG_DEVICE_ID, credentials.getDeviceId()).start();
credentials.getCredentials().stream().forEach(cred -> cred.encryptFields(fieldLevelEncryption));
final var document = JsonObject.mapFrom(credentials);
if (LOG.isTraceEnabled()) {
LOG.trace("creating credentials for device [tenant: {}, device-id: {}, resource-version; {}]:{}{}", credentials.getTenantId(), credentials.getDeviceId(), credentials.getVersion(), System.lineSeparator(), document.encodePrettily());
}
return mongoClient.insert(collectionName, document).map(added -> {
span.log("successfully added credentials");
LOG.debug("successfully added credentials for device [tenant: {}, device-id: {}, resource-version: {}]", credentials.getTenantId(), credentials.getDeviceId(), credentials.getVersion());
return credentials.getVersion();
}).onFailure(t -> {
LOG.debug("error adding credentials for device [tenant: {}, device-id: {}]", credentials.getTenantId(), credentials.getDeviceId(), t);
TracingHelper.logError(span, "error adding credentials", t);
}).recover(this::mapError).onComplete(r -> span.finish());
}
use of io.opentracing.SpanContext in project hono by eclipse.
the class MessageAnnotationsInjectExtractAdapterTest method testJaegerTracerCanUseAdapter.
/**
* Verifies that the Jaeger tracer implementation can successfully use the adapter to inject and extract
* a SpanContext.
*/
@Test
public void testJaegerTracerCanUseAdapter() {
final Configuration config = new Configuration("test");
final Tracer tracer = config.getTracer();
final Span span = tracer.buildSpan("do").start();
final Message message = ProtonHelper.message();
final MessageAnnotationsInjectAdapter injectAdapter = new MessageAnnotationsInjectAdapter(message, propertiesMapName);
tracer.inject(span.context(), Format.Builtin.TEXT_MAP, injectAdapter);
final SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, new MessageAnnotationsExtractAdapter(message, propertiesMapName));
assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
use of io.opentracing.SpanContext in project hono by eclipse.
the class MultiMapInjectExtractAdapterTest method testJaegerTracerCanUseAdapter.
/**
* Verifies that the Jaeger tracer implementation can successfully use the adapter to inject and extract
* a SpanContext.
*/
@Test
public void testJaegerTracerCanUseAdapter() {
final Configuration config = new Configuration("test");
final Tracer tracer = config.getTracer();
final Span span = tracer.buildSpan("do").start();
final MultiMap multiMap = MultiMap.caseInsensitiveMultiMap();
final MultiMapInjectAdapter injectAdapter = new MultiMapInjectAdapter(multiMap);
tracer.inject(span.context(), Format.Builtin.TEXT_MAP, injectAdapter);
final SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, new MultiMapExtractAdapter(multiMap));
assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
use of io.opentracing.SpanContext in project hono by eclipse.
the class JsonObjectInjectExtractAdapterTest method testJaegerTracerCanUseAdapter.
/**
* Verifies that the Jaeger tracer implementation can successfully use the adapter to inject and extract
* a SpanContext.
*/
@Test
public void testJaegerTracerCanUseAdapter() {
final Configuration config = new Configuration("test");
final Tracer tracer = config.getTracer();
final Span span = tracer.buildSpan("do").start();
final JsonObject jsonObject = new JsonObject();
final JsonObjectInjectAdapter injectAdapter = new JsonObjectInjectAdapter(jsonObject);
tracer.inject(span.context(), Format.Builtin.TEXT_MAP, injectAdapter);
final SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, new JsonObjectExtractAdapter(jsonObject));
assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
Aggregations