private void LogStartOfRequest(HttpRequestMessage request, Action <IApmContext, ApmHttpClientStartInformation> startAction) { var applicationName = _apmHttpRequestMessageParser.GetApplicationName(request); var eventName = _apmHttpRequestMessageParser.GetEventName(request); var methodIdentifier = _apmHttpRequestMessageParser.GetMethodIdentifier(request); var clientName = _apmHttpRequestMessageParser.GetClientName(request); var incomingTraceId = _apmHttpRequestMessageParser.GetIncomingTraceId(request); var incomingSpanId = _apmHttpRequestMessageParser.GetIncomingSpanId(request); var incomingParentSpanId = _apmHttpRequestMessageParser.GetIncomingParentSpanId(request); var incomingFlags = _apmHttpRequestMessageParser.GetIncomingFlags(request); var incomingSampled = _apmHttpRequestMessageParser.GetIncomingSampled(request); var traceId = _apmHttpRequestMessageParser.GetTraceId(request); var spanId = _apmHttpRequestMessageParser.GetSpanId(request); var parentSpanId = _apmHttpRequestMessageParser.GetParentSpanId(request); var flags = _apmHttpRequestMessageParser.GetFlags(request); var sampled = _apmHttpRequestMessageParser.GetSampled(request); var apmHttpClientStartInformation = new ApmHttpClientStartInformation { ApplicationName = applicationName, EventName = eventName, MethodIdentifier = methodIdentifier, Request = request, ClientName = clientName, IncomingTraceId = incomingTraceId, IncomingSpanId = incomingSpanId, IncomingParentSpanId = incomingParentSpanId, IncomingSampled = incomingSampled, IncomingFlags = incomingFlags, TraceId = traceId, SpanId = spanId, ParentSpanId = parentSpanId, Sampled = sampled, Flags = flags }; object apmContextObject; if (!request.Properties.TryGetValue(Constants.ApmContextPropertyKey, out apmContextObject)) { apmContextObject = new ApmContext(); request.Properties.Add(Constants.ApmContextPropertyKey, apmContextObject); } var apmContext = (IApmContext)apmContextObject; if (!apmContext.ContainsKey(Constants.RequestUriPropertyKey)) { apmContext[Constants.RequestUriPropertyKey] = request.RequestUri.ToString(); } if (!apmContext.ContainsKey(Constants.RequestMethodPropertyKey)) { apmContext[Constants.RequestMethodPropertyKey] = request.Method.ToString(); } startAction(apmContext, apmHttpClientStartInformation); }
public void GetTraceIdWhenOneIsNotSpecified() { var request = new HttpRequestMessage(); var apmRequestParser = new ApmHttpRequestMessageParser(); var traceId = apmRequestParser.GetTraceId(request); Assert.IsEmpty(traceId); }
public void GetTraceIdWhenAnInvalidOneIsSpecifiedInProperties() { var request = new HttpRequestMessage(); request.Properties.Add(Constants.TraceIdHeaderKey, "jimmm,bobby,susan"); var apmRequestParser = new ApmHttpRequestMessageParser(); var traceId = apmRequestParser.GetTraceId(request); Assert.AreEqual("jimmm,bobby,susan", traceId); }
public void GetTraceIdWhenAValidOneIsSpecifiedInProperties() { var request = new HttpRequestMessage(); request.Properties.Add(Constants.TraceIdHeaderKey, "clienta=ADSFFF"); var apmRequestParser = new ApmHttpRequestMessageParser(); var traceId = apmRequestParser.GetTraceId(request); Assert.AreEqual("clienta=ADSFFF", traceId); }