-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7742] export trace info for agent-sdk
- Loading branch information
Showing
8 changed files
with
347 additions
and
2 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
agent-sdk/src/main/java/com/navercorp/pinpoint/sdk/v1/trace/info/DefaultTraceInfo.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,68 @@ | ||
/* | ||
* Copyright 2022 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.sdk.v1.trace.info; | ||
|
||
/** | ||
* @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 + | ||
'}'; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
agent-sdk/src/main/java/com/navercorp/pinpoint/sdk/v1/trace/info/TraceInfo.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,53 @@ | ||
/* | ||
* Copyright 2022 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.sdk.v1.trace.info; | ||
|
||
/** | ||
* @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); | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
agent-sdk/src/main/java/com/navercorp/pinpoint/sdk/v1/trace/info/TraceInfoHolder.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,63 @@ | ||
/* | ||
* Copyright 2022 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.sdk.v1.trace.info; | ||
|
||
/** | ||
* @author yjqg6666 | ||
* @since 2020-05-15 14:25:50 | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class TraceInfoHolder { | ||
|
||
private static final ThreadLocal<TraceInfo> HOLDER = new ThreadLocal<>(); | ||
|
||
public static String getTransactionId() { | ||
TraceInfo traceInfo = getTraceInfo(); | ||
return traceInfo == null ? null : traceInfo.getTransactionId(); | ||
} | ||
|
||
public static long getSpanId() { | ||
TraceInfo traceInfo = getTraceInfo(); | ||
return traceInfo == null ? 0 : traceInfo.getSpanId(); | ||
} | ||
|
||
public static TraceInfo getTraceInfo() { | ||
return HOLDER.get(); | ||
} | ||
|
||
public static 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 static void setTraceInfo(String txId, long spanId) { | ||
HOLDER.set(new DefaultTraceInfo(txId, spanId)); | ||
} | ||
|
||
public static void clearTraceInfo() { | ||
HOLDER.remove(); | ||
} | ||
|
||
public static String toInfoString() { | ||
return "DefaultTraceInfoHolder{data=" + getTraceInfo() + "}"; | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
.../src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/util/ClassLoaderUtils.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,53 @@ | ||
/* | ||
* Copyright 2022 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.bootstrap.plugin.request.util; | ||
|
||
/** | ||
* @author yjqg6666 | ||
*/ | ||
@SuppressWarnings("unused") | ||
class ClassLoaderUtils { | ||
|
||
public static Class<?> loadClassFromAppObject(Object appLoadedObject, String className) { | ||
ClassLoader appClassLoader = getAppClassLoader(appLoadedObject); | ||
return loadClassFromClassLoader(appClassLoader, className); | ||
} | ||
|
||
public static Class<?> loadClassFromClassLoader(ClassLoader appClassLoader, String className) { | ||
if (appClassLoader == null || className == null) { | ||
return null; | ||
} | ||
try { | ||
return Class.forName(className, false, appClassLoader); | ||
} catch (Throwable t) { | ||
//t.printStackTrace(); | ||
//do nothing even no logging for no introduced dependency | ||
} | ||
return null; | ||
} | ||
|
||
public static ClassLoader getAppClassLoader(Object appLoadedObject) { | ||
if (appLoadedObject == null) { | ||
return null; | ||
} | ||
Class<?> targetClass = appLoadedObject.getClass(); | ||
if (targetClass == null) { | ||
return null; | ||
} | ||
return targetClass.getClassLoader(); | ||
} | ||
} |
Oops, something went wrong.