/// <summary> /// Gets the type of the item. /// </summary> /// <param name="telemetry">The dynamic object.</param> /// <returns>TelemetryItemTypes.</returns> private static TelemetryItemTypes GetItemType(AppInsightsTelemetry telemetry) { string baseType = telemetry?.Data?.BaseType; switch (baseType) { case "PageViewData": return(TelemetryItemTypes.View); case "ExceptionData": return(TelemetryItemTypes.Exception); case "MessageData": return(TelemetryItemTypes.LogMessage); case "MetricData": if (telemetry?.Tags != null && telemetry.Tags.AiOperationSyntheticSource == "HeartbeatState") { return(TelemetryItemTypes.Heartbeat); } return(TelemetryItemTypes.Metric); default: return(TelemetryItemTypes.Event); } }
private static TelemetryItem Build(AppInsightsTelemetry appInsightsTelemetry) { Dictionary <string, string> appInsightsProperties = appInsightsTelemetry.Data?.BaseData?.Properties; //bear in mind - if something goes wrong, properties might be null TelemetryItem item = new TelemetryItem() { Timestamp = appInsightsTelemetry.Time, VersionData = GetVersionData(appInsightsProperties), UserIdentifier = appInsightsTelemetry.Tags?.AiUserId, AuthenticatedUserIdentifier = appInsightsTelemetry.Tags?.AiUserAuthUserId, Properties = GetFilteredProperties(appInsightsProperties), Measurements = appInsightsTelemetry.Data?.BaseData?.Measurements, TelemetryItemType = GetItemType(appInsightsTelemetry), EntryKey = appInsightsTelemetry.Data?.BaseData?.Name ?? "MissingKey", Sequence = appInsightsTelemetry.Seq, LogMessage = appInsightsTelemetry.Data?.BaseData?.Message }; MapTelemetryKey(appInsightsProperties, item); MapLogLevel(appInsightsTelemetry, item); MapExceptionProperties(appInsightsTelemetry, item); HandleNullPropertiesError(appInsightsTelemetry, appInsightsProperties, item); return(item); }
private static void MapLogLevel(AppInsightsTelemetry appInsightsTelemetry, TelemetryItem item) { if (appInsightsTelemetry.Data.BaseData.SeverityLevel != null) { if (Enum.TryParse(appInsightsTelemetry.Data.BaseData.SeverityLevel, out SeverityLevel enumerized)) { item.LogLevel = Map(enumerized); } } }
private static void MapExceptionProperties(AppInsightsTelemetry appInsightsTelemetry, TelemetryItem item) { if (!appInsightsTelemetry.Data.BaseData.Exceptions.IsNullOrEmpty()) { item.Exceptions = new List <TelemetryItem.ExceptionInfo>(); foreach (ExceptionElement baseDataException in appInsightsTelemetry.Data.BaseData.Exceptions) { item.Exceptions.Add(Mapper.Map <TelemetryItem.ExceptionInfo>(baseDataException)); } } }
private void SetPropertiesFromConfigurationParameters() { this.ApplicationName = FabricRuntime.GetActivationContext().ApplicationName; // Observers if (int.TryParse( GetConfigSettingValue(ObserverConstants.ObserverExecutionTimeout), out int result)) { this.observerExecTimeout = TimeSpan.FromSeconds(result); } // Loggers if (bool.TryParse( GetConfigSettingValue(ObserverConstants.EnableVerboseLoggingParameter), out bool enableVerboseLogging)) { this.Logger.EnableVerboseLogging = enableVerboseLogging; } if (int.TryParse( GetConfigSettingValue(ObserverConstants.ObserverLoopSleepTimeSeconds), out int execFrequency)) { ObserverExecutionLoopSleepSeconds = execFrequency; this.Logger.LogInfo($"ExecutionFrequency is {ObserverExecutionLoopSleepSeconds} Seconds"); } // Shutdown if (int.TryParse( GetConfigSettingValue(ObserverConstants.ObserverShutdownGracePeriodInSeconds), out int shutdownGracePeriodInSeconds)) { this.shutdownGracePeriodInSeconds = shutdownGracePeriodInSeconds; } // (Assuming Diagnostics/Analytics cloud service implemented) Telemetry. if (bool.TryParse(GetConfigSettingValue(ObserverConstants.TelemetryEnabled), out bool telemEnabled)) { TelemetryEnabled = telemEnabled; } if (TelemetryEnabled) { string key = GetConfigSettingValue(ObserverConstants.AIKey); if (!string.IsNullOrEmpty(key)) { TelemetryClient = new AppInsightsTelemetry(key); } } }
private static void HandleNullPropertiesError(AppInsightsTelemetry appInsightsTelemetry , Dictionary <string, string> appInsightsProperties, TelemetryItem item) { if (appInsightsProperties == null) { item.TelemetryItemType = TelemetryItemTypes.Exception; item.Exceptions = new List <TelemetryItem.ExceptionInfo>(); item.Exceptions.Add(new TelemetryItem.ExceptionInfo() { Message = appInsightsTelemetry.Data?.BaseData?.Message , HasFullStack = false, Id = 0, OuterId = 0, ParsedStack = new List <TelemetryItem.ExceptionInfo.ParsedStackTrace>(), TypeName = "TelimenaClientInternalError" }); } }
public static void RegisterContainer() { var builder = new ContainerBuilder(); var httpContext = ConfigurationManager.AppSettings["HttpServiceUrl"]; builder.RegisterType <PersonController>() .WithParameter(new TypedParameter(typeof(string), httpContext)) .InstancePerRequest(); builder.RegisterType <Service>() .AsSelf(); var telemetry = new AppInsightsTelemetry(); builder.RegisterInstance(telemetry) .As <ITelemetry>() .SingleInstance(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
private void SetPropertiesFromConfigurationParameters() { this.ApplicationName = FabricRuntime.GetActivationContext().ApplicationName; // Observers if (int.TryParse( GetConfigSettingValue(ObserverConstants.ObserverExecutionTimeout), out int result)) { this.observerExecTimeout = TimeSpan.FromSeconds(result); } // Loggers if (bool.TryParse( GetConfigSettingValue(ObserverConstants.EnableVerboseLoggingParameter), out bool enableVerboseLogging)) { this.Logger.EnableVerboseLogging = enableVerboseLogging; } if (int.TryParse( GetConfigSettingValue(ObserverConstants.ObserverLoopSleepTimeSeconds), out int execFrequency)) { ObserverExecutionLoopSleepSeconds = execFrequency; this.Logger.LogInfo($"ExecutionFrequency is {ObserverExecutionLoopSleepSeconds} Seconds"); } if (bool.TryParse( GetConfigSettingValue(ObserverConstants.EnableLongRunningCSVLogging), out bool enableCSVLogging)) { this.DataLogger.EnableCsvLogging = enableCSVLogging; } string dataLogPath = GetConfigSettingValue(ObserverConstants.DataLogPath); if (!string.IsNullOrEmpty(dataLogPath)) { this.DataLogger.DataLogFolderPath = dataLogPath; } // Shutdown if (int.TryParse( GetConfigSettingValue(ObserverConstants.ObserverShutdownGracePeriodInSeconds), out int shutdownGracePeriodInSeconds)) { this.shutdownGracePeriodInSeconds = shutdownGracePeriodInSeconds; } // FQDN for use in warning or error hyperlinks in HTML output // This only makes sense when you have the FabricObserverWebApi app installed. string fqdn = GetConfigSettingValue(ObserverConstants.FQDN); if (!string.IsNullOrEmpty(fqdn)) { this.Fqdn = fqdn; } // (Assuming Diagnostics/Analytics cloud service implemented) Telemetry. if (bool.TryParse(GetConfigSettingValue(ObserverConstants.TelemetryEnabled), out bool telemEnabled)) { TelemetryEnabled = telemEnabled; } if (TelemetryEnabled) { string key = GetConfigSettingValue(ObserverConstants.AIKey); if (!string.IsNullOrEmpty(key)) { TelemetryClient = new AppInsightsTelemetry(key); } } // FabricObserver runtime telemetry (Non-PII) if (bool.TryParse(GetConfigSettingValue(ObserverConstants.FabricObserverTelemetryEnabled), out bool foTelemEnabled)) { FabricObserverInternalTelemetryEnabled = foTelemEnabled; } // ObserverWebApi. if (bool.TryParse(GetConfigSettingValue(ObserverConstants.ObserverWebApiAppDeployed), out bool obsWeb)) { ObserverWebAppDeployed = obsWeb; } else { ObserverWebAppDeployed = IsObserverWebApiAppInstalled(); } }