public SegmentContext CreateExitSegment(string operationName, StringOrIntValue networkAddress, long startTimeMilliseconds = default) { var parentSegmentContext = GetParentSegmentContext(SpanType.Exit); var traceId = GetTraceId(parentSegmentContext); var segmentId = GetSegmentId(); var sampled = GetSampled(parentSegmentContext, operationName, networkAddress); var segmentContext = new SegmentContext(traceId, segmentId, sampled, _instrumentConfig.ServiceName ?? _instrumentConfig.ApplicationCode, _instrumentConfig.ServiceInstanceName, operationName, SpanType.Exit, startTimeMilliseconds); if (parentSegmentContext != null) { var parentReference = parentSegmentContext.References.FirstOrDefault(); var reference = new SegmentReference { Reference = Reference.CrossThread, EntryEndpoint = parentReference?.EntryEndpoint ?? parentSegmentContext.Span.OperationName, NetworkAddress = parentReference?.NetworkAddress ?? parentSegmentContext.Span.OperationName, ParentEndpoint = parentSegmentContext.Span.OperationName, ParentSpanId = parentSegmentContext.Span.SpanId, ParentSegmentId = parentSegmentContext.SegmentId, EntryServiceInstanceId = parentReference?.EntryServiceInstanceId ?? parentSegmentContext.ServiceInstanceId, ParentServiceInstanceId = parentSegmentContext.ServiceInstanceId, ParentServiceId = parentSegmentContext.ServiceId, TraceId = parentSegmentContext.TraceId }; segmentContext.References.Add(reference); } segmentContext.Span.Peer = networkAddress; _exitSegmentContextAccessor.Context = segmentContext; return(segmentContext); }
public SegmentContext CreateExitSegment(string operationName, StringOrIntValue networkAddress) { var parentSegmentContext = GetParentSegmentContext(SpanType.Exit); var traceId = GetTraceId(parentSegmentContext); var segmentId = GetSegmentId(); var sampled = GetSampled(parentSegmentContext, operationName, networkAddress); var segmentContext = new SegmentContext(traceId, segmentId, sampled, _runtimeEnvironment.ServiceId.Value, _runtimeEnvironment.ServiceInstanceId.Value, operationName, SpanType.Exit); if (parentSegmentContext != null) { var parentReference = parentSegmentContext.References.FirstOrDefault(); var reference = new SegmentReference { Reference = Reference.CrossThread, EntryEndpoint = parentReference?.EntryEndpoint ?? parentSegmentContext.Span.OperationName, NetworkAddress = parentReference?.NetworkAddress ?? parentSegmentContext.Span.OperationName, ParentEndpoint = parentSegmentContext.Span.OperationName, ParentSpanId = parentSegmentContext.Span.SpanId, ParentSegmentId = parentSegmentContext.SegmentId, EntryServiceInstanceId = parentReference?.EntryServiceInstanceId ?? parentSegmentContext.ServiceInstanceId, ParentServiceInstanceId = parentSegmentContext.ServiceInstanceId }; segmentContext.References.Add(reference); } segmentContext.Span.Peer = networkAddress; _exitSegmentContextAccessor.Context = segmentContext; return(segmentContext); }
public SamplingContext(string operationName, StringOrIntValue peer, StringOrIntValue entryEndpoint, StringOrIntValue parentEndpoint) { OperationName = operationName; Peer = peer; EntryEndpoint = entryEndpoint; ParentEndpoint = parentEndpoint; }
private static string ConvertStringOrIntValue(StringOrIntValue value) { if (value.HasIntValue) { return(value.GetIntValue().ToString()); } return("#" + value.GetStringValue()); }
private static void ReadStringOrIntValue <T>(T instance, StringOrIntValue stringOrIntValue, Action <T, string> stringValueReader, Action <T, int> intValueReader) { if (stringOrIntValue.HasStringValue) { stringValueReader.Invoke(instance, stringOrIntValue.GetStringValue()); } else if (stringOrIntValue.HasIntValue) { intValueReader.Invoke(instance, stringOrIntValue.GetIntValue()); } }
private bool GetSampled(SegmentContext parentSegmentContext, string operationName, StringOrIntValue peer = default(StringOrIntValue)) { if (parentSegmentContext != null) { return(parentSegmentContext.Sampled); } var sampledContext = new SamplingContext(operationName, peer, new StringOrIntValue(operationName), default(StringOrIntValue)); var sampler = _samplerChainBuilder.Build(); return(sampler(sampledContext)); }
private static void ReadStringOrIntValue <T>(T instance, StringOrIntValue stringOrIntValue, Action <T, string> stringValueReader, Action <T, int> intValueReader) { // We should first check and prefer the int value to reduce the network transport payload // in case both int and string value is present. if (stringOrIntValue.HasIntValue) { intValueReader.Invoke(instance, stringOrIntValue.GetIntValue()); } else if (stringOrIntValue.HasStringValue) { stringValueReader.Invoke(instance, stringOrIntValue.GetStringValue()); } }
public SegmentSpan(string operationName, SpanType spanType) { OperationName = new StringOrIntValue(operationName); SpanType = spanType; }
public SegmentSpan(string operationName, SpanType spanType, long startTimeMilliseconds = default) { OperationName = new StringOrIntValue(operationName); SpanType = spanType; StartTime = startTimeMilliseconds == default ? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() : startTimeMilliseconds; }