Skip to content

Commit

Permalink
support export trace info to app for external usage
Browse files Browse the repository at this point in the history
  • Loading branch information
yjqg6666 committed May 19, 2020
1 parent d95eabf commit 01afe4e
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 1 deletion.
1 change: 1 addition & 0 deletions agent/src/assembly/component/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<includes>
<include>com.navercorp.pinpoint:pinpoint-annotations</include>
<include>com.navercorp.pinpoint:pinpoint-commons</include>
<include>com.navercorp.pinpoint:pinpoint-trace-info-export</include>
<include>com.navercorp.pinpoint:pinpoint-bootstrap-core</include>
<include>com.navercorp.pinpoint:pinpoint-bootstrap-java7</include>
<include>com.navercorp.pinpoint:pinpoint-bootstrap-java8</include>
Expand Down
4 changes: 4 additions & 0 deletions bootstrap-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-trace-info-export</artifactId>
</dependency>

<!-- Logging dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ProfilerLibs {
"com.navercorp.pinpoint.io",
"com.navercorp.pinpoint.rpc",
"com.navercorp.pinpoint.loader.plugins",
"com.navercorp.pinpoint.export",

// grpc
"com.navercorp.pinpoint.grpc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.navercorp.pinpoint.bootstrap.context.SpanRecorder;
import com.navercorp.pinpoint.bootstrap.context.Trace;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.context.TraceId;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.bootstrap.plugin.RequestRecorderFactory;
Expand All @@ -33,6 +34,7 @@
import com.navercorp.pinpoint.bootstrap.plugin.request.util.ParameterRecorder;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.export.TraceInfoExportHelper;

/**
* @author jaehong.kim
Expand Down Expand Up @@ -107,6 +109,10 @@ public void initialized(T request, final ServiceType serviceType, final MethodDe
return;
}

TraceId traceId = trace.getTraceId();
if (traceId != null) {
TraceInfoExportHelper.exportTraceInfo(request, traceId.getTransactionId(), traceId.getSpanId());
}
final SpanEventRecorder recorder = trace.traceBlockBegin();
recorder.recordServiceType(serviceType);
recorder.recordApi(methodDescriptor);
Expand Down Expand Up @@ -144,6 +150,9 @@ public void destroyed(T request, final Throwable throwable, final int statusCode
return;
}

// clear trace info which is put in initialized method
TraceInfoExportHelper.clearExportedTraceInfo(request);

// TODO STATDISABLE this logic was added to disable statistics tracing
if (!trace.canSampled()) {
traceContext.removeTraceObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class AgentDirBaseClassPathResolver implements ClassPathResolver {
private final JarDescription bootstrapJava7 = new JarDescription("pinpoint-bootstrap-java7", false);
private final JarDescription bootstrapJava8 = new JarDescription("pinpoint-bootstrap-java8", false);
private final JarDescription bootstrapJava9 = new JarDescription("pinpoint-bootstrap-java9", false);
private final List<JarDescription> bootJarDescriptions = Arrays.asList(commons, bootstrapCore, annotations, bootstrapJava7, bootstrapJava8, bootstrapJava9);
private final JarDescription traceInfoExport = new JarDescription("pinpoint-trace-info-export", false);
private final List<JarDescription> bootJarDescriptions = Arrays.asList(commons, bootstrapCore, annotations, bootstrapJava7, bootstrapJava8, bootstrapJava9, traceInfoExport);

private final String classPath;

Expand Down
52 changes: 52 additions & 0 deletions info-export/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2020 NAVER Corp.
~
~ Licensed 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.
-->

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint</artifactId>
<version>2.0.3-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-trace-info-export</artifactId>
<name>pinpoint-trace-info-export</name>
<packaging>jar</packaging>

<properties>
<jdk.version>1.6</jdk.version>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2020 NAVER Corp.
*
* Licensed 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.navercorp.pinpoint.export;

/**
* @author yjqg6666
* @since 2020-05-15 14:43:39
*/
@SuppressWarnings("unused")
public class DefaultTraceInfo implements TraceInfo {

private String transactionId;

private long spanId;

public DefaultTraceInfo(String txId, long spanId) {
setTransactionId(txId);
setSpanId(spanId);
}

public DefaultTraceInfo() {
}

@Override
public String getTransactionId() {
return transactionId;
}

@Override
public void setTransactionId(String txId) {
if (txId == null) {
throw new NullPointerException("TransactionId can NOT be null");
}
this.transactionId = txId;
}

@Override
public long getSpanId() {
return spanId;
}

@Override
public void setSpanId(long spanId) {
this.spanId = spanId;
}

@Override
public String toString() {
return "DefaultTraceInfo{" +
"transactionId='" + transactionId + '\'' +
", spanId=" + spanId +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2020 NAVER Corp.
*
* Licensed 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.navercorp.pinpoint.export;

/**
* @author yjqg6666
* @since 2020-05-15 14:25:50
*/
@SuppressWarnings("unused")
public class DefaultTraceInfoHolder implements TraceInfoHolder {

private static final ThreadLocal<TraceInfo> HOLDER = new ThreadLocal<TraceInfo>();

@Override
public String getTransactionId() {
TraceInfo traceInfo = getTraceInfo();
return traceInfo == null ? null : traceInfo.getTransactionId();
}

@Override
public long getSpanId() {
TraceInfo traceInfo = getTraceInfo();
return traceInfo == null ? 0 : traceInfo.getSpanId();
}

@Override
public TraceInfo getTraceInfo() {
return HOLDER.get();
}

@Override
public void setTraceInfo(TraceInfo traceInfo) {
if (traceInfo == null) {
throw new NullPointerException("TraceInfo can NOT be null");
}
if (traceInfo.getTransactionId() == null) {
throw new NullPointerException("TraceInfo.transactionId can NOT be null");
}
HOLDER.set(traceInfo);
}

public void setTraceInfo(String txId, long spanId) {
HOLDER.set(new DefaultTraceInfo(txId, spanId));
}

@Override
public void clearTraceInfo() {
HOLDER.remove();
}

@Override
public String toString() {
return "DefaultTraceInfoHolder{data=" + getTraceInfo() + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2020 NAVER Corp.
*
* Licensed 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.navercorp.pinpoint.export;

/**
* @author yjqg6666
*/
@SuppressWarnings("unused")
public interface TraceInfo {

/**
* get transaction id
*
* @return txId
*/
String getTransactionId();

/**
* set transaction id
*
* @param txId txId
*/
void setTransactionId(String txId);

/**
* get span id
*
* @return span id
*/
long getSpanId();

/**
* set span id
*
* @param spanId span id
*/
void setSpanId(long spanId);

}
Loading

0 comments on commit 01afe4e

Please sign in to comment.