-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.x: Use MP OpenTelemetry instead of OpenTracing in archetypes (#7993)
Signed-off-by: tvallin <[email protected]>
- Loading branch information
Showing
7 changed files
with
183 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...don/src/main/archetype/mp/custom/files/src/main/java/__pkg__/TracedResource.java.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
archetypes/helidon/src/main/archetype/mp/custom/tracing-outputs.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters