diff --git a/pom.xml b/pom.xml index 53f7962..2c2a9ed 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 5.0.0-SNAPSHOT true ${project.basedir}/src/main/resources/META-INF/MANIFEST.MF - 1.15.2 + 1.17.6 diff --git a/vertx-opentelemetry/src/main/java/io/vertx/tracing/opentelemetry/OpenTelemetryOptions.java b/vertx-opentelemetry/src/main/java/io/vertx/tracing/opentelemetry/OpenTelemetryOptions.java index bd8dcf5..f6a52a1 100644 --- a/vertx-opentelemetry/src/main/java/io/vertx/tracing/opentelemetry/OpenTelemetryOptions.java +++ b/vertx-opentelemetry/src/main/java/io/vertx/tracing/opentelemetry/OpenTelemetryOptions.java @@ -13,7 +13,6 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Span; -import io.opentelemetry.context.Scope; import io.vertx.codegen.annotations.DataObject; import io.vertx.core.json.JsonObject; import io.vertx.core.spi.tracing.VertxTracer; @@ -26,16 +25,13 @@ public class OpenTelemetryOptions extends TracingOptions { public OpenTelemetryOptions(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; - this.setFactory(OpenTelemetryTracingFactory.INSTANCE); } public OpenTelemetryOptions() { - this.setFactory(OpenTelemetryTracingFactory.INSTANCE); } public OpenTelemetryOptions(JsonObject json) { super(json); - this.setFactory(OpenTelemetryTracingFactory.INSTANCE); } VertxTracer buildTracer() { diff --git a/vertx-opentracing/src/main/java/examples/OpenTracingExamples.java b/vertx-opentracing/src/main/java/examples/OpenTracingExamples.java index c9b25c5..313969b 100644 --- a/vertx-opentracing/src/main/java/examples/OpenTracingExamples.java +++ b/vertx-opentracing/src/main/java/examples/OpenTracingExamples.java @@ -12,6 +12,7 @@ import io.vertx.core.tracing.TracingPolicy; import io.vertx.docgen.Source; import io.vertx.tracing.opentracing.OpenTracingOptions; +import io.vertx.tracing.opentracing.OpenTracingTracer; import io.vertx.tracing.opentracing.OpenTracingUtil; @Source @@ -26,11 +27,10 @@ public void ex1() { } public void ex2(Tracer tracer) { - Vertx vertx = Vertx.vertx(new VertxOptions() - .setTracingOptions( - new OpenTracingOptions(tracer) - ) - ); + Vertx vertx = Vertx + .builder() + .withTracer(o -> new OpenTracingTracer(false, tracer)) + .build(); } public void ex3(Vertx vertx) { diff --git a/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingOptions.java b/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingOptions.java index ce39884..5bea935 100644 --- a/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingOptions.java +++ b/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingOptions.java @@ -10,7 +10,6 @@ */ package io.vertx.tracing.opentracing; -import io.opentracing.Tracer; import io.vertx.codegen.annotations.DataObject; import io.vertx.core.json.JsonObject; import io.vertx.core.tracing.TracingOptions; @@ -18,42 +17,19 @@ @DataObject public class OpenTracingOptions extends TracingOptions { - private Tracer tracer; - public OpenTracingOptions() { - this.setFactory(OpenTracingTracerFactory.INSTANCE); - } - - public OpenTracingOptions(Tracer tracer) { - this.tracer = tracer; - this.setFactory(OpenTracingTracerFactory.INSTANCE); } public OpenTracingOptions(OpenTracingOptions other) { - tracer = other.tracer; - this.setFactory(OpenTracingTracerFactory.INSTANCE); + super(other); } public OpenTracingOptions(JsonObject json) { super(json); - this.setFactory(OpenTracingTracerFactory.INSTANCE); } @Override public OpenTracingOptions copy() { return new OpenTracingOptions(this); } - - // Visible for testing - Tracer getTracer() { - return tracer; - } - - io.vertx.core.spi.tracing.VertxTracer buildTracer() { - if (tracer != null) { - return new OpenTracingTracer(false, tracer); - } else { - return new OpenTracingTracer(true, OpenTracingTracer.createDefaultTracer()); - } - } } diff --git a/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingTracerFactory.java b/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingTracerFactory.java index f1a1747..c53350f 100644 --- a/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingTracerFactory.java +++ b/vertx-opentracing/src/main/java/io/vertx/tracing/opentracing/OpenTracingTracerFactory.java @@ -10,6 +10,7 @@ */ package io.vertx.tracing.opentracing; +import io.opentracing.Tracer; import io.vertx.core.json.JsonObject; import io.vertx.core.spi.VertxTracerFactory; import io.vertx.core.spi.tracing.VertxTracer; @@ -17,17 +18,23 @@ public class OpenTracingTracerFactory implements VertxTracerFactory { - static final OpenTracingTracerFactory INSTANCE = new OpenTracingTracerFactory(); + private final Tracer tracer; + + public OpenTracingTracerFactory() { + this(null); + } + + public OpenTracingTracerFactory(Tracer tracer) { + this.tracer = tracer; + } @Override public VertxTracer tracer(TracingOptions options) { - OpenTracingOptions openTracingOptions; - if (options instanceof OpenTracingOptions) { - openTracingOptions = (OpenTracingOptions) options; + if (tracer != null) { + return new OpenTracingTracer(false, tracer); } else { - openTracingOptions = new OpenTracingOptions(options.toJson()); + return new OpenTracingTracer(true, OpenTracingTracer.createDefaultTracer()); } - return openTracingOptions.buildTracer(); } @Override diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/EventBusTest.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/EventBusTest.java index f7bfd67..ad42e1f 100644 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/EventBusTest.java +++ b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/EventBusTest.java @@ -38,7 +38,7 @@ public class EventBusTest { @Before public void before() { tracer = new MockTracer(); - vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer))); + vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build(); client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080)); } diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/HttpTest.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/HttpTest.java index 3d4f08c..fb5e684 100644 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/HttpTest.java +++ b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/HttpTest.java @@ -41,7 +41,7 @@ public class HttpTest { @Before public void before() { tracer = new MockTracer(); - vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer))); + vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build(); } @After diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingOptionsTest.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingOptionsTest.java deleted file mode 100644 index c95b492..0000000 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingOptionsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2011-2021 Contributors to the Eclipse Foundation - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 - */ - -package io.vertx.tracing.opentracing; - -import io.opentracing.mock.MockTracer; -import io.vertx.core.spi.VertxTracerFactory; -import io.vertx.core.tracing.TracingOptions; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -public class OpenTracingOptionsTest { - - @Test - public void testCopy() { - MockTracer tracer = new MockTracer(); - TracingOptions options = new OpenTracingOptions(tracer); - TracingOptions copy = options.copy(); - assertTrue(copy instanceof OpenTracingOptions); - OpenTracingOptions other = (OpenTracingOptions) copy; - assertSame(tracer, other.getTracer()); - } - - @Test - public void testDefaultFactory() { - TracingOptions options = new OpenTracingOptions(); - assertNotNull(options.getFactory()); - assertEquals(OpenTracingTracerFactory.INSTANCE, options.getFactory()); - } - - @Test - public void testFactory() { - TracingOptions options = new OpenTracingOptions().setFactory(VertxTracerFactory.NOOP); - assertNotNull(options.getFactory()); - assertNotEquals(OpenTracingTracerFactory.INSTANCE, options.getFactory()); - assertEquals(VertxTracerFactory.NOOP, options.getFactory()); - } -} diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingTest.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingTest.java index 1d8dad0..3f9738c 100644 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingTest.java +++ b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingTest.java @@ -21,6 +21,7 @@ import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpMethod; import io.vertx.core.http.HttpServerOptions; +import io.vertx.core.tracing.TracingOptions; import io.vertx.core.tracing.TracingPolicy; import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; @@ -47,7 +48,7 @@ public class OpenTracingTest { @Before public void before() { tracer = new MockTracer(); - vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer))); + vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build(); } @After diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingUtilTest.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingUtilTest.java index 5d31147..a24c5dc 100644 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingUtilTest.java +++ b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/OpenTracingUtilTest.java @@ -35,7 +35,7 @@ public class OpenTracingUtilTest { @Before public void before() { tracer = new MockTracer(); - vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer))); + vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build(); } @After diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/SqlClientTest.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/SqlClientTest.java index 7a68fda..d67486b 100644 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/SqlClientTest.java +++ b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/SqlClientTest.java @@ -71,7 +71,7 @@ public static void stopDB() { @Before public void before() { tracer = new MockTracer(); - vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new OpenTracingOptions(tracer))); + vertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build(); pool = PgBuilder.pool().connectingTo(connectOptions).using(vertx).build(); } diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/BasicTracingIT.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/BasicTracingIT.java index 3db2db7..5c02880 100644 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/BasicTracingIT.java +++ b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/BasicTracingIT.java @@ -13,6 +13,7 @@ import io.vertx.junit5.VertxExtension; import io.vertx.junit5.VertxTestContext; import io.vertx.tracing.opentracing.OpenTracingOptions; +import io.vertx.tracing.opentracing.OpenTracingTracerFactory; import io.vertx.tracing.opentracing.it.jaegercontainer.JaegerContainerAllIn; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -50,10 +51,7 @@ public static void deploy(VertxTestContext context) { tracer = JAEGER_ALL_IN_ONE.createTracer(JAEGER_SERVICE_NAME); deployCheck.flag(); - tracedVertx = Vertx.vertx( - new VertxOptions().setTracingOptions( - new OpenTracingOptions(tracer)) - ); + tracedVertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build(); HttpClient client = tracedVertx.createHttpClient(); tracedVertx.deployVerticle(ServerVerticle.class.getName()).onComplete(context.succeeding(id -> { client.request(HttpMethod.GET, 8080,"localhost","/health") diff --git a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/CustomTracingIT.java b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/CustomTracingIT.java index d1b9df6..d9c68a3 100644 --- a/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/CustomTracingIT.java +++ b/vertx-opentracing/src/test/java/io/vertx/tracing/opentracing/it/CustomTracingIT.java @@ -18,6 +18,7 @@ import io.vertx.junit5.VertxExtension; import io.vertx.junit5.VertxTestContext; import io.vertx.tracing.opentracing.OpenTracingOptions; +import io.vertx.tracing.opentracing.OpenTracingTracerFactory; import io.vertx.tracing.opentracing.OpenTracingUtil; import io.vertx.tracing.opentracing.it.jaegercontainer.JaegerContainerAllIn; import org.junit.jupiter.api.AfterAll; @@ -58,10 +59,7 @@ public static void deploy(VertxTestContext context) { JAEGER_ALL_IN_ONE.start(); tracer = JAEGER_ALL_IN_ONE.createTracer(JAEGER_SERVICE_NAME); deployCheck.flag(); - tracedVertx = Vertx.vertx( - new VertxOptions().setTracingOptions( - new OpenTracingOptions(tracer)) - ); + tracedVertx = Vertx.builder().withTracer(new OpenTracingTracerFactory(tracer)).build(); HttpClient client = tracedVertx.createHttpClient(); tracedVertx.deployVerticle(ServerVerticle.class.getName()).onComplete(context.succeeding(id -> { client.request(HttpMethod.GET, 8080,"localhost","/health") diff --git a/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/VertxSender.java b/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/VertxSender.java index d1251bd..a237454 100644 --- a/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/VertxSender.java +++ b/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/VertxSender.java @@ -56,7 +56,7 @@ public class VertxSender extends Sender { public VertxSender(HttpSenderOptions options) { this.options = new HttpSenderOptions(options); this.endpoint = options.getSenderEndpoint(); - this.vertx = Vertx.vertx(new VertxOptions().setTracingOptions(new TracingOptions().setFactory(VertxTracerFactory.NOOP))); + this.vertx = Vertx.builder().withTracer(VertxTracerFactory.NOOP).build(); this.client = vertx.createHttpClient(options); } diff --git a/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/ZipkinTracingOptions.java b/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/ZipkinTracingOptions.java index fda0bf1..e3be92f 100644 --- a/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/ZipkinTracingOptions.java +++ b/vertx-zipkin/src/main/java/io/vertx/tracing/zipkin/ZipkinTracingOptions.java @@ -34,16 +34,13 @@ public class ZipkinTracingOptions extends TracingOptions { public ZipkinTracingOptions(HttpTracing httpTracing) { this.httpTracing = httpTracing; - this.setFactory(ZipkinTracerFactory.INSTANCE); } public ZipkinTracingOptions(Tracing tracing) { this.httpTracing = HttpTracing.newBuilder(tracing).build(); - this.setFactory(ZipkinTracerFactory.INSTANCE); } public ZipkinTracingOptions() { - this.setFactory(ZipkinTracerFactory.INSTANCE); } public ZipkinTracingOptions(ZipkinTracingOptions other) { @@ -52,13 +49,11 @@ public ZipkinTracingOptions(ZipkinTracingOptions other) { this.supportsJoin = other.supportsJoin; this.senderOptions = other.senderOptions == null ? null : new HttpSenderOptions(other.senderOptions); this.httpTracing = other.httpTracing == null ? null : other.httpTracing.toBuilder().build(); - this.setFactory(ZipkinTracerFactory.INSTANCE); } public ZipkinTracingOptions(JsonObject json) { super(json); ZipkinTracingOptionsConverter.fromJson(json, this); - this.setFactory(ZipkinTracerFactory.INSTANCE); } @Override diff --git a/vertx-zipkin/src/test/java/io/vertx/tracing/zipkin/ZipkinTracingOptionsTest.java b/vertx-zipkin/src/test/java/io/vertx/tracing/zipkin/ZipkinTracingOptionsTest.java index 90181b7..7c7423a 100644 --- a/vertx-zipkin/src/test/java/io/vertx/tracing/zipkin/ZipkinTracingOptionsTest.java +++ b/vertx-zipkin/src/test/java/io/vertx/tracing/zipkin/ZipkinTracingOptionsTest.java @@ -40,19 +40,4 @@ public void testBuildFromJsonOptions() { VertxSender sender = tracer.sender(); assertEquals(senderOptions.toJson(), sender.options().toJson()); } - - @Test - public void testDefaultFactory() { - TracingOptions options = new ZipkinTracingOptions(); - assertNotNull(options.getFactory()); - assertEquals(ZipkinTracerFactory.INSTANCE, options.getFactory()); - } - - @Test - public void testFactory() { - TracingOptions options = new ZipkinTracingOptions().setFactory(VertxTracerFactory.NOOP); - assertNotNull(options.getFactory()); - assertNotEquals(ZipkinTracerFactory.INSTANCE, options.getFactory()); - assertEquals(VertxTracerFactory.NOOP, options.getFactory()); - } }