protected override void OnInitializeTelemetry(
            HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
        {
            var httpContext = platformContext.Request.HttpContext;
            var options     = OptionsMonitor.CurrentValue;

            if (!(httpContext.Items[HttpContextProblemItemKey] is MvcProblemDetails problem))
            {
                return;
            }

            if (httpContext.Items[HttpContextIsFailureItemKey] is bool isFailure)
            {
                requestTelemetry.Success = !isFailure;
            }


            if (!options.ShouldSend(httpContext, problem))
            {
                return;
            }

            var choices = new DimensionChoices
            {
                IncludeErrorsValue     = options.IncludeErrorsValue(httpContext, problem),
                IncludeExtensionsValue = options.IncludeExtensionsValue(httpContext, problem),
                IncludeRawJson         = options.IncludeRawJson(httpContext, problem)
            };

            var candidateDimensions = new Dictionary <string, string>();

            DimensionCollector.CollectDimensions(candidateDimensions, problem, httpContext, choices);
            var dimensions = options.MapDimensions(httpContext, problem, candidateDimensions);

            if (dimensions == null)
            {
                return;
            }

            foreach (var(key, value) in dimensions)
            {
                requestTelemetry.Properties[key] = value;
            }
        }
Beispiel #2
0
        public virtual void CollectDimensions(
            IDictionary <string, string> dimensions,
            MvcProblemDetails problem,
            HttpContext httpContext,
            DimensionChoices choices)
        {
            CollectionStandardDimensions(dimensions, problem, httpContext);

            if (problem is ValidationProblemDetails validationProblem && choices.IncludeErrorsValue)
            {
                CollectValidationErrorDimensions(dimensions, validationProblem, httpContext);
            }

            if (choices.IncludeExtensionsValue)
            {
                CollectExtensionDimensions(dimensions, problem, httpContext);
            }

            if (choices.IncludeRawJson)
            {
                CollectionRawProblemDimension(dimensions, problem, httpContext);
            }
        }