All Projects β†’ palantir β†’ tracing-java

palantir / tracing-java

Licence: Apache-2.0 License
Java library providing zipkin-like tracing functionality

Programming Languages

java
68154 projects - #9 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to tracing-java

Plottable
πŸ“Š A library of modular chart components built on D3
Stars: ✭ 2,834 (+21700%)
Mutual labels:  octo-correct-managed
gradle-consistent-versions
Compact, constraint-friendly lockfiles for your dependencies
Stars: ✭ 92 (+607.69%)
Mutual labels:  octo-correct-managed
hadoop-crypto
Library for per-file client-side encyption in Hadoop FileSystems such as HDFS or S3.
Stars: ✭ 38 (+192.31%)
Mutual labels:  octo-correct-managed
Tslint
🚦 An extensible linter for the TypeScript language
Stars: ✭ 5,922 (+45453.85%)
Mutual labels:  octo-correct-managed
conjure-rust
Conjure support for Rust
Stars: ✭ 14 (+7.69%)
Mutual labels:  octo-correct-managed
asana mailer
A script that uses Asana's RESTful API to generate plaintext and HTML emails.
Stars: ✭ 12 (-7.69%)
Mutual labels:  octo-correct-managed
dropwizard-web-security
A Dropwizard bundle for applying default web security functionality
Stars: ✭ 37 (+184.62%)
Mutual labels:  octo-correct-managed
metric-schema
Schema for standard metric definitions
Stars: ✭ 13 (+0%)
Mutual labels:  octo-correct-managed
palantir-java-format
A modern, lambda-friendly, 120 character Java formatter.
Stars: ✭ 203 (+1461.54%)
Mutual labels:  octo-correct-managed
go-baseapp
A lightweight starting point for Go web servers
Stars: ✭ 61 (+369.23%)
Mutual labels:  octo-correct-managed
Python Language Server
An implementation of the Language Server Protocol for Python
Stars: ✭ 2,412 (+18453.85%)
Mutual labels:  octo-correct-managed
amalgomate
Go tool for combining multiple different main packages into a single program or library
Stars: ✭ 19 (+46.15%)
Mutual labels:  octo-correct-managed
giraffe
Gracefully Integrated Remote Access For Files and Execution
Stars: ✭ 50 (+284.62%)
Mutual labels:  octo-correct-managed
Blueprint
A React-based UI toolkit for the web
Stars: ✭ 18,376 (+141253.85%)
Mutual labels:  octo-correct-managed
goastwriter
Go library for writing Go source code programatically
Stars: ✭ 27 (+107.69%)
Mutual labels:  octo-correct-managed
gradle-docker-test-runner
Gradle plugin for running tests in Docker environments
Stars: ✭ 20 (+53.85%)
Mutual labels:  octo-correct-managed
phishcatch
A browser extension and API server for detecting corporate password use on external websites
Stars: ✭ 75 (+476.92%)
Mutual labels:  octo-correct-managed
dropwizard-web-logger
WebLoggerBundle is a Dropwizard bundle used to help log web activity to log files on a server’s backend
Stars: ✭ 14 (+7.69%)
Mutual labels:  octo-correct-managed
python-jsonrpc-server
A Python 2 and 3 asynchronous JSON RPC server
Stars: ✭ 73 (+461.54%)
Mutual labels:  octo-correct-managed
witchcraft-go-server
A highly opinionated Go embedded application server for RESTy APIs
Stars: ✭ 47 (+261.54%)
Mutual labels:  octo-correct-managed

Autorelease

tracing-java Download

Zipkin-style call tracing libraries.

  • com.palantir.tracing:tracing - The key Tracer class, which stores trace information in a ThreadLocal. Also includes classes for convenient integration with SLF4J and executor services.
  • com.palantir.tracing:tracing-api - constants and pure data objects
  • com.palantir.tracing:tracing-jaxrs - utilities to wrap StreamingOutput responses with a new trace.
  • com.palantir.tracing:tracing-okhttp3 - OkhttpTraceInterceptor, which adds the appropriate headers to outgoing requests.
  • com.palantir.tracing:tracing-jersey - TraceEnrichingFilter, a jaxrs filter which reads headers from incoming requests and writes headers to outgoing responses. A traceId is stored in the jaxrs request context under the key com.palantir.tracing.traceId.
  • com.palantir.tracing:tracing-undertow - TracedOperationHandler, an Undertow handler reads headers from incoming requests and writes headers to outgoing responses.
  • com.palantir.tracing:tracing-test-utils - JUnit classes to render traces and also allow snapshot testing them.

Clients and servers propagate call trace ids across JVM boundaries according to the Zipkin specification. In particular, clients insert X-B3-TraceId: <Trace ID> HTTP headers into all requests which get propagated by Jetty servers into subsequent client invocations. We enhance the Zipkin spec in one regard; with outgoing traces we additionally send an X-OrigSpanId: <Originating Span ID> header which enables request logs to be considered a useful subset of the trace events, even on unsampled requests.

Usage

Example of how to use the tracing library:

// build.gradle
dependencies {
  compile "com.palantir.tracing:tracing:$version"
}
try (CloseableTracer span = CloseableTracer.startSpan("do work")) {
    Thread.sleep(100);
    doWork();
}

At the end of this try-with-resources block, any registered SpanObservers will be notified with a single immutable Span object. The above example demonstrates how to instrument chunks of code that start and finish on one thread. For cross-thread tracing, see DetachedSpan.

Logging with SLF4J

By default, the instrumentation forwards trace and span information through HTTP headers, but does not emit completed spans to a log file or to Zipkin. Span observers are static (similar to SLF4J appenders) and can be configured as follows:

// Emit all completed spans to a default SLF4J logger:
Tracer.subscribe("SLF4J" /* user-defined name */, AsyncSlf4jSpanObserver.of(executor));

// No longer emit span events to SLF4J:
Tracer.unsubscribe("SLF4J");

Note that span observers are static; a server typically subscribes span observers in its initialization phase. Libraries should never register span observers (since they can trample observers registered by consumers of the library whose themselves register observers).

tracing-test-utils

You can set up 'snapshot testing' by adding the @TestTracing annotation to a test method (this requires JUnit 5).

 import org.junit.jupiter.api.Test;
 import com.palantir.tracing.TestTracing;

 public class MyTest {
     @Test
+    @TestTracing(snapshot = true)
     public void foo() {
     }
 }

When you run this test for the first time, it will capture all spans and write them to a file src/test/resources/tracing/MyTest/foo, which should be checked-in to Git. This file will be used as a 'golden master', and all future runs will be compared against it.

{"traceId":"7e1014caf8a7278e","parentSpanId":"972f9b3a09431b67","spanId":"f701b7f815176ec2","operation":"healthcheck: SERVICE_DEPENDENCY","startTimeMicroSeconds":1566902887342052,"durationNanoSeconds":20377272,"metadata":{}}
...

If your production code changes and starts producing different spans, the test will fail and render two HTML visualizations: expected.html and actual.html.

Snapshot-testing is not available in JUnit4, but you can still see a HTML visualization of your traces using the RenderTracingRule:

 import org.junit.Test;
 import com.palantir.tracing.RenderTracingRule;

 public class MyTest {

+    @Rule
+    public final RenderTracingRule rule = new RenderTracingRule();

     @Test
     public void foo() {
     }
 }

License

This repository is made available under the Apache 2.0 License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].