From 230f4dd7f8f7ac9c2c64cfe1680adfe5faa1ccce Mon Sep 17 00:00:00 2001 From: Thibault Vallin Date: Wed, 15 Nov 2023 09:10:23 +0100 Subject: [PATCH] 4.x: Use MP OpenTelemetry instead of OpenTracing in archetypes (#7993) Signed-off-by: tvallin --- .../archetype/common/files/README.jaeger.md | 2 +- .../main/archetype/common/observability.xml | 17 +--- .../java/__pkg__/TracedResource.java.mustache | 73 +++++++++++++++ .../archetype/mp/custom/observability.xml | 32 +------ .../archetype/mp/custom/tracing-outputs.xml | 93 +++++++++++++++++++ .../archetype/se/custom/observability.xml | 2 +- .../{tracing.xml => tracing-outputs.xml} | 13 ++- 7 files changed, 183 insertions(+), 49 deletions(-) create mode 100644 archetypes/helidon/src/main/archetype/mp/custom/files/src/main/java/__pkg__/TracedResource.java.mustache create mode 100644 archetypes/helidon/src/main/archetype/mp/custom/tracing-outputs.xml rename archetypes/helidon/src/main/archetype/se/custom/{tracing.xml => tracing-outputs.xml} (77%) diff --git a/archetypes/helidon/src/main/archetype/common/files/README.jaeger.md b/archetypes/helidon/src/main/archetype/common/files/README.jaeger.md index 241f0593419..f418b4b3743 100644 --- a/archetypes/helidon/src/main/archetype/common/files/README.jaeger.md +++ b/archetypes/helidon/src/main/archetype/common/files/README.jaeger.md @@ -19,7 +19,7 @@ docker run -d --name jaeger\ -p 14268:14268\ -p 14269:14269\ -p 9411:9411\ - jaegertracing/all-in-one:1.38 + jaegertracing/all-in-one:1.43 ``` ### View Tracing Using Jaeger UI diff --git a/archetypes/helidon/src/main/archetype/common/observability.xml b/archetypes/helidon/src/main/archetype/common/observability.xml index 8fc2b53ed59..9c18a11db09 100644 --- a/archetypes/helidon/src/main/archetype/common/observability.xml +++ b/archetypes/helidon/src/main/archetype/common/observability.xml @@ -404,21 +404,12 @@ curl -X GET http://localhost:8080/observe/health/ready optional="true"> @@ -427,12 +418,6 @@ curl -X GET http://localhost:8080/observe/health/ready description="Send traces to a Zipkin backend"> - - - io.helidon.tracing.providers - helidon-tracing-providers-zipkin - - diff --git a/archetypes/helidon/src/main/archetype/mp/custom/files/src/main/java/__pkg__/TracedResource.java.mustache b/archetypes/helidon/src/main/archetype/mp/custom/files/src/main/java/__pkg__/TracedResource.java.mustache new file mode 100644 index 00000000000..381fff158e8 --- /dev/null +++ b/archetypes/helidon/src/main/archetype/mp/custom/files/src/main/java/__pkg__/TracedResource.java.mustache @@ -0,0 +1,73 @@ + +package {{package}}; + +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.instrumentation.annotations.WithSpan; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +/** + * A simple JAX-RS resource used for tracing + */ +@Path("/tracing") +public class TracedResource { + + private Span span; + + private Tracer tracer; + + @Inject + TracedResource(Span span, Tracer tracer) { + this.span = span; + this.tracer = tracer; + } + + /** + * Return a worldly greeting message. + * + * @return {@link String} + */ + @GET + @WithSpan("default") + public String getDefaultMessage() { + return "Hello World!"; + } + + /** + * Create an internal custom span and return its description. + * + * @return custom span + */ + @GET + @Path("custom") + @Produces(MediaType.APPLICATION_JSON) + @WithSpan + public String useCustomSpan() { + Span span = tracer.spanBuilder("custom") + .setSpanKind(SpanKind.INTERNAL) + .setAttribute("attribute", "value") + .startSpan(); + span.end(); + + return "Custom Span " + span; + } + + /** + * Get Span info. + * + * @return {@link GreetingMessage} + */ + @GET + @Path("span") + @Produces(MediaType.APPLICATION_JSON) + @WithSpan + public String getSpanInfo() { + return "Span " + span.toString(); + } + +} diff --git a/archetypes/helidon/src/main/archetype/mp/custom/observability.xml b/archetypes/helidon/src/main/archetype/mp/custom/observability.xml index af0bb7d539f..4379c45f1b8 100644 --- a/archetypes/helidon/src/main/archetype/mp/custom/observability.xml +++ b/archetypes/helidon/src/main/archetype/mp/custom/observability.xml @@ -1,7 +1,7 @@ + + + + + + + + io.opentelemetry + opentelemetry-exporter-jaeger + + + + + + + + + + + io.opentelemetry + opentelemetry-exporter-zipkin + + + + + + + + + + + files + + **/TracedResource.java.mustache + + + + + + io.helidon.microprofile.telemetry + helidon-microprofile-telemetry + + + + + + + io.helidon.microprofile.telemetry + + + + + + + diff --git a/archetypes/helidon/src/main/archetype/se/custom/observability.xml b/archetypes/helidon/src/main/archetype/se/custom/observability.xml index 524ed2c0c6e..db722caf323 100644 --- a/archetypes/helidon/src/main/archetype/se/custom/observability.xml +++ b/archetypes/helidon/src/main/archetype/se/custom/observability.xml @@ -19,7 +19,7 @@ - + diff --git a/archetypes/helidon/src/main/archetype/se/custom/tracing.xml b/archetypes/helidon/src/main/archetype/se/custom/tracing-outputs.xml similarity index 77% rename from archetypes/helidon/src/main/archetype/se/custom/tracing.xml rename to archetypes/helidon/src/main/archetype/se/custom/tracing-outputs.xml index 051675de569..34e3d8f154a 100644 --- a/archetypes/helidon/src/main/archetype/se/custom/tracing.xml +++ b/archetypes/helidon/src/main/archetype/se/custom/tracing-outputs.xml @@ -33,6 +33,9 @@ tracing: service: helidon-tracing-service ]]> + + tracing.global=false + io.helidon.webserver.observe @@ -42,8 +45,16 @@ tracing: io.helidon.webserver helidon-webserver-http2 + + io.helidon.tracing.providers + helidon-tracing-providers-jaeger + + + io.helidon.tracing.providers + helidon-tracing-providers-zipkin + - + .register("/traced", new TracedService())