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);
        }
        private static CounterCreationDataCollection GetCounterCreationDataCollectionForApmContextUsage(MethodInfo[] apmContextUsages)
        {
            var counterCreationDataCollection = new CounterCreationDataCollection();

            Trace.TraceInformation("Number of get context uses actions: {0}", apmContextUsages.Length);

            foreach (var apmContextUsage in apmContextUsages)
            {
                var methodIdentifier = ApmContext.GetMethodIdentifier(apmContextUsage);
                var eventName        = ApmContext.GetEventName(apmContextUsage);

                Trace.TraceInformation("Setting up get context uses '{0}' for event '{1}'", methodIdentifier, eventName);

                //Setup action performance counters
                foreach (var counterHandler in PerformanceCounterApmHttpClientDelegatingHandler.CounterHandlers)
                {
                    if (counterCreationDataCollection.Cast <CounterCreationData>().Any(x => x.CounterName == methodIdentifier))
                    {
                        Trace.TraceInformation("Counter for method '{0}' was duplicate", methodIdentifier);
                    }
                    else
                    {
                        var countersToCreate = counterHandler.GetCreationData(methodIdentifier);
                        foreach (var counterToCreate in countersToCreate)
                        {
                            Trace.TraceInformation("Added counter for method '{0}'", counterToCreate.CounterName);
                        }

                        counterCreationDataCollection.AddRange(countersToCreate);
                    }
                }
            }

            return(counterCreationDataCollection);
        }
Esempio n. 3
0
        private IEnumerable <string> ReadFromFakeDatabaseForDepthZero()
        {
            var apmContext    = ApmContext.GetContext();
            var methodHandler = apmContext.GetMethodHander();

            return(methodHandler.Execute <IEnumerable <string> >(() => new[] { "zero" }));
        }
Esempio n. 4
0
        public List <string> GetDepthThreeException(int id)
        {
            var context = ApmContext.GetContext();

            context["id"] = id.ToString();

            using (var client = new HttpClient(context.GetDelegatingHandler()))
            {
                client.BaseAddress = _baseUrl;
                var url      = string.Format("api/DepthThree/GetDepthThreeException/{0}", id);
                var response = client.GetAsync(url).ConfigureAwait(false).GetAwaiter().GetResult();

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(string.Format("GetDepthThreeException - {0} {1} {2}", url, response.StatusCode,
                                                      response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult()));
                }

                var results =
                    Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(
                        response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult());

                return(results);
            }
        }
Esempio n. 5
0
        public void WhenAddingTrackingInformationWithNoPreviousTracing()
        {
            _apmContext.Add(Constants.ClientNamePropertyKey, "TestClient");

            ApmContext.SetTracing(_apmContext);

            var traceId = (string)_apmContext[Constants.TraceIdHeaderKey];

            var regex = new Regex("TestClient=[^;]+");

            Assert.True(regex.IsMatch(traceId));
        }
Esempio n. 6
0
        public void WhenAddingTrackingInformationWithNoSpecifiedSpanIdTracing()
        {
            _apmContext.Add(Constants.IncomingTraceIdPropertyKey, "PreviousTestClient=12345");
            _apmContext.Add(Constants.ClientNamePropertyKey, "TestClient");

            ApmContext.SetTracing(_apmContext);

            var spanId = (string)_apmContext[Constants.SpanIdHeaderKey];

            var regex = new Regex("PreviousTestClient=12345;TestClient=[^;]+");

            Assert.True(regex.IsMatch(spanId));
        }
Esempio n. 7
0
        public void WhenLoggingStartOfRequest()
        {
            var apmContext = ApmContext.GetContext();

            var startActionLogged = false;

            _startAction = (context, information) =>
            {
                startActionLogged = true;
            };

            var testApmMethodHandler = new TestApmMethodHandler(apmContext, _applicationName, _startAction, _finishAction);

            testApmMethodHandler.OnActionExecuting();

            Assert.IsTrue(startActionLogged);
        }
Esempio n. 8
0
        public PingResponse Ping()
        {
            var context = ApmContext.GetContext();

            using (var client = new HttpClient(context.GetDelegatingHandler()))
            {
                client.BaseAddress = _baseUrl;
                var url      = string.Format("api/SmokeTest/Ping");
                var response = client.GetAsync(url).ConfigureAwait(false).GetAwaiter().GetResult();

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(string.Format("Ping - {0} {1} {2}", url, response.StatusCode, response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult()));
                }

                var results = Newtonsoft.Json.JsonConvert.DeserializeObject <PingResponse>(response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult());

                return(results);
            }
        }
Esempio n. 9
0
 public UsersController(ApmContext context)
 {
     this.db = context;
 }
Esempio n. 10
0
 public PointsController(ApmContext context)
 {
     this.db = context;
 }
Esempio n. 11
0
 public StatisticsController(ApmContext context)
 {
     this.db = context;
 }