• Stars
    star
    243
  • Rank 160,523 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build Status Released Version

Dependencies

The opentracing-spring-jaeger-starter simply contains the code needed to provide a Jaeger implementation of the OpenTracing's io.opentracing.Tracer interface.

For a project to be able to actually instrument a Spring stack, one or more of the purpose built starters (like io.opentracing.contrib:opentracing-spring-web-starter or io.opentracing.contrib:opentracing-spring-cloud-starter)
would also have to be included in the POM.

The opentracing-spring-jaeger-web-starter starter is convenience starter that includes both opentracing-spring-jaeger-starter and opentracing-spring-web-starter This means that by including it, simple web Spring Boot microservices include all the necessary dependencies to instrument Web requests / responses and send traces to Jaeger.

The opentracing-spring-jaeger-cloud-starter starter is convenience starter that includes both opentracing-spring-jaeger-starter and opentracing-spring-cloud-starter This means that by including it, all parts of the Spring Cloud stack supported by Opentracing will be instrumented

Library versions

Versions 1.x.y of the library are meant to target Spring Boot 2.x while versions 0.x.y are meant to be used with Spring Boot 1.5

Configuration

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

or

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

Either 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/api/traces

Configuration options

All the available configuration options can be seen in JaegerConfigurationProperties. 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 or opentracing.jaeger.service-name (which has the highest priority).
  • 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/api/traces

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

By 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-sampler.max-traces-per-second = value

    Configures that traces are sampled with a certain constant rate. For example, when sampler.param=2.0 it will sample requests with the rate of 2 traces per second.

  • Remote sampler

    Remote sampler consults Jaeger agent for the appropriate sampling strategy to use in the current service. This allows controlling the sampling strategies in the services from a central configuration in Jaeger backend. It can be configured like so:

    opentracing.jaeger.remote-controlled-sampler.host-port=localhost:5778

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

Propagate headers in W3C Trace Context format

opentracing.jaeger.enable-w3c-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

If arbitrary customizations need to be performed on Tracer.Builder but you don't want to forgo the rest of the auto-configuration features, TracerBuilderCustomizer comes in handy. It allows the developer to invoke any method of Tracer.Builder (with the exception of build) before the auto-configuration code invokes the build method. Examples of this type of customization can be seen in the B3CodecTracerBuilderCustomizer and ExpandExceptionLogsTracerBuilderCustomizer classes.

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

./mvnw clean install

Tips and tricks

Completely disable tracing

There are times when it might be desirable to completely disable tracing (for example in a testing environment). Due to the multiple (auto)configurations that come into play, this is not as simple as setting opentracing.jaeger.enabled to false.

When one of the starters of this project is included, then io.opentracing.contrib:opentracing-spring-tracer-configuration-starter is also included since it performs some necessary plumbing. However, when opentracing.jaeger.enabled is set to false, then the aforementioned dependency provides a default Tracer implementation that needs the JAEGER_SERVICE_NAME environment variable (see this).

One simple way around this would be to do the add the following Spring configuration:

@ConditionalOnProperty(value = "opentracing.jaeger.enabled", havingValue = "false", matchIfMissing = false)
@Configuration
public class MyTracerConfiguration {

    @Bean
    public io.opentracing.Tracer jaegerTracer() {
        return io.opentracing.noop.NoopTracerFactory.create();
    }
}

In the code above we are activating a io.opentracing.Tracer iff opentracing.jaeger.enabled is set to false. This tracer is necessary to keep the various Spring configurations happy but has been configured to not sample any requests, therefore effectively disabling tracing.

Trace id not propagated via the Feign client

If you are using Feign, in some cases it might be necessary to explicitely expose the Feign client in the Spring configuration, in order to get the uber-trace-id propagated. This can be done easily by adding the following into one of your configuration classes:

@Bean
public Client feignClient() {
    return new Client.Default(null, null);
}

Release

Follow instructions in RELEASE

License

Apache 2.0 License.

More Repositories

1

opentracing-specification-zh

OpenTracing标准(中文版) `zh` (Chinese) translation of the opentracing/specification
929
star
2

nginx-opentracing

NGINX plugin for OpenTracing
C++
494
star
3

java-spring-cloud

Distributed tracing for Spring Boot, Cloud and other Spring projects
Java
386
star
4

