Skip to content

Commit

Permalink
Propagate trace information in the user client
Browse files Browse the repository at this point in the history
Fix: #84
  • Loading branch information
io7m committed Jun 21, 2023
1 parent 77dea58 commit 78294ca
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.io7m.verdant.core.VProtocolSupported;
import com.io7m.verdant.core.VProtocols;
import com.io7m.verdant.core.cb.VProtocolMessages;
import io.opentelemetry.api.OpenTelemetry;
import net.jqwik.api.Arbitraries;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -113,7 +114,9 @@ public void setup()
new IdUClients();
this.client =
this.clients.openAsynchronousClient(
new IdUClientConfiguration(Locale.ROOT)
new IdUClientConfiguration(
OpenTelemetry.noop(),
Locale.ROOT)
);

this.messages =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.io7m.verdant.core.VProtocolSupported;
import com.io7m.verdant.core.VProtocols;
import com.io7m.verdant.core.cb.VProtocolMessages;
import io.opentelemetry.api.OpenTelemetry;
import net.jqwik.api.Arbitraries;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -112,7 +113,9 @@ public void setup()
new IdUClients();
this.client =
this.clients.openSynchronousClient(
new IdUClientConfiguration(Locale.ROOT)
new IdUClientConfiguration(
OpenTelemetry.noop(),
Locale.ROOT)
);

this.messages =
Expand Down
4 changes: 4 additions & 0 deletions com.io7m.idstore.user_client.api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.hibiscus</groupId>
<artifactId>com.io7m.hibiscus.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,33 @@
package com.io7m.idstore.user_client.api;

import com.io7m.hibiscus.api.HBConfigurationType;
import io.opentelemetry.api.OpenTelemetry;

import java.util.Locale;
import java.util.Objects;

/**
* The user client configuration.
*
* @param locale The locale
* @param openTelemetry The OpenTelemetry API
* @param locale The locale
*/

public record IdUClientConfiguration(
OpenTelemetry openTelemetry,
Locale locale)
implements HBConfigurationType
{
/**
* The user client configuration.
*
* @param locale The locale
* @param openTelemetry The OpenTelemetry API
* @param locale The locale
*/

public IdUClientConfiguration
{
Objects.requireNonNull(openTelemetry, "openTelemetry");
Objects.requireNonNull(locale, "locale");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
requires static org.osgi.annotation.bundle;
requires static org.osgi.annotation.versioning;

requires transitive io.opentelemetry.api;
requires transitive com.io7m.hibiscus.api;
requires transitive com.io7m.idstore.protocol.user;

Expand Down
9 changes: 9 additions & 0 deletions com.io7m.idstore.user_client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
</dependency>

<dependency>
<groupId>com.io7m.hibiscus</groupId>
<artifactId>com.io7m.hibiscus.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.io7m.idstore.user_client.api.IdUClientEventType;
import com.io7m.idstore.user_client.api.IdUClientException;
import com.io7m.junreachable.UnreachableCodeException;
import io.opentelemetry.context.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -134,10 +135,27 @@ private static String userAgent()
final var sendBytes =
this.messages.serialize(message);

final var request =
final HttpRequest.Builder builder =
HttpRequest.newBuilder(uri)
.header("User-Agent", userAgent())
.POST(HttpRequest.BodyPublishers.ofByteArray(sendBytes))
.header("User-Agent", userAgent());

/*
* Inject any required trace propagation headers.
*/

this.configuration()
.openTelemetry()
.getPropagators()
.getTextMapPropagator()
.inject(Context.current(), builder, (b, name, value) -> {
if (LOG.isTraceEnabled()) {
LOG.trace("injecting header {} -> {}", name, value);
}
builder.header(name, value);
});

final var request =
builder.POST(HttpRequest.BodyPublishers.ofByteArray(sendBytes))
.build();

final var response =
Expand Down
2 changes: 2 additions & 0 deletions com.io7m.idstore.user_client/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
requires com.io7m.jxtrand.vanilla;
requires com.io7m.verdant.core.cb;
requires com.io7m.verdant.core;
requires io.opentelemetry.api;
requires io.opentelemetry.context;
requires java.net.http;
requires org.slf4j;

Expand Down

0 comments on commit 78294ca

Please sign in to comment.