源码中有如下 sample:
1 var distributedTracingData = DistributedTracingData.TryDeserializeFromString(args[0]); 2 3 WriteLineToConsole($"Callee process started - continuing trace with distributed tracing data: {distributedTracingData}"); 4 var transaction2 = Agent.Tracer.StartTransaction("Transaction2", "TestTransaction", distributedTracingData); 5 6 try 7 { 8 transaction2.CaptureSpan("TestSpan", "TestSpanType", () => Thread.Sleep(200)); 9 } 10 finally 11 { 12 transaction2.End(); 13 }
Agent.Tracer 这个是静态字段,public static ITracer Tracer => Instance.Tracer;
整个 Agent 就是一个静态类
Instance实际上是个单例,就是 new ApmAgent(Components)
这个里面的 Trace 又到了 AgentComponents里
这个 trace 这样new
TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigurationStore, currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo, breakdownMetricsProvider);
最后这个 trace 执行start 的时候 会 new 一个 Transaction, 之后会用到 Activity
这个里面的 StartActivity() 会 把这Activity.start()这会设置Activity.Curent
标签:distributedTracingData,Elastic,Apm,源码,Activity,trace,new,Tracer From: https://www.cnblogs.com/qgbo/p/16652556.html