Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 07bf8aa

Browse files
author
Yuri Shkuro
committed
Boorstrap Java lesson 1
1 parent c0db105 commit 07bf8aa

File tree

6 files changed

+79
-38
lines changed

6 files changed

+79
-38
lines changed

java/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
.classpath
2+
.project
3+
.settings/
14
target/

java/README.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
1-
# OpenTracing Tutorial - Go
1+
# OpenTracing Tutorial - Java
22

33
## Installing
44

55
The tutorials are using CNCF Jaeger (https://github.com/jaegertracing/jaeger) as the tracing backend,
66
[see here](../README.md) how to install it in a Docker image.
77

8-
This repository uses [glide](https://github.com/Masterminds/glide) to manage dependencies (installed automatically below).
9-
10-
When you clone the tutorials repository, it should be located in the right place under `$GOPATH`:
11-
12-
```
13-
mkdir -p $GOPATH/src/github.com/yurishkuro/
14-
cd $GOPATH/src/github.com/yurishkuro/
15-
git clone https://github.com/yurishkuro/opentracing-tutorial.git opentracing-tutorial
16-
```
17-
18-
After that, install the dependencies:
8+
This repository uses Maven to manage dependencies. To install all dependencies, run:
199

2010
```
21-
cd $GOPATH/src/github.com/yurishkuro/opentracing-tutorial/go
22-
make install
11+
cd opentracing-tutorial/java
12+
mvn package
2313
```
2414

25-
The rest of the commands in the Go tutorials should be executed relative to this directory.
15+
All subsequent commands in the tutorials should be executed relative to this `java` directory.
2616

2717
## Lessons
2818

29-
* [Lesson 01 - Hello World](lesson01)
19+
* [Lesson 01 - Hello World](./src/main/java/lesson01)
3020
* Instantiate a Tracer
3121
* Create a simple trace
3222
* Annotate the trace
33-
* [Lesson 02 - Context and Tracing Functions](lesson02)
23+
* [Lesson 02 - Context and Tracing Functions](./src/main/java/lesson02)
3424
* Trace individual functions
3525
* Combine multiple spans into a single trace
3626
* Propagate the in-process context
37-
* [Lesson 03 - Tracing RPC Requests](lesson03)
27+
* [Lesson 03 - Tracing RPC Requests](./src/main/java/lesson03)
3828
* Trace a transaction across more than one microservice
3929
* Pass the context between processes using `Inject` and `Extract`
4030
* Apply OpenTracing-recommended tags
41-
* [Lesson 04 - Baggage](lesson04)
31+
* [Lesson 04 - Baggage](./src/main/java/lesson04)
4232
* Understand distributed context propagation
4333
* Use baggage to pass data through the call graph

java/pom.xml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.github.yurishkuro</groupId>
5-
<artifactId>java-opentracing-tutorial</artifactId>
6-
<packaging>jar</packaging>
7-
<version>1.0-SNAPSHOT</version>
8-
<name>java-opentracing-tutorial</name>
9-
<url>http://maven.apache.org</url>
10-
<properties>
11-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12-
</properties>
13-
<dependencies>
14-
<dependency>
15-
<groupId>com.uber.jaeger</groupId>
16-
<artifactId>jaeger-core</artifactId>
17-
<version>0.21.0</version>
18-
</dependency>
19-
</dependencies>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.github.yurishkuro</groupId>
5+
<artifactId>java-opentracing-tutorial</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>java-opentracing-tutorial</name>
9+
<url>http://maven.apache.org</url>
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
13+
<!--
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.codehaus.mojo</groupId>
18+
<artifactId>exec-maven-plugin</artifactId>
19+
<version>1.5</version>
20+
<configuration>
21+
<mainClass>lesson01.solution.Hello</mainClass>
22+
</configuration>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
-->
27+
<dependencies>
28+
<dependency>
29+
<groupId>com.uber.jaeger</groupId>
30+
<artifactId>jaeger-core</artifactId>
31+
<version>0.21.0</version>
32+
</dependency>
33+
</dependencies>
2034
</project>

java/run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
if [ "$1" == "" ]; then
4+
echo "Usage: run.sh qualified-class-name [args]"
5+
exit 1
6+
fi
7+
8+
className=$1
9+
shift
10+
11+
mvn exec:java -Dexec.mainClass="$className" -Dexec.args="$*" | grep -v -e '\[INFO\]' -e '\[WARNING\]' -e '\[ERROR\]'

java/src/main/java/lesson01/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ Learn how to:
1212

1313
### A simple Hello-World program
1414

15-
Let's create a simple Go program `lesson01/hello.go` that takes an argument and prints "Hello, {arg}!".
15+
Let's create a simple Java program `lesson01/Hello.java` that takes an argument and prints "Hello, {arg}!".
16+
17+
```java
18+
public class Hello {
19+
20+
public static void main(String[] args) {
21+
System.out.println("Hello, World");
22+
}
23+
24+
}
25+
1626

17-
```go
1827
package main
1928

2029
import (
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package lesson01.solution;
2+
3+
public class Hello {
4+
5+
public static void main(String[] args) {
6+
if (args.length != 1) {
7+
throw new IllegalArgumentException("Expecting one argument");
8+
}
9+
String helloTo = args[0];
10+
String helloStr = String.format("Hello, %s!", helloTo);
11+
System.out.println(helloStr);
12+
}
13+
14+
}

0 commit comments

Comments
 (0)