Esempio n. 1
0
        public static RequestTelemetry ConvertRequestToSdkApi(Telemetry inputTelemetry)
        {
            var result = new RequestTelemetry();

            Request item = inputTelemetry.Request;

            result.Id   = item.Id;
            result.Name = item.Name;

            if (DateTimeOffset.TryParseExact(inputTelemetry.DateTime, "o", CultureInfo.InvariantCulture, DateTimeStyles.None, out var timestamp))
            {
                result.Timestamp = timestamp;
            }

            result.Duration     = item.Duration?.ToTimeSpan() ?? TimeSpan.Zero;
            result.ResponseCode = item.ResponseCode;
            result.Success      = item.Success?.Value;
            result.Source       = item.Source;

            if (Uri.TryCreate(item.Url, UriKind.RelativeOrAbsolute, out Uri url))
            {
                result.Url = url;
            }

            result.Properties.PopulateFromProtobuf(item.Properties);
            result.Metrics.PopulateFromProtobuf(item.Measurements);

            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);
            AiTelemetryConverter.CopySamplingFields(inputTelemetry, result);

            return(result);
        }
Esempio n. 2
0
        public static PageViewTelemetry ConvertPageViewToSdkApi(Telemetry inputTelemetry)
        {
            var result = new PageViewTelemetry();

            PageView item = inputTelemetry.PageView;

            item.Event = item.Event ?? new Event();

            result.Id = item.Id;

            if (Uri.TryCreate(item.Url, UriKind.RelativeOrAbsolute, out var uri))
            {
                result.Url = uri;
            }

            result.Duration = item.Duration?.ToTimeSpan() ?? TimeSpan.Zero;

            result.Name = item.Event.Name;

            result.Properties.PopulateFromProtobuf(item.Event?.Properties);
            result.Metrics.PopulateFromProtobuf(item.Event?.Measurements);

            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);
            AiTelemetryConverter.CopySamplingFields(inputTelemetry, result);

            return(result);
        }
Esempio n. 3
0
        public static AvailabilityTelemetry ConvertAvailabilityToSdkApi(Telemetry inputTelemetry)
        {
            var result = new AvailabilityTelemetry();

            Availability item = inputTelemetry.Availability;

            result.Id   = item.Id;
            result.Name = item.Name;

            if (DateTimeOffset.TryParseExact(inputTelemetry.DateTime, "o", CultureInfo.InvariantCulture, DateTimeStyles.None, out var timestamp))
            {
                result.Timestamp = timestamp;
            }

            result.Duration    = item.Duration?.ToTimeSpan() ?? TimeSpan.Zero;
            result.RunLocation = item.RunLocation;
            result.Success     = item.Success;
            result.Message     = item.Message;

            result.Properties.PopulateFromProtobuf(item.Properties);
            result.Metrics.PopulateFromProtobuf(item.Measurements);

            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);

            return(result);
        }
Esempio n. 4
0
        public static DependencyTelemetry ConvertDependencyToSdkApi(Telemetry inputTelemetry)
        {
            var result = new DependencyTelemetry();

            Dependency item = inputTelemetry.Dependency;

            result.Type   = item.Type;
            result.Target = item.Target;
            result.Name   = item.Name;
            result.Data   = item.Data;

            if (DateTimeOffset.TryParseExact(inputTelemetry.DateTime, "o", CultureInfo.InvariantCulture, DateTimeStyles.None, out var timestamp))
            {
                result.Timestamp = timestamp;
            }

            result.Duration   = item.Duration?.ToTimeSpan() ?? TimeSpan.Zero;
            result.ResultCode = item.ResultCode;
            result.Success    = item.Success?.Value ?? true;
            result.Id         = item.Id;

            result.Properties.PopulateFromProtobuf(item.Properties);
            result.Metrics.PopulateFromProtobuf(item.Measurements);

            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);
            AiTelemetryConverter.CopySamplingFields(inputTelemetry, result);

            return(result);
        }
