opentracing-sparkjava

Opentracing Request Filters for Sparkjava

License

License

GroupId

GroupId

com.mikelduke
ArtifactId

ArtifactId

opentracing-sparkjava
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

opentracing-sparkjava
Opentracing Request Filters for Sparkjava
Project URL

Project URL

https://github.com/mikelduke/opentracing-sparkjava
Project Organization

Project Organization

mikelduke
Source Code Management

Source Code Management

https://github.com/mikelduke/opentracing-sparkjava

Download opentracing-sparkjava

How to add to project

<!-- https://jarcasting.com/artifacts/com.mikelduke/opentracing-sparkjava/ -->
<dependency>
    <groupId>com.mikelduke</groupId>
    <artifactId>opentracing-sparkjava</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.mikelduke/opentracing-sparkjava/
implementation 'com.mikelduke:opentracing-sparkjava:1.0.1'
// https://jarcasting.com/artifacts/com.mikelduke/opentracing-sparkjava/
implementation ("com.mikelduke:opentracing-sparkjava:1.0.1")
'com.mikelduke:opentracing-sparkjava:jar:1.0.1'
<dependency org="com.mikelduke" name="opentracing-sparkjava" rev="1.0.1">
  <artifact name="opentracing-sparkjava" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.mikelduke', module='opentracing-sparkjava', version='1.0.1')
)
libraryDependencies += "com.mikelduke" % "opentracing-sparkjava" % "1.0.1"
[com.mikelduke/opentracing-sparkjava "1.0.1"]

Dependencies

compile (3)

Group / Artifact Type Version
com.sparkjava : spark-core jar 2.7.2
io.opentracing : opentracing-api jar 0.31.0
io.opentracing : opentracing-util jar 0.31.0

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
io.jaegertracing : jaeger-core jar 0.28.0
com.squareup.okhttp3 : okhttp jar 3.9.0

Project Modules

There are no modules declared in this project.

Maven Central OpenTracing Badge License

opentracing-sparkjava

OpenTracing Instrumentation for SparkJava

This repo contains tracing filters and an exception handler for SparkJava. The filters extract tracing headers from incoming requests to create OpenTracing spans. These spans can be exported to a variety of backends including Jaeger, Hawkular, and others.

Dependencies

The Spark dependency is marked as compileOnly and must be supplied by the application.

compile group: 'com.sparkjava', name: 'spark-core', version: '2.7.+'

Usage

To enable tracing you need to add before, exception and afterAfter hooks:

OpenTracingSparkFilters sparkTracingFilters = new OpenTracingSparkFilters(tracer);
Spark.before(sparkTracingFilters.before());
Spark.afterAfter(sparkTracingFilters.afterAfter());
Spark.exception(sparkTracingFilters.exception());

// tracing is added for all routes
Spark.get("/hello", (req, res) -> "hello world");

To access the current span in a resource retrieve it from the request attributes using OpenTracingSparkFilters.SERVER_SPAN:

Spark.get("/path", (req, res) -> {
    Span span = req.attribute(OpenTracingSparkFilters.SERVER_SPAN);
    tracer.buildSpan("child").asChildOf(span).withTag("test", "value").start().finish();

    //do stuff
    return "hello world";
});

Versions

Version
1.0.1