Repository: EventStore/EventStoreDB-Client-Java
Pull request #274 (2024-05-28 05:26:01)

Add user certificates and otel samples
Changed: Add user certificates and otel samples


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1145707..4eedc7a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,7 @@
 # Changelog
 All notable changes to this project will be documented in this file.
 
-## [Unreleased]
+## [5.4.0] - 2024-05-23
 
 ### Added
 - new connection settings to provide an x.509 certificate for user authentication. [EventStoreDB-Client-Java#266](https://github.com/EventStore/EventStoreDB-Client-Java/pull/266)
diff --git a/db-client-java/build.gradle b/db-client-java/build.gradle
index 91cbd3d..7f7f6a6 100644
--- a/db-client-java/build.gradle
+++ b/db-client-java/build.gradle
@@ -19,7 +19,7 @@ tasks.withType(JavaCompile) {
 }
 
 group = 'com.eventstore'
-version = '5.3.2'
+version = '5.4.0'
 
 java {
     withJavadocJar()
@@ -69,6 +69,8 @@ dependencies {
     testImplementation 'org.slf4j:slf4j-simple:2.0.9'
     testImplementation "io.opentelemetry:opentelemetry-sdk"
     testImplementation "io.opentelemetry:opentelemetry-sdk-testing"
+    testImplementation 'io.opentelemetry:opentelemetry-exporter-logging:1.38.0'
+    testImplementation 'io.opentelemetry:opentelemetry-exporter-otlp-trace:1.14.0'
 }
 
 tasks.withType(Test).configureEach {


Test patch:
diff --git a/db-client-java/src/test/java/com/eventstore/dbclient/samples/authentication/UserCertificate.java b/db-client-java/src/test/java/com/eventstore/dbclient/samples/authentication/UserCertificate.java
new file mode 100644
index 0000000..f97ecdf
--- /dev/null
+++ b/db-client-java/src/test/java/com/eventstore/dbclient/samples/authentication/UserCertificate.java
@@ -0,0 +1,18 @@
+package com.eventstore.dbclient.samples.authentication;
+
+import com.eventstore.dbclient.EventStoreDBClient;
+import com.eventstore.dbclient.EventStoreDBClientSettings;
+
+public class UserCertificate {
+    private static void tracing() {
+        // region client-with-user-certificates
+        EventStoreDBClientSettings settings = EventStoreDBClientSettings.builder()
+                .tls(true)
+                .defaultClientCertificate("/path/to/ca.crt", "/path/to/ca.key")
+                .defaultCredentials("admin", "changeit")
+                .buildConnectionSettings();
+
+        EventStoreDBClient client = EventStoreDBClient.create(settings);
+        // endregion client-with-user-certificates
+    }
+}
diff --git a/db-client-java/src/test/java/com/eventstore/dbclient/samples/opentelemetry/Instrumentation.java b/db-client-java/src/test/java/com/eventstore/dbclient/samples/opentelemetry/Instrumentation.java
new file mode 100644
index 0000000..e505eca
--- /dev/null
+++ b/db-client-java/src/test/java/com/eventstore/dbclient/samples/opentelemetry/Instrumentation.java
@@ -0,0 +1,63 @@
+package com.eventstore.dbclient.samples.opentelemetry;
+
+import com.eventstore.dbclient.*;
+import com.eventstore.dbclient.samples.TestEvent;
+// region import-required-packages
+import io.opentelemetry.exporter.logging.LoggingSpanExporter;
+import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
+import io.opentelemetry.sdk.OpenTelemetrySdk;
+import io.opentelemetry.sdk.resources.Resource;
+import io.opentelemetry.sdk.trace.SdkTracerProvider;
+import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
+// endregion import-required-packages
+
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
+
+public class Instrumentation {
+    private static void tracing(EventStoreDBClient client) throws ExecutionException, InterruptedException {
+        Resource resource = Resource.getDefault().toBuilder()
+                .put(SERVICE_NAME, "sample")
+                .build();
+
+        // region setup-exporter
+        LoggingSpanExporter consoleExporter = LoggingSpanExporter.create();
+
+        OtlpGrpcSpanExporter jaegarExporter = OtlpGrpcSpanExporter.builder()
+                .setEndpoint("http://localhost:4317")
+                .build();
+
+        SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
+                .addSpanProcessor(SimpleSpanProcessor.create(jaegarExporter))
+                .addSpanProcessor(SimpleSpanProcessor.create(consoleExporter))
+                .setResource(resource)
+                .build();
+        // endregion setup-exporter
+
+        // region register-instrumentation
+        OpenTelemetrySdk.builder()
+                .setTracerProvider(sdkTracerProvider)
+                .buildAndRegisterGlobal();
+        // endregion register-instrumentation
+
+        // region setup-client-for-tracing
+        EventData eventData = EventData
+                .builderAsJson(
+                        UUID.randomUUID(),
+                        "some-event",
+                        new TestEvent(
+                                "1",
+                                "some value"
+                        ))
+                .build();
+        // endregion setup-client-for-tracing
+
+        AppendToStreamOptions options = AppendToStreamOptions.get()
+                .expectedRevision(ExpectedRevision.any());
+
+        WriteResult appendResult = client.appendToStream("some-stream", options, eventData)
+                .get();
+    }
+}