Skip to content

4.x: Use MP OpenTelemetry instead of OpenTracing in archetypes #7993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 1 addition & 16 deletions archetypes/helidon/src/main/archetype/common/observability.xml
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,12 @@ curl -X GET http://localhost:8080/observe/health/ready
optional="true">
<option value="jaeger"
name="Jaeger"
description="Send traces to a Jaeger backend" >
description="Send traces to a Jaeger backend">
<output>
<model>
<list key="dependencies">
<map order="800">
<value key="groupId">io.helidon.tracing.providers</value>
<value key="artifactId">helidon-tracing-providers-jaeger</value>
</map>
</list>
<list key="readme-sections">
<value file="/common/files/README.jaeger.md"/>
</list>
<list key="config-properties">
<value>tracing.global=false</value>
</list>
</model>
</output>
</option>
Expand All @@ -427,12 +418,6 @@ curl -X GET http://localhost:8080/observe/health/ready
description="Send traces to a Zipkin backend">
<output>
<model>
<list key="dependencies">
<map order="800">
<value key="groupId">io.helidon.tracing.providers</value>
<value key="artifactId">helidon-tracing-providers-zipkin</value>
</map>
</list>
<list key="readme-sections">
<value file="/common/files/README.zipkin.md"/>
</list>
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
32 changes: 2 additions & 30 deletions archetypes/helidon/src/main/archetype/mp/custom/observability.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2022 Oracle and/or its affiliates.
Copyright (c) 2023 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,33 +19,5 @@
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">
<output>
<model if="${tracing}">
<list key="dependencies">
<map order="800">
<value key="groupId">io.helidon.microprofile.tracing</value>
<value key="artifactId">helidon-microprofile-tracing</value>
</map>
</list>
<list key="microprofile-config-entries">
<value>tracing.service=helidon-tracing-service</value>
<value>tracing.components.web-server.spans.0.name="HTTP Request"</value>
</list>
<list if="${tracing.provider} == 'jaeger'" key="microprofile-config-entries">
<value>tracing.protocol=http</value>
<value>tracing.host=localhost</value>
<value>tracing.port=14250</value>
<value>tracing.path=/api/traces/mine</value>
<value>tracing.token=token</value>
<value>tracing.propagation=jaeger</value>
</list>
<list if="${tracing.provider} == 'zipkin'" key="microprofile-config-entries">
<value>tracing.protocol=https</value>
<value>tracing.host=192.168.1.1</value>
<value>tracing.port=9987</value>
<value>tracing.path=/api/v2/spans</value>
<value>tracing.api-version=1</value>
</list>
</model>
</output>
<exec src="tracing-outputs.xml" if="${tracing}"/>
</archetype-script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2023 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">
<methods>
<method name="tracing-jaeger">
<output if="${tracing.provider} == 'jaeger'">
<model>
<list key="dependencies">
<map order="800">
<value key="groupId">io.opentelemetry</value>
<value key="artifactId">opentelemetry-exporter-jaeger</value>
</map>
</list>
</model>
</output>
</method>
<method name="tracing-zipkin">
<output if="${tracing.provider} == 'zipkin'">
<model>
<list key="dependencies">
<map order="800">
<value key="groupId">io.opentelemetry</value>
<value key="artifactId">opentelemetry-exporter-zipkin</value>
</map>
</list>
</model>
</output>
</method>
</methods>
<call method="tracing-jaeger"/>
<call method="tracing-zipkin"/>
<output>
<templates engine="mustache" transformations="packaged,mustache">
<directory>files</directory>
<includes>
<include>**/TracedResource.java.mustache</include>
</includes>
</templates>
<model>
<list key="dependencies">
<map order="800">
<value key="groupId">io.helidon.microprofile.telemetry</value>
<value key="artifactId">helidon-microprofile-telemetry</value>
</map>
</list>
<list key="microprofile-config-entries">
<value template="mustache"><![CDATA[
#OpenTelemetry
otel.sdk.disabled=false
otel.traces.exporter={{tracing.provider}}
otel.service.name=helidon-tracing-service]]></value>
</list>
<list key="module-requires">
<value>io.helidon.microprofile.telemetry</value>
</list>
<list key="readme-exercise-the-application">
<value><![CDATA[
Tracing:
```
curl -X GET http://localhost:8080/tracing
"Hello World!"

curl -X GET http://localhost:8080/tracing/span
{"Span":"PropagatedSpan{ImmutableSpanContext{traceId=...}}"}

curl -X GET http://localhost:8080/tracing/custom
{
"Custom Span": "SdkSpan{traceId=..."
}
```
]]></value>
</list>
</model>
</output>
</archetype-script>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">
<exec src="tracing.xml" if="${tracing}" />
<exec src="tracing-outputs.xml" if="${tracing}" />
<output>
<model if="${health} || ${metrics} || ${tracing}">
<list key="module-requires">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ tracing:
service: helidon-tracing-service
]]></value>
</list>
<list key="config-properties" if="${tracing.provider} == 'jaeger'">
<value>tracing.global=false</value>
</list>
<list key="dependencies">
<map>
<value key="groupId">io.helidon.webserver.observe</value>
Expand All @@ -42,8 +45,16 @@ tracing:
<value key="groupId">io.helidon.webserver</value>
<value key="artifactId">helidon-webserver-http2</value>
</map>
<map if="${tracing.provider} == 'jaeger'">
<value key="groupId">io.helidon.tracing.providers</value>
<value key="artifactId">helidon-tracing-providers-jaeger</value>
</map>
<map if="${tracing.provider} == 'zipkin'">
<value key="groupId">io.helidon.tracing.providers</value>
<value key="artifactId">helidon-tracing-providers-zipkin</value>
</map>
</list>
<list key="Main-routing-builder" if="${tracing}">
<list key="Main-routing-builder">
<value>.register("/traced", new TracedService())</value>
</list>
<list key="readme-exercise-the-application">
Expand Down