Skip to content

Commit

Permalink
added jaeger support from svc_ping
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir.Shapkin authored and Vladimir.Shapkin committed May 30, 2024
1 parent 6161b10 commit 414e853
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 6 deletions.
57 changes: 57 additions & 0 deletions mesh/istio-gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: req-gateway
spec:
# The selector matches the ingress gateway pod labels.
# If you installed Istio using Helm following the standard documentation, this would be "istio=ingress"
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 8080
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: req-router
spec:
hosts:
- "*"
gateways:
- req-gateway
http:
- match:
- uri:
prefix: /api/callcount
- uri:
prefix: /api/callping
- uri:
exact: /api/callpinghdr
ignoreUriCase: true
route:
- destination:
host: req-app
port:
number: 8080
- match:
- uri:
exact: /productpage
- uri:
prefix: /static
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
---
16 changes: 15 additions & 1 deletion mesh/run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ kubectl port-forward service/req-app 8080:8080 # Forward service port t
#kubectl get svc "$INGRESS_NAME" -n "$INGRESS_NS"
#kubectl describe svc istio-ingressgateway -n istio-system - opened port


#running jaeger locally
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.50
14 changes: 11 additions & 3 deletions mesh/svc_ping/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<groupId>io.helidon.microprofile.telemetry</groupId>
<artifactId>helidon-microprofile-telemetry</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-autoconfigure-spi</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-jaeger</artifactId>
Expand Down Expand Up @@ -263,9 +271,6 @@
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
<plugin>
Expand All @@ -284,6 +289,9 @@
<destinationFile>${basedir}/target/classes/META-INF/openapi.yaml</destinationFile>
</configuration>
</execution>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

package mesh.test.rest.incomings.controllers;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.time.Duration;
Expand Down Expand Up @@ -85,8 +88,20 @@ public long count() {
@Override
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public long ping() {
final Span span = Span.current();
final long current = this.counter.getAndIncrement();
LOG.log(System.Logger.Level.TRACE, String.format("Old counter = %d", current));
span.addEvent(
"svc_ping::CounterServiceImpl::ping",
Attributes.of(
AttributeKey.stringKey("Count"),
String.valueOf(current)
)
);
span.setAttribute(
"svc_ping::CounterServiceImpl::Count",
String.valueOf(current)
);
if (current > 10 && current < 15) {
LOG.log(
System.Logger.Level.ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

package mesh.test.rest.incomings.exceptions;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
Expand All @@ -38,6 +41,14 @@
public class MyExceptionMapper implements ExceptionMapper<MyException> {
@Override
public Response toResponse(final MyException exception) {
final Span span = Span.current();
span.recordException(
exception,
Attributes.of(
AttributeKey.stringKey("svc_ping::MyExceptionMapper::MyException"),
"Error"
)
);
return Response
.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(exception.getMessage())
Expand Down
19 changes: 19 additions & 0 deletions mesh/svc_ping/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,24 @@ server:
metrics:
rest-request:
enabled: false
otel:
sdk:
disabled: false
traces:
exporter: jaeger
exporter:
name: svc_ping
jaeger:
endpoint: http://example:4317
# otlp:
# endpoint: http://example:4317
# agent:
# present: true
tracing:
service: "svc_ping"
protocol: "grpc"
# host: "jaeger-collector.istio-system.svc.cluster.local"
host: "localhost"
port: 4317
counterservice:
delay: 5
7 changes: 7 additions & 0 deletions mesh/svc_req/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ otel:
exporter: jaeger
exporter:
name: svc_req
jaeger:
endpoint: http://example:4317
tracing:
service: "svc_req"
protocol: "grpc"
host: "jaeger-collector.istio-system.svc.cluster.local"
port: 14250
org.eclipse.microprofile.rest.client.propagateHeaders: >-
x-request-id,x-b3-traceid,x-b3-spanid,x-b3-parentspanid,x-b3-sampled,x-b3-flags,
x-ot-span-context,x-datadog-trace-id,x-datadog-parent-id,x-datadog-sampling-priority,
Expand Down
28 changes: 26 additions & 2 deletions mesh/test-istio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,18 @@ spec:
ports:
- containerPort: 8080
env:
- name: COUNTERSERVICE_DELAY
value: "5"
- name: COUNTERSERVICE_DELAY
value: "5"
- name: TRACING_SERVICE
value: "svc_ping_tr_v1"
- name: TRACING_PROTOCOL
value: "grpc"
- name: OTEL_PROPAGATORS
value: "jaeger"
- name: OTEL_EXPORTER_JAEGER_ENDPOINT
value: "http://jaeger-collector.istio-system.svc.cluster.local:14250"
- name: OTEL_SERVICE_NAME
value: "svc_ping_v1"
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -224,4 +234,18 @@ spec:
env:
- name: COUNTERSERVICE_DELAY
value: "5"
- name: TRACING_SERVICE
value: "svc_ping"
- name: TRACING_PROTOCOL
value: "http"
- name: TRACING_HOST
value: "jaeger-collector.istio-system.svc.cluster.local"
- name: TRACING_PORT
value: "4317"
- name: OTEL_PROPAGATORS
value: "jaeger"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://jaeger-collector.istio-system.svc.cluster.local:4317"
- name: OTEL_SERVICE_NAME
value: "svc_ping_v2"
---

0 comments on commit 414e853

Please sign in to comment.