protected override string CreateBody(ThreadSample threadSample) { var pprof = new Pprof(); var sampleBuilder = new SampleBuilder(); pprof.AddLabel(sampleBuilder, "source.event.time", threadSample.Timestamp.Milliseconds); if (threadSample.SpanId != 0 || threadSample.TraceIdHigh != 0 || threadSample.TraceIdLow != 0) { pprof.AddLabel(sampleBuilder, "span_id", threadSample.SpanId); pprof.AddLabel(sampleBuilder, "trace_id", TraceIdHelper.ToString(threadSample.TraceIdHigh, threadSample.TraceIdLow)); } foreach (var methodName in threadSample.Frames) { sampleBuilder.AddLocationId(pprof.GetLocationId(methodName)); } pprof.AddLabel(sampleBuilder, "thread.id", threadSample.ManagedId); pprof.AddLabel(sampleBuilder, "thread.name", threadSample.ThreadName); pprof.AddLabel(sampleBuilder, "thread.os.id", threadSample.NativeId); pprof.Profile.Samples.Add(sampleBuilder.Build()); return(Serialize(pprof.Profile)); }
public TraceInfo(TraceInfo parentTraceInfo) { ParentTraceInfo = parentTraceInfo; TraceId = parentTraceInfo?.TraceId; SpanId = TraceIdHelper.GenerateHexEncodedInt64Id(); IsSampled = parentTraceInfo?.IsSampled ?? false; IsJoinedSpan = false; Domain = parentTraceInfo?.Domain; LocalIP = parentTraceInfo?.LocalIP; }
private TraceInfo ReadTraceInfo(HttpContext context) { string headerTraceId = context.Request.Headers[TraceInfo.TraceIdHeaderName]; string headerSpanId = context.Request.Headers[TraceInfo.SpanIdHeaderName]; string headerParentSpanId = context.Request.Headers[TraceInfo.ParentSpanIdHeaderName]; string headerSampled = context.Request.Headers[TraceInfo.SampledHeaderName]; var requestPath = context.Request.Path.ToString(); var traceId = headerTraceId.IsParsableTo128Or64Bit() ? headerTraceId : TraceIdHelper.GenerateNewTraceId(_zipkinConfig.Create128BitTraceId); var spanId = headerSpanId.IsParsableToLong() ? headerSpanId : TraceIdHelper.GenerateHexEncodedInt64Id(); var parentSpanId = headerParentSpanId.IsParsableToLong() ? headerParentSpanId : string.Empty; var isSampled = _zipkinConfig.ShouldBeSampled(headerSampled, requestPath); var domain = _zipkinConfig.Domain(context.Request); var isJoinedSpan = spanId.Equals(headerSpanId); var traceInfo = new TraceInfo(traceId, spanId, isSampled, isJoinedSpan, domain, context.Connection.LocalIpAddress, parentSpanId); context.Items[TraceInfo.TraceInfoKey] = traceInfo; _traceInfoAccessor.TraceInfo = traceInfo; return(traceInfo); }