Coder Social home page Coder Social logo

java-elasticsearch-client's Introduction

Build Status Coverage Status Released Version Apache-2.0 license

OpenTracing Elasticsearch Client Instrumentation

OpenTracing instrumentation for Elasticsearch clients.

Installation

Maven

pom.xml

Elasticsearch 5

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-elasticsearch5-client</artifactId>
    <version>VERSION</version>
</dependency>

Elasticsearch 6

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-elasticsearch6-client</artifactId>
    <version>VERSION</version>
</dependency>

Elasticsearch 7

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-elasticsearch7-client</artifactId>
    <version>VERSION</version>
</dependency>

Usage

// Instantiate tracer
Tracer tracer = ...

// Optionally register tracer with GlobalTracer
GlobalTracer.register(tracer);

// Build TransportClient with TracingPreBuiltTransportClient
TransportClient transportClient = new TracingPreBuiltTransportClient(settings)
                .addTransportAddress(...));

// Build RestClient adding TracingHttpClientConfigCallback
 RestClient restClient = RestClient.builder(
                new HttpHost(...))
                .setHttpClientConfigCallback(new TracingHttpClientConfigCallback(tracer))
                .build();

Custom Span Names with the TracingHttpClientConfigCallback

This driver includes support for customizing the spans created using the TracingHttpClientConfigCallback. You can use the predefined ones listed further below, or write your own in the form of a Function object.

// Create a Function for the TracingHttpClientConfigCallback that operates on
// the HttpRequest and returns a String that will be used as the Span name.
Function<HttpRequest, String> customSpanNameProvider =
  (request) -> request.getRequestLine().getMethod().toLowerCase();

// Build RestClient adding TracingHttpClientConfigCallback
 RestClient restClient = RestClient.builder(
                new HttpHost(...))
                .setHttpClientConfigCallback(new TracingHttpClientConfigCallback(tracer, customSpanNameProvider))
                .build();
 
 // Spans created by the restClient will now have the request's lowercase method name as the span name.
 // "POST" -> "post"

Predefined Span Name Providers

The following Functions are already included in the ClientSpanNameProvider class, with REQUEST_METHOD_NAME being the default should no other span name provider be provided.

  • REQUEST_METHOD_NAME: Returns the HTTP method of the request.
    • GET /twitter/tweet/1?routing=user1 -> "GET"
  • PREFIXED_REQUEST_METHOD_NAME(String prefix): Returns a String concatenation of prefix and the HTTP method of the request.
    • GET /twitter/tweet/1?routing=user1 -> prefix + "GET"
  • REQUEST_TARGET_NAME: Returns the Elasticsearch target of the request, i.e. the index and resource it's operating on. IDs and other numbers not part of names will be replaced with a "?" to avoid overly granular names.
    • GET /twitter/tweet/1?routing=user1 -> "/twitter/tweet/?"
  • PREFIXED_REQUEST_TARGET_NAME(String prefix): Returns a String concatenation of prefix and the Elasticsearch target of the request. IDs and other numbers not part of names will be replaced with a "?" to avoid overly granular names.
    • GET /twitter/tweet/1?routing=user1 -> prefix + "/twitter/tweet/?"
  • REQUEST_METHOD_TARGET_NAME: Returns a String concatenation of the HTTP method of the request and the Elasticsearch target of the request. IDs and other numbers not part of names will be replaced with a "?" to avoid overly granular names.
    • GET /twitter/tweet/1?routing=user1 -> "GET /twitter/tweet/?"
  • PREFIXED_REQUEST_METHOD_TARGET_NAME(String prefix): Returns a String concatenation of prefix, the HTTP method of the request, and the Elasticsearch target of the request. IDs and other numbers not part of names will be replaced with a "?" to avoid overly granular names.
    • GET /twitter/tweet/1?routing=user1 -> prefix + "GET /twitter/tweet/?"

License

Apache 2.0 License.

java-elasticsearch-client's People

Contributors

bhs avatar dependabot[bot] avatar jordanjlopez avatar malafeev avatar safris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

java-elasticsearch-client's Issues

span reports 401 http status on success

I am using the TracingHttpClientConfigCallback to add spans to my elastic search REST client use. However, we also use credentials, as mentioned in

https://stackoverflow.com/questions/48185570/add-authentication-in-elasticsearch-high-level-client-for-java

so I pass the credentials callback in as a parameter to the TracingHttpClientConfigCallback. When I didn't do that, my queries failed with a 401. Now my queries succeed, but the elasticsearch client spans still show a status of 401, even though I can confirm in the logs that the query was successful.

I'm wondering if the authentication mechanism is somehow causing an initial 401.

Has anyone seen this, or have recommendations on how to address it?

A secondary issue is that the time reported in the span seems very short compared to my logging and other spans. This could be linked to the 401 problem, however.

We are using version 6.6.1 of the Elasticsearch client API JARs.

Support for Elasticsearch 5

It would be nice to have a separated module for Elasticsearch 5, the current version doesn't work for Elasticsearch 5.5.0 transport client... Maybe slipt in 3 modules, a core, elasticsearch5 and elasticsearch6.

spans never finished when timeout occurs in Rest client

We ran into an issue where we are getting timeouts in the Apache HTTP AsyncClient of the ES Rest client. This tracing solution using interceptors is not catching that timeout event--the response interceptor is not called/not finishing the span.

https://github.com/opentracing-contrib/java-elasticsearch-client/blob/master/opentracing-elasticsearch-client-common/src/main/java/io/opentracing/contrib/elasticsearch/common/TracingHttpClientConfigCallback.java

I haven't figured out how to solve it yet, and I'm looking for some help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.