项目作者: opentracing-contrib

项目描述 :
OpenTracing Instrumentation for Elasticsearch Client
高级语言: Java
项目地址: git://github.com/opentracing-contrib/java-elasticsearch-client.git
创建时间: 2017-04-15T21:05:00Z
项目社区:https://github.com/opentracing-contrib/java-elasticsearch-client

开源协议:Apache License 2.0

下载


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

  1. <dependency>
  2. <groupId>io.opentracing.contrib</groupId>
  3. <artifactId>opentracing-elasticsearch5-client</artifactId>
  4. <version>VERSION</version>
  5. </dependency>

Elasticsearch 6

  1. <dependency>
  2. <groupId>io.opentracing.contrib</groupId>
  3. <artifactId>opentracing-elasticsearch6-client</artifactId>
  4. <version>VERSION</version>
  5. </dependency>

Elasticsearch 7

  1. <dependency>
  2. <groupId>io.opentracing.contrib</groupId>
  3. <artifactId>opentracing-elasticsearch7-client</artifactId>
  4. <version>VERSION</version>
  5. </dependency>

Usage

  1. // Instantiate tracer
  2. Tracer tracer = ...
  3. // Optionally register tracer with GlobalTracer
  4. GlobalTracer.register(tracer);
  5. // Build TransportClient with TracingPreBuiltTransportClient
  6. TransportClient transportClient = new TracingPreBuiltTransportClient(settings)
  7. .addTransportAddress(...));
  8. // Build RestClient adding TracingHttpClientConfigCallback
  9. RestClient restClient = RestClient.builder(
  10. new HttpHost(...))
  11. .setHttpClientConfigCallback(new TracingHttpClientConfigCallback(tracer))
  12. .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.

  1. // Create a Function for the TracingHttpClientConfigCallback that operates on
  2. // the HttpRequest and returns a String that will be used as the Span name.
  3. Function<HttpRequest, String> customSpanNameProvider =
  4. (request) -> request.getRequestLine().getMethod().toLowerCase();
  5. // Build RestClient adding TracingHttpClientConfigCallback
  6. RestClient restClient = RestClient.builder(
  7. new HttpHost(...))
  8. .setHttpClientConfigCallback(new TracingHttpClientConfigCallback(tracer, customSpanNameProvider))
  9. .build();
  10. // Spans created by the restClient will now have the request's lowercase method name as the span name.
  11. // "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.