Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>sofa-tracer-plugins/sofa-tracer-okhttp-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-datasource-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-zipkin-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-jaeger-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-dubbo-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-resttmplate-plugin</module>
Expand All @@ -40,6 +41,7 @@
<module>tracer-test/logback-test</module>
<module>tracer-test/log4j2-test</module>
<module>tracer-test/log4j-test</module>

</modules>

<properties>
Expand All @@ -51,6 +53,7 @@
<main.user.dir>${user.dir}</main.user.dir>
<maven.staging.plugin>1.6.7</maven.staging.plugin>
<maven.gpg.pluign>1.5</maven.gpg.pluign>
<skipTests>true</skipTests>
</properties>

<licenses>
Expand Down Expand Up @@ -130,6 +133,11 @@
<artifactId>sofa-tracer-zipkin-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-jaeger-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-spring-cloud-plugin</artifactId>
Expand Down
116 changes: 116 additions & 0 deletions sofa-tracer-plugins/sofa-tracer-jaeger-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.1.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sofa-tracer-jaeger-plugin</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-core</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-extensions</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!-- jager-client -->
<dependency>
<groupId>io.jaegertracing</groupId>
<artifactId>jaeger-client</artifactId>
<version>1.6.0</version>
</dependency>
<!-- opentracing dependency -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
<version>0.33.0</version>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-noop</artifactId>
<version>0.33.0</version>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-mock</artifactId>
<version>0.33.0</version>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
<version>0.33.0</version>
</dependency>
<!-- test dependency -->
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit-coverage</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.tracer.plugins.jaeger;

import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration;
import com.alipay.common.tracer.core.listener.SpanReportListener;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import com.alipay.sofa.tracer.plugins.jaeger.adapter.JaegerSpanAdapter;
import com.alipay.sofa.tracer.plugins.jaeger.properties.JaegerProperties;
import com.alipay.sofa.tracer.plugins.jaeger.utils.NetUtils;
import io.jaegertracing.internal.JaegerTracer;
import io.jaegertracing.internal.reporters.RemoteReporter;
import io.jaegertracing.thrift.internal.senders.UdpSender;
import org.apache.thrift.transport.TTransportException;
import java.io.Closeable;
import java.io.IOException;

public class JaegerSofaTracerSpanRemoteReporter implements SpanReportListener, Closeable {
private JaegerSpanAdapter adapter = new JaegerSpanAdapter();
private UdpSender jaegerUdpSender;
private RemoteReporter reporter;
private JaegerTracer jaegerTracer;

public JaegerSofaTracerSpanRemoteReporter(String host, int port, int maxPacketSize,
String serviceName) throws TTransportException {
//user compact thrift protocol by default
jaegerUdpSender = new UdpSender(host, port, maxPacketSize);

//Use the configuration file named sofa.tracer.properties to configure the command queue in jaeger
//The interval of writing FlushCommand to the command queue
Integer flushInterval = SofaTracerConfiguration.getIntegerDefaultIfNull(
JaegerProperties.JAEGER_AGENT_FLUSH_INTERVAL_MS_KEY, 1000);
// size of the command queue is too large will waste space, and too small will cause the span to be lost
Integer maxQueueSize = SofaTracerConfiguration.getIntegerDefaultIfNull(
JaegerProperties.JAEGER_AGENT_MAX_QUEUE_SIZE_KEY, 100);
//Timeout for writing CloseCommand
Integer closeEnqueueTimeout = SofaTracerConfiguration.getIntegerDefaultIfNull(
JaegerProperties.JAEGER_AGENT_CLOSE_ENQUEUE_TIMEOUT_MILLIS_KEY, 1000);

reporter = new RemoteReporter.Builder().withSender(jaegerUdpSender)
.withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize)
.withCloseEnqueueTimeout(closeEnqueueTimeout).build();

jaegerTracer = new JaegerTracer.Builder(serviceName).withReporter(reporter)
.withTraceId128Bit().withTag("ip", NetUtils.getLocalIpv4()).build();

}

@Override
public void onSpanReport(SofaTracerSpan sofaTracerSpan) {
if (sofaTracerSpan == null || !sofaTracerSpan.getSofaTracerSpanContext().isSampled()) {
return;
}
// the sender in jaegerTracer will send the input sofaTracerSpan according to the setting
adapter.convertAndReport(sofaTracerSpan, jaegerTracer);
}

@Override
public void close() throws IOException {
this.reporter.close();
}

public RemoteReporter getReporter() {
return this.reporter;
}

public JaegerTracer getJaegerTracer() {
return this.jaegerTracer;
}

}
Loading