Search in sources :

Example 86 with SpanContext

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());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Status(io.vertx.ext.healthchecks.Status) FieldLevelEncryption(org.eclipse.hono.deviceregistry.util.FieldLevelEncryption) HealthCheckHandler(io.vertx.ext.healthchecks.HealthCheckHandler) HealthCheckProvider(org.eclipse.hono.service.HealthCheckProvider) References(io.opentracing.References) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Promise(io.vertx.core.Promise) MongoClient(io.vertx.ext.mongo.MongoClient) UUID(java.util.UUID) Future(io.vertx.core.Future) SpanContext(io.opentracing.SpanContext) Objects(java.util.Objects) CredentialsDto(org.eclipse.hono.service.management.credentials.CredentialsDto) IndexOptions(io.vertx.ext.mongo.IndexOptions) Optional(java.util.Optional) Span(io.opentracing.Span) FindOptions(io.vertx.ext.mongo.FindOptions) UpdateOptions(io.vertx.ext.mongo.UpdateOptions) MongoDbDocumentBuilder(org.eclipse.hono.deviceregistry.mongodb.utils.MongoDbDocumentBuilder) JsonObject(io.vertx.core.json.JsonObject) Span(io.opentracing.Span)

Example 87 with SpanContext

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());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Status(io.vertx.ext.healthchecks.Status) FieldLevelEncryption(org.eclipse.hono.deviceregistry.util.FieldLevelEncryption) HealthCheckHandler(io.vertx.ext.healthchecks.HealthCheckHandler) HealthCheckProvider(org.eclipse.hono.service.HealthCheckProvider) References(io.opentracing.References) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Promise(io.vertx.core.Promise) MongoClient(io.vertx.ext.mongo.MongoClient) UUID(java.util.UUID) Future(io.vertx.core.Future) SpanContext(io.opentracing.SpanContext) Objects(java.util.Objects) CredentialsDto(org.eclipse.hono.service.management.credentials.CredentialsDto) IndexOptions(io.vertx.ext.mongo.IndexOptions) Optional(java.util.Optional) Span(io.opentracing.Span) FindOptions(io.vertx.ext.mongo.FindOptions) UpdateOptions(io.vertx.ext.mongo.UpdateOptions) MongoDbDocumentBuilder(org.eclipse.hono.deviceregistry.mongodb.utils.MongoDbDocumentBuilder) Span(io.opentracing.Span)

Example 88 with SpanContext

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());
}
Also used : SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Message(org.apache.qpid.proton.message.Message) Tracer(io.opentracing.Tracer) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 89 with SpanContext

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());
}
Also used : MultiMap(io.vertx.core.MultiMap) SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Tracer(io.opentracing.Tracer) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 90 with SpanContext

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());
}
Also used : SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Tracer(io.opentracing.Tracer) JsonObject(io.vertx.core.json.JsonObject) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Aggregations

SpanContext (io.opentracing.SpanContext)118 Span (io.opentracing.Span)81 Future (io.vertx.core.Future)70 Tracer (io.opentracing.Tracer)60 Objects (java.util.Objects)57 HttpURLConnection (java.net.HttpURLConnection)56 JsonObject (io.vertx.core.json.JsonObject)55 TracingHelper (org.eclipse.hono.tracing.TracingHelper)55 Logger (org.slf4j.Logger)54 LoggerFactory (org.slf4j.LoggerFactory)54 List (java.util.List)51 Promise (io.vertx.core.Promise)45 Optional (java.util.Optional)45 Map (java.util.Map)40 ClientErrorException (org.eclipse.hono.client.ClientErrorException)39 MessageHelper (org.eclipse.hono.util.MessageHelper)33 UUID (java.util.UUID)31 Collectors (java.util.stream.Collectors)31 HashMap (java.util.HashMap)25 Vertx (io.vertx.core.Vertx)24