public static void EmitException(string className, string methodName, Exception exception) { if (className == null) { throw new ArgumentNullException(nameof(className)); } if (methodName == null) { throw new ArgumentNullException(nameof(methodName)); } if (exception == null) { throw new ArgumentNullException(nameof(exception)); } TelemetryEvent ToTelemetryEvent(Exception e, string name) { TelemetryEvent te = new TelemetryEvent(name); te["Message"] = e.Message; te["ExceptionType"] = e.GetType().FullName; te["StackTrace"] = e.StackTrace; if (e is AggregateException aggregateException) { var exceptions = aggregateException.InnerExceptions .Select(ie => ToTelemetryEvent(ie, name: null)) .ToList(); te.ComplexData["InnerExceptions"] = exceptions; } else if (e.InnerException != null) { var inner = ToTelemetryEvent(e.InnerException, name: null); te.ComplexData["InnerException"] = inner; } return(te); } TelemetryEvent telemetryEvent = ToTelemetryEvent(exception, $"errors/{className}.{methodName}"); TelemetryActivity.EmitTelemetryEvent(telemetryEvent); }
public static VsTelemetryEvent ToVsTelemetryEvent(TelemetryEvent telemetryEvent) { if (telemetryEvent == null) { throw new ArgumentNullException(nameof(telemetryEvent)); } var vsTelemetryEvent = new VsTelemetryEvent(VSEventNamePrefix + telemetryEvent.Name); foreach (var pair in telemetryEvent) { vsTelemetryEvent.Properties[VSPropertyNamePrefix + pair.Key] = pair.Value; } foreach (var pair in telemetryEvent.GetPiiData()) { vsTelemetryEvent.Properties[VSPropertyNamePrefix + pair.Key] = new VsTelemetryPiiProperty(pair.Value); } return(vsTelemetryEvent); }
internal static async Task <TelemetryEvent> ToTelemetryAsync(Data data, SourceRepository sourceRepository, string parentId, string actionName, PackageSourceMapping packageSourceMappingConfiguration) { if (data.Resources.Count == 0) { return(null); } FeedType feedType = await sourceRepository.GetFeedType(CancellationToken.None); TelemetryEvent telemetry; lock (data._lock) { bool isPackageSourceMappingEnabled = packageSourceMappingConfiguration?.IsEnabled ?? false; telemetry = new TelemetryEvent(EventName, new Dictionary <string, object>() { { PropertyNames.ParentId, parentId }, { PropertyNames.Action, actionName }, { PropertyNames.PackageSourceMapping.IsMappingEnabled, isPackageSourceMappingEnabled } }); AddSourceProperties(telemetry, sourceRepository, feedType); telemetry[PropertyNames.Duration.Total] = data.Resources.Values.Sum(r => r.duration.TotalMilliseconds); telemetry[PropertyNames.Nupkgs.Copied] = data.NupkgCount; telemetry[PropertyNames.Nupkgs.Bytes] = data.NupkgSize; AddResourceProperties(telemetry, data.Resources); if (data.Http.Requests > 0) { AddHttpProperties(telemetry, data.Http); } } return(telemetry); }
private static void AddResourceProperties(TelemetryEvent telemetry, Dictionary <string, (int count, TimeSpan duration)> resources)
public void PostEvent(TelemetryEvent telemetryEvent) { VsTelemetryService.DefaultSession.PostEvent(ToVsTelemetryEvent(telemetryEvent)); }
public void EmitEvent(TelemetryEvent telemetryEvent) { TelemetryActivity.EmitTelemetryEvent(telemetryEvent); }