Skip to content

Jaeger sample #15

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions addons/jaeger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Sample Apps for Jaeger-Addon

web-service1 is the root service which calls web-service2 and web-service3.

web-service2 and web-service3 can also run independently.



Steps to Run:

1. run maven build for each web-service
2. mvn seedstack:run is the command to start each web-service
3. web-service1, web-service2, web-service3 will start on port 8080, 9000, 8090 respectively
4. you need a collector to collect the traces send by above web services and that can be downloaded from https://www.jaegertracing.io/download/ ( see binary for windows, simpler one ).
5. start the jaeger-all-in-one.exe as back-end service (Collector)


URLs of Web Services-

web-service1-> http://localhost:8080/api/v1/names/random

web-service2-> http://localhost:9000/api/v1/animals/random

web-service3-> http://localhost:8090/api/v1/scientists/random

now access- http://localhost:16686/search to see the jaeger traces



109 changes: 109 additions & 0 deletions addons/jaeger/web-service1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.seedstack.samples</groupId>
<artifactId>samples</artifactId>
<version>20.11-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>web-service1</artifactId>

<properties>
<hibernate-validator.version>6.1.6.Final</hibernate-validator.version>
<logback.version>1.2.3</logback.version>
<assertj.version>3.12.1</assertj.version>
<rest-assured.version>3.3.0</rest-assured.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.seedstack</groupId>
<artifactId>seedstack-maven-plugin</artifactId>
<executions>
<execution>
<id>build-capsule</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


<dependencies>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-core</artifactId>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web-core</artifactId>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web-security</artifactId>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-rest-jersey2</artifactId>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.seedstack.business</groupId>
<artifactId>business-core</artifactId>
</dependency>
<dependency>
<groupId>org.seedstack.addons.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>

<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-testing-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.seedstack.addons.jaeger</groupId>
<artifactId>jaeger</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.generated.project.domain.model.aggregate;

import org.seedstack.business.domain.BaseAggregateRoot;


public class Aggregate extends BaseAggregateRoot<String> {
private String id;


public Aggregate(String id) {
this.id = id;
}

@Override
public String getId() {
return id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Creation : 9 Jun 2021
*/
package org.generated.project.domain.services;

import java.util.Map;

import io.jaegertracing.internal.metrics.Counter;
import io.jaegertracing.internal.metrics.Gauge;
import io.jaegertracing.internal.metrics.Timer;
import io.jaegertracing.spi.MetricsFactory;

public class MyMetricFactory implements MetricsFactory {

@Override
public Counter createCounter(String name, Map<String, String> tags) {
return new Counter() {

@Override
public void inc(long delta) {
}
};
}

@Override
public Timer createTimer(final String name, final Map<String, String> tags) {
return new Timer() {

@Override
public void durationMicros(long time) {
}
};
}

@Override
public Gauge createGauge(final String name, final Map<String, String> tags) {
return new Gauge() {

@Override
public void update(long amount) {
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.generated.project.domain.services;

import io.opentracing.propagation.TextMap;
import okhttp3.Request;

import java.util.Iterator;
import java.util.Map;

public class RequestBuilderCarrier implements TextMap {
private final Request.Builder requestBuilder;

public RequestBuilderCarrier(Request.Builder requestBuilder) {
this.requestBuilder = requestBuilder;
}

@Override
public Iterator<Map.Entry<String, String>> iterator() {
throw new UnsupportedOperationException("carrier is writer-only");
}

@Override
public void put(String key, String value) {
requestBuilder.addHeader(key, value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.generated.project.interfaces.rest;

import java.io.IOException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.generated.project.domain.services.RequestBuilderCarrier;
import org.seedstack.jaeger.Tracing;

import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

@Path("/api/v1/names")
public class NameGeneratorService {

OkHttpClient client = new OkHttpClient();

@Tracing("name-svc")
private Tracer tracer;

@GET
@Path("/random")
public String name() throws Exception {

Span span = tracer.buildSpan("generate-name").start();

Span scientistSpan = tracer.buildSpan("scientist-name-service").asChildOf(span).start();
String scientist = makeRequest("http://localhost:8090/api/v1/scientists/random", scientistSpan);
scientistSpan.finish();

Span animalSpan = tracer.buildSpan("animal-name-service").asChildOf(span).start();
String animal = makeRequest("http://localhost:9000/api/v1/animals/random", animalSpan);
animalSpan.finish();

String name = scientist + "<-->" + animal;
span.setTag("name", "HeynameTag");
span.finish();
return name;
}

private String makeRequest(String url, Span span) throws IOException {
Request.Builder requestBuilder = new Request.Builder().url(url);

SpanContext spanContext = span.context();
Format<TextMap> format = Format.Builtin.HTTP_HEADERS;
RequestBuilderCarrier requestBuilderCarriernew = new RequestBuilderCarrier(requestBuilder);

tracer.inject(spanContext, format, requestBuilderCarriernew);

Request request = requestBuilder.build();

try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
}

}
76 changes: 76 additions & 0 deletions addons/jaeger/web-service1/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Put main configuration in this file
# See http://seedstack.org/docs/seed/configuration for more information

logging:
level: INFO

application:
# Unique identifier of the application accross your organization
id: Web-Service1
# Make sure all your application base packages are listed below
basePackages: [ org.generated.project ]

security:
# The security configuration realm uses the 'users' section below (replace it with a more useful realm later)
# See http://seedstack.org/docs/seed/manual/security/#realms for more information
realms: ConfigurationRealm
users:
# A default 'demo' user is defined with password 'demo'
demo: demo
web:
server:
host: localhost
port: 8080

# The 'urls' section below in used to secure HTTP requests
# See http://seedstack.org/docs/seed/manual/security/#http-access-control for more information
urls:
# -
# pattern: /api/**
# filters: authcBasic


jaeger:
#whether using Jaeger in devMode (boolean )
devMode: false
samplerConfig:
#The sampler type ( String ). Valid values: remote (default),ratelimiting, probabilistic, const. Optional ( String )
samplerType: const
#The integer or floating point value that makes sense for the correct samplerType (Number). Optional ( String )
samplerParam: 1
#The HTTP host:port when using the remote controlled sampler. optional, ( String )
samplerManagerHostPort: 128.0.0.1
senderConfig:
#The hostname for communicating with agent via UDP ( String )
agentHost: 127.0.0.1
#The port for communicating with agent via UDP ( String )
agentPort: 6831
#The traces endpoint, in case the client should connect directly to the Collector, like http://jaeger-collector:14268/api/traces ( String )
endPoint: http://localhost:14268/api/traces
#Authentication Token to send as "Bearer" to the endpoint ( String )
authToken: myauthtoken
#Username to send as part of "Basic" authentication to the endpoint ( String )
userName: myusername
#Password to send as part of "Basic" authentication to the endpoint ( String )
password: mypassword
reporterConfig:
#Whether the reporter should also log the spans ( boolean )
reporterLogSpans: true
#The reporter's maximum queue size ( String )
reporterMaxQueueSize: 10000
#The reporter's flush interval (ms) ( String )
reporterFlushInterval: 1000
codecConfig:
#Comma separated list of formats to use for propagating the trace context.Defaults to the standard Jaeger format.Valid values are jaeger, b3
propagation: jaeger,b3
tracerConfig:
#Opt-in to use 128 bit traceIds. By default, uses 64 bits ( boolean ).
traceId128Bit: false
#The fully qualified class name of the Metrics factory (Optional). (Class<? extends io.jaegertracing.spi.MetricsFactory>)
metricsFactory: #org.generated.project.domain.services.MyMetricFactory
#A comma separated list of name = value tracer level tags, which get added to all reported spans.default is optional
tracerTags:
tracerTag1: TracerValue1
tracerTag2: TracerValue2


Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.generated.project.interfaces.rest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.seedstack.seed.Configuration;
import org.seedstack.seed.testing.junit4.SeedITRunner;
import org.seedstack.seed.undertow.LaunchWithUndertow;

@RunWith(SeedITRunner.class)
@LaunchWithUndertow
public class HelloResourceIT {
@Configuration("runtime.web.baseUrl")
private String baseUrl;

@Test
public void testHelloWorld() throws Exception {
// Response response = given().auth().basic("demo", "demo").expect().statusCode(200).when().get(baseUrl + "/hello");

// assertThat(response.body().asString()).isEqualTo("Hello World!");
}
}
Loading