示例#1
0
        public void Match_WithCorrectPattern_ShouldSuccess()
        {
            var path = "http://localhost:5001/api/values";

            var pattern = "http://localhost:5001/api/values";
            var result  = FastPathMatcher.Match(pattern, path);

            Assert.True(result);

            pattern = "*//localhost:5001/api/values";
            result  = FastPathMatcher.Match(pattern, path);
            Assert.True(result);

            pattern = "**/localhost:5001/api/values";
            result  = FastPathMatcher.Match(pattern, path);
            Assert.True(result);

            pattern = "**/localhost:5001/**";
            result  = FastPathMatcher.Match(pattern, path);
            Assert.True(result);

            pattern = "**localhost:5001**";
            result  = FastPathMatcher.Match(pattern, path);
            Assert.True(result);
        }
示例#2
0
        public void Handle(ITracingContext tracingContext, HttpRequestMessage request)
        {
            var operationName         = request.RequestUri.GetLeftPart(UriPartial.Path);
            var shouldStopPropagation = _httpClientDiagnosticConfig.StopHeaderPropagationPaths != null &&
                                        _httpClientDiagnosticConfig.StopHeaderPropagationPaths
                                        .Any(pattern => FastPathMatcher.Match(pattern, operationName));

            var context = tracingContext.CreateExitSegmentContext(operationName,
                                                                  $"{request.RequestUri.Host}:{request.RequestUri.Port}",
                                                                  shouldStopPropagation ? null : new HttpClientICarrierHeaderCollection(request));

            context.Span.SpanLayer = SpanLayer.HTTP;
            context.Span.Component = Common.Components.HTTPCLIENT;
            context.Span.AddTag(Tags.URL, request.RequestUri.ToString());
            context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString());
        }
        public bool Invoke(SamplingContext samplingContext, Sampler next)
        {
            if (!_sample_on)
            {
                return(next(samplingContext));
            }

            foreach (var pattern in _ignorePaths)
            {
                if (FastPathMatcher.Match(pattern, samplingContext.OperationName))
                {
                    return(false);
                }
            }

            return(next(samplingContext));
        }
示例#4
0
        public void Handle(ITracingContext tracingContext, HttpRequestMessage request)
        {
            var operationName = request.RequestUri.GetLeftPart(UriPartial.Path);

            var ignored = _httpClientDiagnosticConfig.IgnorePaths != null &&
                          _httpClientDiagnosticConfig.IgnorePaths
                          .Any(pattern => FastPathMatcher.Match(pattern, operationName));

            if (ignored)
            {
                return;
            }

            var shouldStopPropagation = _httpClientDiagnosticConfig.StopHeaderPropagationPaths != null &&
                                        _httpClientDiagnosticConfig.StopHeaderPropagationPaths
                                        .Any(pattern => FastPathMatcher.Match(pattern, operationName));

            var context = tracingContext.CreateExitSegmentContext(operationName,
                                                                  $"{request.RequestUri.Host}:{request.RequestUri.Port}",
                                                                  shouldStopPropagation ? null : new HttpClientICarrierHeaderCollection(request));

            context.Span.SpanLayer = SpanLayer.HTTP;
            context.Span.Component = Common.Components.HTTPCLIENT;
            context.Span.AddTag(Tags.URL, request.RequestUri.ToString());
            context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString());

            if (_httpClientDiagnosticConfig.CollectRequestHeaders?.Count > 0)
            {
                var headers = CollectHeaders(request, _httpClientDiagnosticConfig.CollectRequestHeaders);
                if (!string.IsNullOrEmpty(headers))
                {
                    context.Span.AddTag(Tags.HTTP_HEADERS, headers);
                }
            }

            if (request.Content != null && _httpClientDiagnosticConfig.CollectRequestBodyContentTypes?.Count > 0)
            {
                var requestBody = request.Content.TryCollectAsString(
                    _httpClientDiagnosticConfig.CollectRequestBodyContentTypes,
                    _httpClientDiagnosticConfig.CollectBodyLengthThreshold);
                if (!string.IsNullOrEmpty(requestBody))
                {
                    context.Span.AddTag(Tags.HTTP_REQUEST_BODY, requestBody);
                }
            }
        }
示例#5
0
        public void Match_WithWrongPattern_ShouldFail()
        {
            var path = "http://localhost:5001/api/values";

            var pattern = "localhost:5001/api/values";
            var result  = FastPathMatcher.Match(pattern, path);

            Assert.False(result);

            pattern = "//localhost:5001/api/values";
            result  = FastPathMatcher.Match(pattern, path);
            Assert.False(result);

            pattern = "*localhost:5001/api/values";
            result  = FastPathMatcher.Match(pattern, path);
            Assert.False(result);

            pattern = "**/LOCALHOST:5001/**";
            result  = FastPathMatcher.Match(pattern, path);
            Assert.False(result);
        }