csharp-netcore

OpenTracing instrumentation for .NET Core 3.1 & .NET 6+ apps
C#
261
star
5

go-stdlib

OpenTracing instrumentation for packages in the Go stdlib
Go
219
star
6

java-specialagent

Automatic instrumentation for 3rd-party libraries in Java applications with OpenTracing.
Java
186
star
7

python-flask

OpenTracing instrumentation for the Flask microframework
Python
136
star
8

java-kafka-client

OpenTracing Instrumentation for Apache Kafka Client
Java
120
star
9

java-spring-web

OpenTracing Spring Web instrumentation
Java
106
star
10

java-opentracing-walkthrough

A self-guided OpenTracing walkthrough / demo project
JavaScript
106
star
11

python-django

OpenTracing instrumentation for the Django framework
Python
106
star
12

java-jdbc

OpenTracing Instrumentation for JDBC
Java
81
star
13

java-jfr-tracer

This is a delegating tracer to be used with OpenTracing. It records span information into the JFR, allowing very deep tracing.
Java
76
star
14

go-grpc

Package otgrpc provides OpenTracing support for any gRPC client or server.
Go
69
star
15

go-gin

OpenTracing middleware for gin-gonic
Go
63
star
16

java-grpc

OpenTracing Instrumentation for gRPC
Java
52
star
17

python-grpc

Python
51
star
18

csharp-grpc

OpenTracing Instrumentation for gRPC
C#
43
star
19

java-agent

Agent-based OpenTracing instrumentation in Java
Java
40
star
20

javascript-express

OpenTracing middleware for express
JavaScript
39
star
21

java-jaxrs

OpenTracing Java JAX-RS instrumentation
Java
37
star
22

java-concurrent

OpenTracing-aware helpers related to java.util.concurrent
Java
36
star
23

meta

A meta-repository for OpenTracing contributions
34
star
24

java-redis-client

OpenTracing Instrumentation for Redis Client
Java
33
star
25

go-zap

Integration with go.uber.org/zap
Go
32
star
26

java-metrics

Java
31
star
27

go-amqp

AMQP instrumentation in Go
Go
29
star
28

opentracing-erlang

Open Tracing Toolkit for ERlang
Erlang
24
star
29

scala-concurrent

OpenTracing instrumentation for scala.concurrent package
Scala
24
star
30

java-web-servlet-filter

OpenTracing Java Web Servlet Filter Instrumentation
Java
23
star
31

java-okhttp

OpenTracing Okhttp client instrumentation
Java
23
star
32

java-xray-tracer

Java OpenTracing implementation backed by AWS X-Ray
Java
23
star
33

java-vertx-web

OpenTracing instrumentation for Vert.x web package
Java
21
star
34

python-redis

OpenTracing instrumentation for the Redis client.
Python
20
star
35

ruby-rack-tracer

Ruby
20
star
36

java-span-reporter

A Tracer implementation that writes all instrumented data to a conventional Logger
Java
20
star
37

goredis

a middleware for go-redis/redis to use opentracing
Go
17
star
38

java-spring-rabbitmq

OpenTracing RabbitMQ instrumentation
Java
17
star
39

python-sqlalchemy

OpenTracing instrumentation for SQLAlchemy
Python
16
star
40

java-spring-zipkin

Java
16
star
41

scala-akka

OpenTracing instrumentation for Scala Akka
Scala
16
star
42

java-dropwizard

(deprecated) OpenTracing instrumentation for the Dropwizard framework
Java
15
star
43

java-aws-sdk

OpenTracing instrumentation for AWS SDK
Java
15
star
44

java-specialagent-demo

A SpecialAgent Demo
Java
13
star
45

java-reactor

OpenTracing instrumentation for Reactor
Java
12
star
46

java-mongo-driver

OpenTracing Instrumentation for Mongo Driver
Java
12
star
47

javascript-tracedpromise

JavaScript
12
star
48

python-elasticsearch

OpenTracing instrumentation for the the Python's Elasticsearch clients
Python
11
star
49

java-apache-httpclient

OpenTracing Apache HttpClient instrumentation
Java
11
star
50

python-requests

OpenTracing instrumentation for Requests
Python
10
star
51

echo

