-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4.x] - MP Telemetry examples (#6813)
MP Telemetry Examples --------- Signed-off-by: Dmitry Aleksandrov <[email protected]> Co-authored-by: Romain Grecourt <[email protected]>
- Loading branch information
1 parent
b705956
commit fc4c3bf
Showing
16 changed files
with
731 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,64 @@ | ||
# Helidon MP Examples | ||
# Helidon MicroProfile Telemetry Example | ||
|
||
This directory contains Helidon MP examples. | ||
This example implements demonstrates usage of MP Telemetry Tracing. | ||
|
||
## Build and run | ||
|
||
With JDK17+ | ||
```bash | ||
mvn package | ||
java -jar greeting/target/helidon-examples-microprofile-telemetry-greeting.jar | ||
``` | ||
|
||
Run Jaeger tracer. If you prefer to use Docker, run in terminal: | ||
```bash | ||
docker run -d --name jaeger \ | ||
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ | ||
-e COLLECTOR_OTLP_ENABLED=true \ | ||
-p 6831:6831/udp \ | ||
-p 6832:6832/udp \ | ||
-p 5778:5778 \ | ||
-p 16686:16686 \ | ||
-p 4317:4317 \ | ||
-p 4318:4318 \ | ||
-p 14250:14250 \ | ||
-p 14268:14268 \ | ||
-p 14269:14269 \ | ||
-p 9411:9411 \ | ||
jaegertracing/all-in-one:1.43 | ||
``` | ||
|
||
If you have Jaeger all-in-one installed, use this command: | ||
|
||
```bash | ||
jaeger-all-in-one --collector.zipkin.host-port=9411 --collector.otlp.enabled=true | ||
``` | ||
|
||
Run the Secondary service: | ||
|
||
With JDK17+ | ||
```bash | ||
mvn package | ||
java -jar secondary/target/helidon-examples-microprofile-telemetry-secondary.jar | ||
``` | ||
|
||
## Exercise the application | ||
|
||
``` | ||
curl -X GET http://localhost:8080/greet | ||
"Hello World!" | ||
curl -X GET http://localhost:8080/greet/span | ||
{"Span":"PropagatedSpan{ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}}"} | ||
curl -X GET http://localhost:8080/greet/custom | ||
{ | ||
"Custom Span": "SdkSpan{traceId=bea7da56d1fe82400af8ec0a8adb370d, spanId=57647ead5dc32ae7, parentSpanContext=ImmutableSpanContext{traceId=bea7da56d1fe82400af8ec0a8adb370d, spanId=0ca670f1e3330ea5, traceFlags=01, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=true}, name=custom, kind=INTERNAL, attributes=AttributesMap{data={attribute=value}, capacity=128, totalAddedValues=1}, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1683724682576003542, endEpochNanos=1683724682576006000}" | ||
} | ||
curl -X GET http://localhost:8080/greet/outbound | ||
Secondary | ||
``` | ||
|
||
Proceed Jaeger UI http://localhost:16686. In the top-down menu select "greeting-service" and click "Find traces". Tracing information should become available. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Helidon MicroProfile Telemetry Example | ||
|
||
This example implements demonstrates usage of MP Telemetry Tracing. | ||
|
||
## Build and run | ||
|
||
With JDK17+ | ||
```bash | ||
mvn package | ||
java -jar greeting/target/helidon-examples-microprofile-telemetry-greeting.jar | ||
``` | ||
|
||
Run Jaeger tracer. If you prefer to use Docker, run in terminal: | ||
```bash | ||
docker run -d --name jaeger \ | ||
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ | ||
-e COLLECTOR_OTLP_ENABLED=true \ | ||
-p 6831:6831/udp \ | ||
-p 6832:6832/udp \ | ||
-p 5778:5778 \ | ||
-p 16686:16686 \ | ||
-p 4317:4317 \ | ||
-p 4318:4318 \ | ||
-p 14250:14250 \ | ||
-p 14268:14268 \ | ||
-p 14269:14269 \ | ||
-p 9411:9411 \ | ||
jaegertracing/all-in-one:1.43 | ||
``` | ||
|
||
If you have Jaeger all-in-one installed, use this command: | ||
|
||
```bash | ||
jaeger-all-in-one --collector.zipkin.host-port=9411 --collector.otlp.enabled=true | ||
``` | ||
|
||
Run the Secondary service: | ||
|
||
With JDK17+ | ||
```bash | ||
mvn package | ||
java -jar secondary/target/helidon-examples-microprofile-telemetry-secondary.jar | ||
``` | ||
|
||
## Exercise the application | ||
|
||
``` | ||
curl -X GET http://localhost:8080/greet | ||
"Hello World!" | ||
curl -X GET http://localhost:8080/greet/span | ||
{"Span":"PropagatedSpan{ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}}"} | ||
curl -X GET http://localhost:8080/greet/custom | ||
{ | ||
"Custom Span": "SdkSpan{traceId=bea7da56d1fe82400af8ec0a8adb370d, spanId=57647ead5dc32ae7, parentSpanContext=ImmutableSpanContext{traceId=bea7da56d1fe82400af8ec0a8adb370d, spanId=0ca670f1e3330ea5, traceFlags=01, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=true}, name=custom, kind=INTERNAL, attributes=AttributesMap{data={attribute=value}, capacity=128, totalAddedValues=1}, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1683724682576003542, endEpochNanos=1683724682576006000}" | ||
} | ||
curl -X GET http://localhost:8080/greet/outbound | ||
Secondary | ||
``` | ||
|
||
Proceed Jaeger UI http://localhost:16686. In the top-down menu select "greeting-service" and click "Find traces". Tracing information should become available. |
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,77 @@ | ||
<?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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.applications</groupId> | ||
<artifactId>helidon-mp</artifactId> | ||
<version>4.0.0-SNAPSHOT</version> | ||
<relativePath>../../../../applications/mp/pom.xml</relativePath> | ||
</parent> | ||
<groupId>io.helidon.examples.microprofile</groupId> | ||
<artifactId>helidon-examples-microprofile-telemetry-greeting</artifactId> | ||
<name>Microprofile Telemetry Greeting Example</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.bundles</groupId> | ||
<artifactId>helidon-microprofile</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-exporter-jaeger</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.telemetry</groupId> | ||
<artifactId>helidon-microprofile-telemetry</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye</groupId> | ||
<artifactId>jandex</artifactId> | ||
<scope>runtime</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-libs</id> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>io.smallrye</groupId> | ||
<artifactId>jandex-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>make-index</id> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
124 changes: 124 additions & 0 deletions
124
...etry/greeting/src/main/java/io/helidon/examples/microprofile/telemetry/GreetResource.java
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,124 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.helidon.examples.microprofile.telemetry; | ||
|
||
import java.util.Collections; | ||
|
||
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.json.Json; | ||
import jakarta.json.JsonBuilderFactory; | ||
import jakarta.json.JsonObject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.client.WebTarget; | ||
import jakarta.ws.rs.core.MediaType; | ||
import org.glassfish.jersey.server.Uri; | ||
|
||
|
||
/** | ||
* A simple JAX-RS resource to greet you. Examples: | ||
* | ||
* Get default greeting message: | ||
* curl -X GET http://localhost:8080/greet | ||
* | ||
* Get Span information: | ||
* curl -X GET http://localhost:8080/greet/span | ||
* | ||
* Call secondary service: | ||
* curl -X GET http://localhost:8080/greet/outbound | ||
*/ | ||
@Path("/greet") | ||
public class GreetResource { | ||
|
||
private static final JsonBuilderFactory JSON = Json.createBuilderFactory(Collections.emptyMap()); | ||
|
||
private Span span; | ||
|
||
private Tracer tracer; | ||
|
||
@Uri("http://localhost:8081/secondary") | ||
private WebTarget target; | ||
|
||
@Inject | ||
GreetResource(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 {@link JsonObject} | ||
*/ | ||
@GET | ||
@Path("custom") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@WithSpan | ||
public JsonObject useCustomSpan(){ | ||
Span span = tracer.spanBuilder("custom") | ||
.setSpanKind(SpanKind.INTERNAL) | ||
.setAttribute("attribute", "value") | ||
.startSpan(); | ||
span.end(); | ||
|
||
return JSON.createObjectBuilder() | ||
.add("Custom Span", span.toString()) | ||
.build(); | ||
} | ||
/** | ||
* Get Span info. | ||
* | ||
* @return {@link JsonObject} | ||
*/ | ||
@GET | ||
@Path("span") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@WithSpan | ||
public JsonObject getSpanInfo(){ | ||
return JSON.createObjectBuilder() | ||
.add("Span", span.toString()) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Call the secondary service running on port 8081. | ||
* | ||
* @return String from the secondary service. | ||
*/ | ||
@GET | ||
@Path("/outbound") | ||
@WithSpan("outbound") | ||
public String outbound() { | ||
return target.request().accept(MediaType.TEXT_PLAIN).get(String.class); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...metry/greeting/src/main/java/io/helidon/examples/microprofile/telemetry/package-info.java
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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* MicroProfile Telemetry example. | ||
*/ | ||
package io.helidon.examples.microprofile.telemetry; |
25 changes: 25 additions & 0 deletions
25
examples/microprofile/telemetry/greeting/src/main/resources/META-INF/beans.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,25 @@ | ||
<?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. | ||
--> | ||
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee | ||
https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd" | ||
version="3.0" | ||
bean-discovery-mode="annotated"> | ||
</beans> |
Oops, something went wrong.