Skip to content

Instantly share code, notes, and snippets.

View wu-sheng's full-sized avatar
🌍
Working from home, travel globally

吴晟 Wu Sheng wu-sheng

🌍
Working from home, travel globally
View GitHub Profile
@wu-sheng
wu-sheng / AppendToBootstrapClassLoaderSearch.java
Last active March 7, 2024 06:14
byte-buddy appendToBootstrapClassLoaderSearch, and jdk instrumentation
/**
* All codes from stagemonitor apm, which gives a example about how to use instrumentation::appendToBootstrapClassLoaderSearch
* This will be very useful for instrument some class in rt.jar
*/
private static boolean initInstrumentation() {
try {
/**
* this try-catch block shows two ways about instrumentation.
* ref issue: https://github.com/raphw/byte-buddy/issues/237
*/
@wu-sheng
wu-sheng / Transaction.java
Created December 28, 2016 03:43
Transaction Trace
/**
* Created by wusheng on 2016/12/21.
*/
public class Transaction {
// 当前线程事务GUID
private java.lang.String traceId;
// 相关性上级GUID
private java.lang.String refTraceId;
// 全局 GUID
private java.lang.String tripId;
@wu-sheng
wu-sheng / Random.Long_TraceId_Generation_banchmark.md
Last active December 28, 2016 03:24
TraceId Generation by Random.Long
  • My laptop benchmarks normal random long (including work to create the java object representing a context) is something like 40 per microsecond
  • Desktop: 2.8Ghz macbook pro
  • Using threadlocalrandom
@wu-sheng
wu-sheng / TraceAndSpanIdGenerator.java
Created December 28, 2016 03:15
TraceAndSpanIdGenerator From nike.wingtips
/**
* Code from
* https://github.com/Nike-Inc/wingtips/blob/38d8ce83207ffee3d638bf7466b8f7058bb36498/wingtips-core/src/main/java/com/nike/wingtips/TraceAndSpanIdGenerator.java#L60
* Thanks to @adriancole
*/
public static long generate64BitRandomLong() {
byte[] random8Bytes = new byte[8];
random.nextBytes(random8Bytes);
@wu-sheng
wu-sheng / TraceIdGenerator.java
Created December 26, 2016 02:53
sky-walking TraceIdGenerator
public final class TraceIdGenerator {
private static final ThreadLocal<Integer> ThreadTraceIdSequence = new ThreadLocal<Integer>(){
@Override
protected Integer initialValue() {
return 0;
}
};
private static final int PROCESS_UUID;
@wu-sheng
wu-sheng / TracerLoader.java
Created December 21, 2016 08:00
ServiceLoader of OT tracer
package io.opentracing.contrib;
import io.opentracing.NoopTracerFactory;
import io.opentracing.Tracer;
import java.util.Iterator;
import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
@wu-sheng
wu-sheng / opentracing-zipkin.md
Created December 21, 2016 06:30 — forked from codefromthecrypt/opentracing-zipkin.md
My ramble on OpenTracing (with a side of Zipkin)

I've had many people ask me questions about OpenTracing, often in relation to OpenZipkin. I've seen assertions about how it is vendor neutral and is the lock-in cure. This post is not a sanctioned, polished or otherwise muted view, rather what I personally think about what it is and is not, and what it helps and does not help with. Scroll to the very end if this is too long. Feel free to add a comment if I made any factual mistakes or you just want to add a comment.

So, what is OpenTracing?

OpenTracing is documentation and library interfaces for distributed tracing instrumentation. To be "OpenTracing" requires bundling its interfaces in your work, so that others can use it to time distributed operations with the same library.

So, who is it for?

OpenTracing interfaces are targeted to authors of instrumentation libraries, and those who want to collaborate with traces created by them. Ex something started a trace somewhere and I add a notable event to that trace. Structure logging was recently added to O