a middleware for the echov4 web framework to use opentracing
Go
10
star
52

go-aws-sdk

OpenTracing support for AWS SDK in Go
Go
10
star
53

java-thrift

OpenTracing instrumentation for Apache Thrift
Java
10
star
54

java-rabbitmq-client

OpenTracing Instrumentation for RabbitMQ Client
Java
9
star
55

python-tornado

OpenTracing instrumentation for Tornado
Python
9
star
56

java-rxjava

OpenTracing Instrumentation for RxJava
Java
9
star
57

examples

Examples (some trivial) for opentracing.io
Go
9
star
58

java-elasticsearch-client

OpenTracing Instrumentation for Elasticsearch Client
Java
8
star
59

go-observer

an Observer API for OpenTracing-Go Tracers
Go
8
star
60

java-examples

tested examples of common instrumentation patterns
Java
7
star
61

ruby-faraday-tracer

Ruby
7
star
62

csharp-decorators

C#
6
star
63

java-akka

Java
6
star
64

java-tracerresolver

Resolver API for OpenTracing Tracer implementations.
Java
6
star
65

go-gorilla

OpenTracing instrumentation for Gorilla framework (github.com/gorilla)
Go
6
star
66

java-spanmanager

Current span management for Java
Java
6
star
67

java-jms

OpenTracing Instrumentation for JMS API
Java
5
star
68

perfevents

Perf metrics library for go and java applications
Go
5
star
69

beego

a middleware for the beego web framework to use opentracing
Go
5
star
70

java-hprose

OpenTracing instrumentation for the Hprose Remote Object Service Engine
Java
4
star
71

java-p6spy

OpenTracing Instrumentation for P6Spy
Java
4
star
72

python-pyramid

OpenTracing instrumentation for the Pyramid framework
Python
4
star
73

java-cassandra-driver

OpenTracing instrumentation for Cassandra Driver
Java
4
star
74

java-globaltracer

(deprecated) Global OpenTracing Tracer resolution for Java
Java
4
star
75

java-asynchttpclient

OpenTracing Instrumentation for https://github.com/AsyncHttpClient/async-http-client
Java
4
star
76

cpp-grpc

OpenTracing Instrumentation for gRPC
4
star
77

python-cassandra

OpenTracing instrumentation for cassandra-driver
Python
3
star
78

java-jdbi

OpenTracing instrumentation for the JDBI database framework
Java
3
star
79

java-spring-messaging

OpenTracing Spring Messaging instrumentation
Java
3
star
80

java-redisson

OpenTracing Instrumentation for Redisson
Java
3
star
81

java-benchmarks

Set of benchmarks to assess the performance of different OpenTracing components and/or libraries
Java
3
star
82

python-examples

tester examples of common instrumentation patterns
Python
3
star
83

java-spring-tracer-configuration

Java
2
star
84

python-pymongo

OpenTracing instrumentation for PyMongo
Python
2
star
85

java-cdi

Java
2
star
86

go-restful

OpenTracing instrumentation for the go-restful framework
Go
2
star
87

java-neo4j-driver

OpenTracing instrumentation for Neo4j Driver
Java
2
star
88

java-ejb

Java
2
star
89

java-solr-client

OpenTracing Instrumentation for Solr Client
Java
2
star
90

python-gevent

OpenTracing instrumentation for gevent
Python
2
star
91

java-grizzly-http-server

OpenTracing instrumentation for Grizzly HttpServer
Java
1
star
92

ruby-redis-instrumentation

Ruby
1
star
93

java-memcached-client

OpenTracing Instrumentation for Memcached Client
Java
1
star
94

java-grizzly-ahc

OpenTracing instrumentation for Grizzly AsyncHttpClient
Java
1
star
95

ruby-mongodb-instrumentation

Ruby
1
star
96

java-common

Common utilities for OpenTracing Instrumentation Plugins.
Java
1
star
97

java-opentelemetry-bridge

OpenTracing-OpenTelemetry Tracer Bridge
Java
1
star
98

java-hazelcast

OpenTracing Instrumentation for Hazelcast
Java
1
star
99

java-api-extensions

This repository contains API extensions for use with the core Tracer and Span APIs.
Java
1
star
100

java-opentracing-jaeger-bundle

Java
1
star