Skip to content

Commit

Permalink
Fix tracing for Quarkus based adapters.
Browse files Browse the repository at this point in the history
HonoConnectionImpl#tracer needs to be set explicitly,
otherwise the NoopTracer is used.

Signed-off-by: Carsten Lohmann <[email protected]>
  • Loading branch information
calohmn committed Nov 23, 2020
1 parent 3fa7e9d commit 4305490
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
19 changes: 19 additions & 0 deletions client/src/main/java/org/eclipse/hono/client/HonoConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ static HonoConnection newConnection(final Vertx vertx, final ClientConfigPropert
return new HonoConnectionImpl(vertx, clientConfigProperties);
}

/**
* Creates a new connection using the default implementation.
* <p>
* <strong>Note:</strong> Instances of {@link ClientConfigProperties} are not thread safe and not immutable.
* They must therefore not be modified after calling this method.
*
* @param vertx The vert.x instance to use.
* @param clientConfigProperties The client properties to use.
* @param tracer The OpenTracing tracer.
* @return The newly created connection. Note that the underlying AMQP connection will not be established
* until one of its <em>connect</em> methods is invoked.
* @throws NullPointerException if any of the parameters is {@code null}.
*/
static HonoConnection newConnection(final Vertx vertx, final ClientConfigProperties clientConfigProperties, final Tracer tracer) {
final HonoConnectionImpl connection = new HonoConnectionImpl(vertx, clientConfigProperties);
connection.setTracer(tracer);
return connection;
}

/**
* Gets the vert.x instance used by this connection.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ protected Future<ProtonDelivery> sendMessage(final Message message, final Span c

@Override
protected Span startSpan(final SpanContext parent, final Message message) {
if (connection.getTracer() == null) {
throw new IllegalStateException("no tracer configured");
} else {
final Span span = newFollowingSpan(parent, "sending async command");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_PRODUCER);
return span;
}
final Span span = newFollowingSpan(parent, "sending async command");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_PRODUCER);
return span;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,8 @@ public static Future<DelegatedCommandSender> create(
@Override
protected Span startSpan(final SpanContext parent, final Message rawMessage) {

if (connection.getTracer() == null) {
throw new IllegalStateException("no tracer configured");
} else {
final Span span = newChildSpan(parent, "delegate Command request");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
return span;
}
final Span span = newChildSpan(parent, "delegate Command request");
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
return span;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected ConnectionEventProducer connectionEventProducer() {
*/
protected TenantClient tenantClient() {
return new ProtonBasedTenantClient(
HonoConnection.newConnection(vertx, config.tenant),
HonoConnection.newConnection(vertx, config.tenant, tracer),
messageSamplerFactory,
protocolAdapterProperties,
newCaffeineCache(config.tenant));
Expand All @@ -179,7 +179,7 @@ protected TenantClient tenantClient() {
*/
protected DeviceRegistrationClient registrationClient() {
return new ProtonBasedDeviceRegistrationClient(
HonoConnection.newConnection(vertx, config.registration),
HonoConnection.newConnection(vertx, config.registration, tracer),
messageSamplerFactory,
protocolAdapterProperties,
newCaffeineCache(config.registration));
Expand All @@ -192,7 +192,7 @@ protected DeviceRegistrationClient registrationClient() {
*/
protected CredentialsClient credentialsClient() {
return new ProtonBasedCredentialsClient(
HonoConnection.newConnection(vertx, config.credentials),
HonoConnection.newConnection(vertx, config.credentials, tracer),
messageSamplerFactory,
protocolAdapterProperties,
newCaffeineCache(config.credentials));
Expand All @@ -205,7 +205,7 @@ protected CredentialsClient credentialsClient() {
*/
protected CommandRouterClient commandRouterClient() {
return new ProtonBasedCommandRouterClient(
HonoConnection.newConnection(vertx, config.commandRouter),
HonoConnection.newConnection(vertx, config.commandRouter, tracer),
messageSamplerFactory,
protocolAdapterProperties);
}
Expand All @@ -217,7 +217,7 @@ protected CommandRouterClient commandRouterClient() {
*/
protected DeviceConnectionClient deviceConnectionClient() {
return new ProtonBasedDeviceConnectionClient(
HonoConnection.newConnection(vertx, config.deviceConnection),
HonoConnection.newConnection(vertx, config.deviceConnection, tracer),
messageSamplerFactory,
protocolAdapterProperties);
}
Expand All @@ -229,7 +229,7 @@ protected DeviceConnectionClient deviceConnectionClient() {
*/
protected ProtonBasedDownstreamSender downstreamSender() {
return new ProtonBasedDownstreamSender(
HonoConnection.newConnection(vertx, config.messaging),
HonoConnection.newConnection(vertx, config.messaging, tracer),
messageSamplerFactory,
protocolAdapterProperties);
}
Expand All @@ -240,7 +240,7 @@ protected ProtonBasedDownstreamSender downstreamSender() {
* @return The connection.
*/
protected HonoConnection commandConsumerConnection() {
return HonoConnection.newConnection(vertx, config.command);
return HonoConnection.newConnection(vertx, config.command, tracer);
}

/**
Expand Down Expand Up @@ -298,7 +298,7 @@ protected CommandTargetMapper commandTargetMapper() {
*/
protected CommandResponseSender commandResponseSender() {
return new ProtonBasedCommandResponseSender(
HonoConnection.newConnection(vertx, config.command),
HonoConnection.newConnection(vertx, config.command, tracer),
messageSamplerFactory,
protocolAdapterProperties);
}
Expand Down

0 comments on commit 4305490

Please sign in to comment.