Esempio n. 5
0
        public static EventTelemetry ConvertEventToSdkApi(Telemetry inputTelemetry)
        {
            var result = new EventTelemetry();

            result.Name = inputTelemetry.Event.Name;
            result.Properties.PopulateFromProtobuf(inputTelemetry.Event.Properties);
            result.Metrics.PopulateFromProtobuf(inputTelemetry.Event.Measurements);

            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);
            AiTelemetryConverter.CopySamplingFields(inputTelemetry, result);

            return(result);
        }
Esempio n. 6
0
        public static MetricTelemetry ConvertMetricToSdkApi(Telemetry inputTelemetry)
        {
            // only one metric in the list is currently supported by Application Insights storage. If multiple data points were sent only the first one will be used
            if (!inputTelemetry.Metric.Metrics.Any())
            {
                throw new ArgumentException("Metrics list can't be empty");
            }

            DataPoint firstMetric = inputTelemetry.Metric.Metrics[0];

            MetricTelemetry result;

            switch (firstMetric.Kind)
            {
            case DataPointType.Measurement:
                result = new MetricTelemetry(firstMetric.Name, firstMetric.Value);
                break;

            case DataPointType.Aggregation:
                firstMetric.Count = firstMetric.Count ?? new Google.Protobuf.WellKnownTypes.Int32Value()
                {
                    Value = 1
                };
                firstMetric.Min = firstMetric.Min ?? new Google.Protobuf.WellKnownTypes.DoubleValue()
                {
                    Value = firstMetric.Value
                };
                firstMetric.Max = firstMetric.Max ?? new Google.Protobuf.WellKnownTypes.DoubleValue()
                {
                    Value = firstMetric.Value
                };
                firstMetric.StdDev = firstMetric.StdDev ?? new Google.Protobuf.WellKnownTypes.DoubleValue()
                {
                    Value = 0
                };

                result = new MetricTelemetry(firstMetric.Name, firstMetric.Count.Value, firstMetric.Value, firstMetric.Min.Value, firstMetric.Max.Value, firstMetric.StdDev.Value);
                break;

            default:
                throw new ArgumentOutOfRangeException(FormattableString.Invariant($"Unknown aggregation Kind: {firstMetric.Kind}"));
            }

            result.MetricNamespace = firstMetric.Ns;

            result.Properties.PopulateFromProtobuf(inputTelemetry.Metric.Properties);

            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);

            return(result);
        }
Esempio n. 7
0
        public static TraceTelemetry ConvertTraceToSdkApi(Telemetry inputTelemetry)
        {
            var result = new TraceTelemetry();

            result.Message = inputTelemetry.Message.Message_;

            result.SeverityLevel = AiTelemetryConverter.ConvertSeverityLevel(inputTelemetry.Message.SeverityLevel);

            result.Properties.PopulateFromProtobuf(inputTelemetry.Message.Properties);

            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);
            AiTelemetryConverter.CopySamplingFields(inputTelemetry, result);

            return(result);
        }
Esempio n. 8
0
        public static ExceptionTelemetry ConvertExceptionToSdkApi(Telemetry inputTelemetry)
        {
            //!!! make sure we're onboarded onto a release version of AI SDK
            var item = inputTelemetry.Exception;

            var result = new ExceptionTelemetry(
                item.Exceptions.Select(ed => new ExceptionDetailsInfo(ed.Id, ed.OuterId, ed.TypeName, ed.Message, ed.HasFullStack?.Value ?? true, ed.Stack,
                                                                      ed.ParsedStack.Select(f => new Microsoft.ApplicationInsights.DataContracts.StackFrame(f.Assembly, f.FileName, f.Level, f.Line, f.Method)))),
                AiTelemetryConverter.ConvertSeverityLevel(item.SeverityLevel), item.ProblemId, item.Properties, item.Measurements);


            AiTelemetryConverter.CopyCommonFields(inputTelemetry, result);
            AiTelemetryConverter.CopySamplingFields(inputTelemetry, result);

            return(result);
        }