Skip to content

Commit

Permalink
Copy jaeger functionality from java-spring-cloud (#1)
Browse files Browse the repository at this point in the history
Copy jaeger functionality from java-spring-cloud
  • Loading branch information
geoand authored May 30, 2018
1 parent 67a9aac commit 9c78ef2
Show file tree
Hide file tree
Showing 35 changed files with 2,728 additions and 12 deletions.
48 changes: 36 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
!.mvn/wrapper/maven-wrapper.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
target

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Eclipse
.project
.classpath
.settings

.gitkeep
.editorconfig

# Intellij Idea
*.iml
.idea/
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
43 changes: 43 additions & 0 deletions .settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018 The OpenTracing Authors
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.
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>sonatype</id>
<username>${env.SONATYPE_USER}</username>
<password>${env.SONATYPE_PASSWORD}</password>
</server>
<server>
<id>bintray</id>
<username>${env.BINTRAY_USER}</username>
<password>${env.BINTRAY_KEY}</password>
</server>
<server>
<id>jfrog-snapshots</id>
<username>${env.BINTRAY_USER}</username>
<password>${env.BINTRAY_KEY}</password>
</server>
<server>
<id>github.com</id>
<username>${env.GH_USER}</username>
<password>${env.GH_TOKEN}</password>
</server>
</servers>
</settings>
45 changes: 45 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
sudo: required
dist: trusty

language: java
jdk:
- oraclejdk8

services:
- docker

cache:
directories:
- $HOME/.m2/repository

before_install:
# allocate commits to CI, not the owner of the deploy key
- git config user.name "opentracingci"
- git config user.email "[email protected]"
# setup https authentication credentials, used by ./mvnw release:prepare
- git config credential.helper "store --file=.git/credentials"
- echo "https://$GH_TOKEN:@github.com" > .git/credentials

install:
# Override default travis to use the maven wrapper
- ./mvnw clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V

script:
- ./travis/publish.sh

branches:
except:
- /^[0-9]/

env:
global:
# Ex. travis encrypt -r org/repo BINTRAY_USER=your_github_account
- secure: "SQyi4nN9p1vFi5InarGtSG52cyCPut1ScHsC/5YXN+UrgO1VY7U8J+dwGJ1hA38QEwGEhWr5Myo452TqA9X0yQVw7Y6WxmJsf6w3qWXitgDLGUzSO1o/aGYts3U1BCbOQWYFwy6JoqhT6EJpu7RVmUfCLyV5eTaMb9xH1RjaPhR1Z6uCwuLS0p881QjL4g95nidAfP3cfJnnaK8gcXCYvIvZo4CNHoNK32xZ4+2YkkhdYngjB6kg7JWiokOwLj/j1Hrkmgg9PbnehG9Iv+7Ca8VUPy+XqeWtMpSy4wl1gWsvLA9QAfeynLysRwO9cz36V64mPX1lqhydgn7M/66T9Ckmzdo1u3yjazOn0uA8VLlVzVfKBjW9uJg0yh2hgc4p3aSz1ltx9L46qjU8reMdNlRpEE6zXtxycdXXJTdvg06UCuPAnSmDvOyOzx1H31cuxhcz/iD9/ogLwV5YZ5c3G49YRF4j0mknl3rpMVr2KWStbjOIi00vRiQD96wMVj/Ug56PTjBs0XLHQmnyKkOW8GDi1U64qKlGSYGWOYroQueE1UjkX1xx3y8TvNtHQpttIOh5SOcRxi6zVvW3dzSnP7vsuTFsd4s4xcNEjqa8kfUvB/adQ91cT4nFR1bZSuwfKXr7Bw4zofKzHHRar+iMDlPl++L6tIq/32KB9UL0/RQ="
# Ex. travis encrypt -r org/repo BINTRAY_KEY=xxx-https://bintray.com/profile/edit-xxx --add
- secure: "kWeuL485vL9ab7qT4QfE4TydKx5LjL5jNcGnAiPzFyDpSgvq6V+rM2iUtHrboEX9Q3iEn3lWHDuTQDTSjmdea9fSdEtPx5+iTnGDBGM8vI7xFG2Mp510YxwT3EANhdgieduik54DLvCBtoZISkQgAIYTOXQTmK4VgrE+VE8Cchey/Q2YfNFHdGp93HrmtpgKfVPZstvOrPvlU2nak/nLJ7VbmwvCly1s5CrS+wBTMZLYXaYYUq7o9pS1XeaS+enUSqF3/EEpEbHPfTEQnIU+sGI6kUfZvk7uis49KECFoEYRGfcTemrm+V9ToEWFrTqFiKeuSBvDwdlBowU4qa44rJbKOBpWUsFZlw1tUWbTWI5ldyxUpXglDNhxMoECDap/yAgldAupvGg1wA78E1jpQTnyrkGfCbiMEF0j6bdJBjr4O7LCwFfGLCrlqdnhUVRS2ohTBCVNYfovUYM93VUZg1ewgOGZwVRPdP9dWo2GjgDLVSEdpVWEZDe63NrHiuAeyCD5WeEB7CdjSJbOxej+sjg0PeiLiIScVGwSFnNsL65dtgnoVt36rMYMB253Wh02aPH5RdQvHFS1dfo6I0uObLVgnIDXbZXKCSudpRNAffyUjhBuEWqsEsfwDwDhvZ4PiMJMWlJICNCkMzkvAnqtWfBHbELmEf4Jd5HZN2x6eMk="
# Ex. travis encrypt -r org/repo GH_TOKEN=XXX-https://github.com/settings/tokens-XXX --add
- secure: "bw/UJMLZ3kqACD6eyYKYWvWr4UknNUULymhp2F+gl2FpAoQ2QqDtF0cAtyvm6Tp9i08XD2TBMSlZsu/AxYxSS6o8Xkx8E8IQovVXjKrGheHNDrmQ8LUFrNFzLPGh6i73BKma8bi/zyCT7Lvbi7qcBA0gbNOXPLM+jov0RUiibb0fwSkRfaP7EjDNmoZQmPthftfPcle1tNF9yTnHdRZ8W2pXrI1Tl7t1r2Q1GP0jji+2Xs4V7FFPiyIITzZyAAyAWoN50DPW4gNXD/LVB8la5R8v0JMwT8s5DC+FqOAuReF7anstcWZU3IHRi1Zv0jktWeA9VsGJf1BO7P9Wu36Uo4aWBaX1sFTAT2v7WXaeo1Shcz6Zgs79VUz+l5AE8GRLJ9hgvV2pBx94UpDza5jwDANOaiKc0rFiYACxW0sJVUtSjF50mdwBY22eOQam1NIfHss+nSVws4OOOcV3ud6D92622BdAuo9ZffjRubBCfdOKf21GARFSTiKKL293UABtGekgZ9VYYE3fElIdiIADuc9TchxLFFPXOkVUtSkDMU04+Bqwd1AqU8filoS2B4KkawsFhzvMQuntkM+1mQkuauRLYaR8T3sYwCBfWI9Eay9DCv4dmSwWOMCe51TZeuJDi/27mae2txrQ0kKqS4C7kptEGdR32+vntZ7pf+I2Ba4="
# Ex. travis encrypt -r org/repo SONATYPE_USER=your_sonatype_account
- secure: "Ok45bs1fs/9AfrMzyzx0UgI0zF1rNQimEsnEOhOfCDvAnvyXPYOZpW8sXEdkvqMGpvMduvg70kVU1Ms9D8y79hRhm0hGoFPesC7CPGeF0ennILlopheFuoS3xwBGSVT+GOtutityOZtfMUDos+F0aj/jF9m3N4Magat6cPrICjW+owq0GEh0whl1IAWYaZAw3VRp1JwqO23BD7yQsWqLiL6bWSed5lDXhItptp4UtK8KP91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0HRrUZ8UoU0FJGu5BAyadc7HkFuY/ixC/b6KY52DGALUHe9lKvcpEi+c3GyeisdpEUbS63bIthRxNwP6UffNXIW0IdQB90QYZB8="
160 changes: 160 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
[![Build Status][ci-img]][ci] [![Released Version][maven-img]][maven]

## Configuration

```xml
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-jaeger-starter</artifactId>
</dependency>
```

The dependency will ensure that Spring Boot will auto configure a Jaeger implementation of OpenTracing's `Tracer` when the application starts.

If no settings are changed, spans will be reported to the UDP port `6831` of `localhost`.
The simplest way to change this behavior is to set the following properties:

```
opentracing.jaeger.udp-sender.host=jaegerhost
opentracing.jaeger.udp-sender.port=portNumber
```

for the UDP sender, or use an HTTP sender by setting the following property:

`opentracing.jaeger.http-sender.url = http://jaegerhost:portNumber`


## Configuration options

All the available configuration options can be seen in [JaegerConfigurationProperties](src/main/java/io/opentracing/contrib/java/spring/jaeger/JaegerAutoConfiguration.java).
The prefix to be used for these properties is `opentracing.jaeger`.
Furthermore, the service name is configured via the standard Spring Cloud `spring.application.name` property.

Beware to use the correct syntax for properties that are camel-case in `JaegerConfigurationProperties`.

* For properties / yaml files use `-`. For example `opentracing.jaeger.log-spans=true`
* For environment variables use `_`. For example `OPENTRACING_JAEGER_LOG_SPANS`

## Defaults

If no configuration options are changed and the user does not manually provide any of the beans that the
auto-configuration process provides, the following defaults are used:

* `unknown-spring-boot` Will be used as the service-name if no value has been specified to the property `spring.application.name`.
* `CompositeReporter` is provided which contains the following delegates:
- `LoggingReporter` for reporting spans to the console
- `RemoteReporter` that contains a `UdpSender` that sends spans to `localhost:6831`
* `ConstSampler` with the value of `true`. This means that every trace will be sampled
* `NoopMetricsFactory` is used - effectively meaning that no metrics will be collected

## Senders

Configuring senders is as simple as setting a couple necessary properties

### HTTP Sender

`opentracing.jaeger.http-sender.url = http://jaegerhost:portNumber`

It's possible to configure authentication on the HTTP sender by specifying an username and password:

`opentracing.jaeger.http-sender.username = username`
`opentracing.jaeger.http-sender.password = password`

Or by specifying a bearer token:

`opentracing.jaeger.http-sender.authtoken = token`


Note that when an HTTP Sender is defined, the UDP sender is not used, even if it has been configured

### UDP Sender

`opentracing.jaeger.udp-sender.host=jaegerhost`
`opentracing.jaeger.udp-sender.port=portNumber`

## Common cases

### Set service name

Set `spring.application.name` to the desired name

### Log Spans

Be default spans are logged to the console. This can be disabled by setting:

`opentracing.jaeger.log-spans = false`

### Additional reporters

By defining a bean of type `ReporterAppender`, the code has the chance to add any Reporter without
having to forgo what the auto-configuration provides

### Sampling

* Const sampler

`opentracing.jaeger.const-sampler.decision = true | false`

* Probabilistic sampler

`opentracing.jaeger.probabilistic-sampler.sampling-rate = value`

Where `value` is between `0.0` (no sampling) and `1.0` (sampling of every request)

* Rate-limiting sampler

`opentracing.jaeger.rate-limiting-max-traces-per-second = value`

Where `value` is between `0.0` (no sampling) and `1.0` (sampling of every request)


The samplers above are mutually exclusive.

A custom sampler could of course be provided by declaring a bean of type `io.jaegertracing.samplers.Sampler`

### Propagate headers in B3 format (for compatibility with Zipkin collectors)

`opentracing.jaeger.enable-b3-propagation = true`

## Advanced cases

### Manual bean provisioning

Any of the following beans can be provided by the application (by adding configuring them as bean with `@Bean` for example)
and will be used to by the Tracer instead of the auto-configured beans.

* `io.jaegertracing.samplers.Sampler`
* `io.jaegertracing.metrics.MetricsFactory`

### io.jaegertracing.Tracer.Builder customization

Right before the `Tracer` is created, it is possible to provide arbitrary customizations to `Tracer.Builder` by providing a bean
of type `JaegerTracerCustomizer`

## Caution

### Beware of the default sampler in production

In a high traffic environment, the default sampler that is configured is very unsafe since it samples every request.
It is therefore highly recommended to explicitly configure on of the other options in a production environment



## Development
Maven checkstyle plugin is used to maintain consistent code style based on [Google Style Guides](https://github.com/google/styleguide)

```shell
./mvnw clean install
```

## Release
Follow instructions in [RELEASE](RELEASE.md)

[ci-img]: https://travis-ci.org/opentracing-contrib/java-spring-tracer.svg?branch=master
[ci]: https://travis-ci.org/opentracing-contrib/java-spring-jaeger
[maven-img]: https://img.shields.io/maven-central/v/io.opentracing.contrib/java-spring-jaeger.svg?maxAge=2592000
[maven]: http://search.maven.org/#search%7Cga%7C1%7Cjava-spring-jaeger

## License

[Apache 2.0 License](./LICENSE).
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# OpenTracing Release Process

This repo uses semantic versions. Please keep this in mind when choosing version numbers.

For the up-to-date release process, please refer the
[release process from the OpenTracing Java API](https://github.com/opentracing/opentracing-java/blob/master/RELEASE.md).
Loading

0 comments on commit 9c78ef2

Please sign in to comment.