forked from sofastack/sofa-tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
report spans to SkyWalking (sofastack#443)
- Loading branch information
1 parent
ca86846
commit 974d284
Showing
39 changed files
with
1,839 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?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-skywalking-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> | ||
<!-- 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> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
67 changes: 67 additions & 0 deletions
67
...src/main/java/com/alipay/sofa/tracer/plugins/skywalking/SkywalkingSpanRemoteReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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.skywalking; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alipay.common.tracer.core.listener.SpanReportListener; | ||
import com.alipay.common.tracer.core.span.SofaTracerSpan; | ||
import com.alipay.sofa.tracer.plugins.skywalking.adapter.SkywalkingSegmentAdapter; | ||
import com.alipay.sofa.tracer.plugins.skywalking.reporter.AsyncReporter; | ||
import com.alipay.sofa.tracer.plugins.skywalking.sender.SkywalkingRestTemplateSender; | ||
import com.alipay.sofa.tracer.plugins.skywalking.model.Segment; | ||
|
||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.io.Closeable; | ||
import java.io.Flushable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* SkywalkingSpanRemoteReporter | ||
* @author zhaochen | ||
*/ | ||
public class SkywalkingSpanRemoteReporter implements SpanReportListener, Closeable, Flushable { | ||
private AsyncReporter reporter; | ||
private SkywalkingRestTemplateSender sender; | ||
private SkywalkingSegmentAdapter adapter; | ||
|
||
public SkywalkingSpanRemoteReporter(String baseUrl, int maxBufferSize) { | ||
adapter = new SkywalkingSegmentAdapter(); | ||
sender = new SkywalkingRestTemplateSender(new RestTemplate(), baseUrl); | ||
reporter = new AsyncReporter(maxBufferSize, sender); | ||
} | ||
|
||
@Override | ||
public void onSpanReport(SofaTracerSpan sofaTracerSpan) { | ||
if (sofaTracerSpan == null || !sofaTracerSpan.getSofaTracerSpanContext().isSampled()) { | ||
return; | ||
} | ||
Segment segment = adapter.convertToSkywalkingSegment(sofaTracerSpan); | ||
int segmentSize = JSON.toJSONString(segment).length(); | ||
reporter.report(segment, segmentSize); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
reporter.close(); | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
reporter.flush(); | ||
} | ||
} |
Oops, something went wrong.