Example #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);
        }
Example #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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }