Adding ES instrumentation
This commit is contained in:
parent
c89db2592c
commit
ca32835ff7
|
@ -1,244 +1,286 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.datadoghq</groupId>
|
<groupId>com.datadoghq</groupId>
|
||||||
<artifactId>dd-trace-java</artifactId>
|
<artifactId>dd-trace-java</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>dd-java-agent</artifactId>
|
<artifactId>dd-java-agent</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>dd-java-agent</name>
|
<name>dd-java-agent</name>
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<ot.dd-trace.version>1.0-SNAPSHOT</ot.dd-trace.version>
|
<ot.dd-trace.version>1.0-SNAPSHOT</ot.dd-trace.version>
|
||||||
<ot.agent.version>0.0.12</ot.agent.version>
|
<ot.agent.version>0.0.12</ot.agent.version>
|
||||||
<ot.contrib.webservlet.version>0.0.8</ot.contrib.webservlet.version>
|
<ot.contrib.webservlet.version>0.0.8</ot.contrib.webservlet.version>
|
||||||
<ot.contrib.mongo.version>0.0.1</ot.contrib.mongo.version>
|
<ot.contrib.mongo.version>0.0.1</ot.contrib.mongo.version>
|
||||||
<ot.contrib.okhttp.version>0.0.4</ot.contrib.okhttp.version>
|
<ot.contrib.okhttp.version>0.0.4</ot.contrib.okhttp.version>
|
||||||
<opentracing.version>0.22.0</opentracing.version>
|
<opentracing.version>0.22.0</opentracing.version>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- DD tracer CORE -->
|
<!-- DD tracer CORE -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.datadoghq</groupId>
|
<groupId>com.datadoghq</groupId>
|
||||||
<artifactId>dd-trace</artifactId>
|
<artifactId>dd-trace</artifactId>
|
||||||
<version>${ot.dd-trace.version}</version>
|
<version>${ot.dd-trace.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- opentracing agent -->
|
<!-- opentracing agent -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-agent</artifactId>
|
<artifactId>opentracing-agent</artifactId>
|
||||||
<version>${ot.agent.version}</version>
|
<version>${ot.agent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-agent-rules-java-okhttp</artifactId>
|
<artifactId>opentracing-agent-rules-java-okhttp</artifactId>
|
||||||
<version>${ot.agent.version}</version>
|
<version>${ot.agent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-agent-rules-java-web-servlet-filter</artifactId>
|
<artifactId>opentracing-agent-rules-java-web-servlet-filter</artifactId>
|
||||||
<version>${ot.agent.version}</version>
|
<version>${ot.agent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Used to find annotated methods -->
|
<!-- Used to find annotated methods -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.reflections</groupId>
|
<groupId>org.reflections</groupId>
|
||||||
<artifactId>reflections</artifactId>
|
<artifactId>reflections</artifactId>
|
||||||
<version>0.9.11</version>
|
<version>0.9.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Server side instrumentation -->
|
<!-- Server side instrumentation -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-web-servlet-filter</artifactId>
|
<artifactId>opentracing-web-servlet-filter</artifactId>
|
||||||
<version>${ot.contrib.webservlet.version}</version>
|
<version>${ot.contrib.webservlet.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-mongo-driver</artifactId>
|
<artifactId>opentracing-mongo-driver</artifactId>
|
||||||
<version>${ot.contrib.mongo.version}</version>
|
<version>${ot.contrib.mongo.version}</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>mongodb-driver-async</artifactId>
|
<artifactId>mongodb-driver-async</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>mongo-java-driver</artifactId>
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Opentracing JDBC contribution -->
|
<!-- Opentracing JDBC contribution -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-jdbc</artifactId>
|
<artifactId>opentracing-jdbc</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Client side instrumentation -->
|
<!-- Client side instrumentation -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-okhttp3</artifactId>
|
<artifactId>opentracing-okhttp3</artifactId>
|
||||||
<version>${ot.contrib.okhttp.version}</version>
|
<version>${ot.contrib.okhttp.version}</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
|
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- AWS SDK instrumentation -->
|
<!-- AWS SDK instrumentation -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing.contrib</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-aws-sdk</artifactId>
|
<artifactId>opentracing-aws-sdk</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.1</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk</artifactId>
|
<artifactId>aws-java-sdk</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JUnit tests -->
|
<!-- ES instrumentation -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.opentracing</groupId>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<artifactId>opentracing-mock</artifactId>
|
<artifactId>opentracing-elasticsearch-client</artifactId>
|
||||||
<version>${opentracing.version}</version>
|
<version>0.0.1</version>
|
||||||
<scope>test</scope>
|
<!--<exclusions>-->
|
||||||
</dependency>
|
<!--<exclusion>-->
|
||||||
<dependency>
|
<!--<groupId>com.amazonaws</groupId>-->
|
||||||
<groupId>junit</groupId>
|
<!--<artifactId>aws-java-sdk</artifactId>-->
|
||||||
<artifactId>junit</artifactId>
|
<!--</exclusion>-->
|
||||||
<version>4.12</version>
|
<!--</exclusions>-->
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.assertj</groupId>
|
|
||||||
<artifactId>assertj-core</artifactId>
|
|
||||||
<version>3.6.2</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Mongo tests -->
|
<!-- JUnit tests -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>io.opentracing</groupId>
|
||||||
<artifactId>mongo-java-driver</artifactId>
|
<artifactId>opentracing-mock</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>${opentracing.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- OkHTTP tests -->
|
<dependency>
|
||||||
<dependency>
|
<groupId>junit</groupId>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<artifactId>junit</artifactId>
|
||||||
<artifactId>okhttp</artifactId>
|
<version>4.12</version>
|
||||||
<version>3.6.0</version>
|
<scope>test</scope>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<!-- Jetty Servlet tests -->
|
<groupId>org.assertj</groupId>
|
||||||
<dependency>
|
<artifactId>assertj-core</artifactId>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<version>3.6.2</version>
|
||||||
<artifactId>jetty-server</artifactId>
|
<scope>test</scope>
|
||||||
<version>9.4.1.v20170120</version>
|
</dependency>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
|
||||||
<artifactId>jetty-servlet</artifactId>
|
|
||||||
<version>9.4.1.v20170120</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Tomcat Servlet tests -->
|
<!-- Mongo tests -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tomcat.embed</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>tomcat-embed-core</artifactId>
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
<version>8.0.41</version>
|
<version>3.4.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!-- OkHTTP tests -->
|
||||||
<groupId>org.apache.tomcat.embed</groupId>
|
<dependency>
|
||||||
<artifactId>tomcat-embed-jasper</artifactId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<version>8.0.41</version>
|
<artifactId>okhttp</artifactId>
|
||||||
<scope>test</scope>
|
<version>3.6.0</version>
|
||||||
</dependency>
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Jetty Servlet tests -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-server</artifactId>
|
||||||
|
<version>9.4.1.v20170120</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-servlet</artifactId>
|
||||||
|
<version>9.4.1.v20170120</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- AWS SDK tests -->
|
<!-- Tomcat Servlet tests -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
<artifactId>aws-java-sdk</artifactId>
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
<version>1.11.132</version>
|
<version>8.0.41</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-jasper</artifactId>
|
||||||
|
<version>8.0.41</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
<!-- AWS SDK tests -->
|
||||||
<build>
|
<dependency>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<groupId>com.amazonaws</groupId>
|
||||||
<plugins>
|
<artifactId>aws-java-sdk</artifactId>
|
||||||
<plugin>
|
<version>1.11.132</version>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<scope>test</scope>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
</dependency>
|
||||||
<version>3.6.1</version>
|
|
||||||
<configuration>
|
<!--Elasticsearch tests-->
|
||||||
<source>${java.version}</source>
|
<dependency>
|
||||||
<target>${java.version}</target>
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
</configuration>
|
<artifactId>transport</artifactId>
|
||||||
</plugin>
|
<version>5.4.0</version>
|
||||||
<plugin>
|
<scope>test</scope>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
</dependency>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<dependency>
|
||||||
<version>2.20</version>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<configuration>
|
<artifactId>log4j-api</artifactId>
|
||||||
<argLine>-javaagent:${M2_REPO}/com/datadoghq/dd-java-agent/${project.version}/dd-java-agent-${project.version}.jar</argLine>
|
<version>2.7</version>
|
||||||
<includes>
|
<scope>test</scope>
|
||||||
<include>*Test.java</include>
|
</dependency>
|
||||||
</includes>
|
<dependency>
|
||||||
</configuration>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
</plugin>
|
<artifactId>log4j-core</artifactId>
|
||||||
<plugin>
|
<version>2.7</version>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<scope>test</scope>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
</dependency>
|
||||||
<version>2.4.3</version>
|
<dependency>
|
||||||
<executions>
|
<groupId>io.opentracing.contrib</groupId>
|
||||||
<execution>
|
<artifactId>opentracing-spanmanager</artifactId>
|
||||||
<phase>package</phase>
|
<version>0.0.5</version>
|
||||||
<goals>
|
<scope>test</scope>
|
||||||
<goal>shade</goal>
|
</dependency>
|
||||||
</goals>
|
|
||||||
<configuration>
|
</dependencies>
|
||||||
<artifactSet>
|
<build>
|
||||||
<excludes>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<!-- <exclude>ch.qos.logback:*</exclude> -->
|
<plugins>
|
||||||
<!-- <exclude>org.slf4j:*</exclude> -->
|
<plugin>
|
||||||
</excludes>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
</artifactSet>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<transformers>
|
<version>3.6.1</version>
|
||||||
<transformer
|
<configuration>
|
||||||
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
<source>${java.version}</source>
|
||||||
<resource>otarules.btm</resource>
|
<target>${java.version}</target>
|
||||||
</transformer>
|
</configuration>
|
||||||
<transformer
|
</plugin>
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
<plugin>
|
||||||
<manifestEntries>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<Agent-Class>io.opentracing.contrib.agent.AnnotationsTracingAgent</Agent-Class>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<Premain-Class>io.opentracing.contrib.agent.AnnotationsTracingAgent</Premain-Class>
|
<version>2.20</version>
|
||||||
<Can-Redefine-Classes>true</Can-Redefine-Classes>
|
<configuration>
|
||||||
<Can-Retransform-Classes>true</Can-Retransform-Classes>
|
<argLine>
|
||||||
<Boot-Class-Path>./${project.artifactId}.jar</Boot-Class-Path>
|
-javaagent:${M2_REPO}/com/datadoghq/dd-java-agent/${project.version}/dd-java-agent-${project.version}.jar
|
||||||
</manifestEntries>
|
</argLine>
|
||||||
</transformer>
|
<includes>
|
||||||
</transformers>
|
<include>*Test.java</include>
|
||||||
</configuration>
|
</includes>
|
||||||
</execution>
|
</configuration>
|
||||||
</executions>
|
</plugin>
|
||||||
</plugin>
|
<plugin>
|
||||||
</plugins>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
</build>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.4.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactSet>
|
||||||
|
<excludes>
|
||||||
|
<!-- <exclude>ch.qos.logback:*</exclude> -->
|
||||||
|
<!-- <exclude>org.slf4j:*</exclude> -->
|
||||||
|
</excludes>
|
||||||
|
</artifactSet>
|
||||||
|
<transformers>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||||
|
<resource>otarules.btm</resource>
|
||||||
|
</transformer>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Agent-Class>io.opentracing.contrib.agent.AnnotationsTracingAgent</Agent-Class>
|
||||||
|
<Premain-Class>io.opentracing.contrib.agent.AnnotationsTracingAgent
|
||||||
|
</Premain-Class>
|
||||||
|
<Can-Redefine-Classes>true</Can-Redefine-Classes>
|
||||||
|
<Can-Retransform-Classes>true</Can-Retransform-Classes>
|
||||||
|
<Boot-Class-Path>./${project.artifactId}.jar</Boot-Class-Path>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -16,8 +16,6 @@ ENDRULE
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
# Instrument AWS client
|
# Instrument AWS client
|
||||||
RULE AWS SDK Client instrumentation 1
|
RULE AWS SDK Client instrumentation 1
|
||||||
|
@ -44,3 +42,57 @@ DO
|
||||||
$this.requestHandlers.add(0, requestTracerHandler);
|
$this.requestHandlers.add(0, requestTracerHandler);
|
||||||
ENDRULE
|
ENDRULE
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------
|
||||||
|
# Instrument Elasticsearch client
|
||||||
|
RULE Elasticsearch Client instrumentation 1
|
||||||
|
CLASS org.elasticsearch.client.RestClientBuilder
|
||||||
|
METHOD build()
|
||||||
|
BIND
|
||||||
|
callback:io.opentracing.contrib.elasticsearch.TracingHttpClientConfigCallback = new io.opentracing.contrib.elasticsearch.TracingHttpClientConfigCallback();
|
||||||
|
AT ENTRY
|
||||||
|
IF TRUE
|
||||||
|
DO
|
||||||
|
$this.setHttpClientConfigCallback(callback);
|
||||||
|
ENDRULE
|
||||||
|
|
||||||
|
|
||||||
|
RULE Elasticsearch Client instrumentation 2
|
||||||
|
CLASS org.elasticsearch.client.transport.TransportClient
|
||||||
|
METHOD doExecute
|
||||||
|
HELPER io.opentracing.contrib.agent.OpenTracingHelper
|
||||||
|
BIND
|
||||||
|
span:io.opentracing.Span = null;
|
||||||
|
# decorator:io.opentracing.contrib.elasticsearch.SpanDecorator = io.opentracing.contrib.elasticsearch.SpanDecorator;
|
||||||
|
AT ENTRY
|
||||||
|
IF currentSpan() == null
|
||||||
|
DO
|
||||||
|
span = getTracer().buildSpan($2.getClass().getSimpleName())
|
||||||
|
.asChildOf()
|
||||||
|
.withTag(io.opentracing.tag.Tags.SPAN_KIND.getKey(), io.opentracing.tag.Tags.SPAN_KIND_CLIENT)
|
||||||
|
.start();
|
||||||
|
# decorator.onRequest(span);
|
||||||
|
$3 = new io.opentracing.contrib.elasticsearch.TracingResponseListener($3, span);
|
||||||
|
ENDRULE
|
||||||
|
|
||||||
|
|
||||||
|
RULE Elasticsearch Client instrumentation 3
|
||||||
|
CLASS org.elasticsearch.client.transport.TransportClient
|
||||||
|
METHOD doExecute
|
||||||
|
HELPER io.opentracing.contrib.agent.OpenTracingHelper
|
||||||
|
BIND
|
||||||
|
span:io.opentracing.Span = null;
|
||||||
|
# decorator:io.opentracing.contrib.elasticsearch.SpanDecorator = io.opentracing.contrib.elasticsearch.SpanDecorator;
|
||||||
|
AT ENTRY
|
||||||
|
IF currentSpan() != null
|
||||||
|
DO
|
||||||
|
span = getTracer().buildSpan($2.getClass().getSimpleName())
|
||||||
|
.asChildOf(currentSpan())
|
||||||
|
.withTag(io.opentracing.tag.Tags.SPAN_KIND.getKey(), io.opentracing.tag.Tags.SPAN_KIND_CLIENT)
|
||||||
|
.start();
|
||||||
|
# decorator.onRequest(span);
|
||||||
|
$3 = new io.opentracing.contrib.elasticsearch.TracingResponseListener($3, span);
|
||||||
|
ENDRULE
|
||||||
|
# --------------------------------------------------------
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
package com.datadoghq.trace.instrument;
|
||||||
|
|
||||||
|
import io.opentracing.Tracer;
|
||||||
|
import io.opentracing.contrib.spanmanager.DefaultSpanManager;
|
||||||
|
import io.opentracing.mock.MockTracer;
|
||||||
|
import io.opentracing.util.GlobalTracer;
|
||||||
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
|
import org.elasticsearch.action.index.IndexResponse;
|
||||||
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
||||||
|
import org.elasticsearch.node.InternalSettingsPreparer;
|
||||||
|
import org.elasticsearch.node.Node;
|
||||||
|
import org.elasticsearch.plugins.Plugin;
|
||||||
|
import org.elasticsearch.transport.Netty3Plugin;
|
||||||
|
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||||
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by gpolaert on 5/23/17.
|
||||||
|
*/
|
||||||
|
public class ElasticSearchInstrumentationTest {
|
||||||
|
|
||||||
|
|
||||||
|
private static final int HTTP_PORT = 9205;
|
||||||
|
private static final String HTTP_TRANSPORT_PORT = "9305";
|
||||||
|
private static final String ES_WORKING_DIR = "target/es";
|
||||||
|
private static String clusterName = "cluster-name";
|
||||||
|
private static Node node;
|
||||||
|
private static MockTracer tracer;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startElasticsearch() throws Exception {
|
||||||
|
|
||||||
|
tracer = new MockTracer();
|
||||||
|
GlobalTracer.register(tracer);
|
||||||
|
|
||||||
|
|
||||||
|
Settings settings = Settings.builder()
|
||||||
|
.put("path.home", ES_WORKING_DIR)
|
||||||
|
.put("path.data", ES_WORKING_DIR + "/data")
|
||||||
|
.put("path.logs", ES_WORKING_DIR + "/logs")
|
||||||
|
.put("transport.type", "netty3")
|
||||||
|
.put("http.type", "netty3")
|
||||||
|
.put("cluster.name", clusterName)
|
||||||
|
.put("http.port", HTTP_PORT)
|
||||||
|
.put("transport.tcp.port", HTTP_TRANSPORT_PORT)
|
||||||
|
.put("network.host", "127.0.0.1")
|
||||||
|
.build();
|
||||||
|
Collection plugins = Collections.singletonList(Netty3Plugin.class);
|
||||||
|
node = new PluginConfigurableNode(settings, plugins);
|
||||||
|
node.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopElasticsearch() throws Exception {
|
||||||
|
node.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
DefaultSpanManager.getInstance().activate(tracer.buildSpan("parent").start());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
DefaultSpanManager.getInstance().current().close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void Test() throws IOException {
|
||||||
|
|
||||||
|
Settings settings = Settings.builder()
|
||||||
|
.put("cluster.name", clusterName).build();
|
||||||
|
|
||||||
|
|
||||||
|
TransportClient client = new PreBuiltTransportClient(settings)
|
||||||
|
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"),
|
||||||
|
Integer.parseInt(HTTP_TRANSPORT_PORT)));
|
||||||
|
|
||||||
|
IndexRequest indexRequest = new IndexRequest("twitter").type("tweet").id("1").
|
||||||
|
source(jsonBuilder()
|
||||||
|
.startObject()
|
||||||
|
.field("user", "kimchy")
|
||||||
|
.field("postDate", new Date())
|
||||||
|
.field("message", "trying out Elasticsearch")
|
||||||
|
.endObject()
|
||||||
|
);
|
||||||
|
|
||||||
|
IndexResponse indexResponse = client.index(indexRequest).actionGet();
|
||||||
|
|
||||||
|
|
||||||
|
client.close();
|
||||||
|
DefaultSpanManager.getInstance().current().close();
|
||||||
|
assertThat(tracer.finishedSpans().size()).isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class PluginConfigurableNode extends Node {
|
||||||
|
public PluginConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
|
||||||
|
super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue