public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules) { configuration.TelemetryInitializers.Add(new SdkVersionPropertyTelemetryInitializer()); #if !CORE_PCL configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer()); #endif // Load customizations from the ApplicationsInsights.config file string text = PlatformSingleton.Current.ReadConfigurationXml(); if (!string.IsNullOrEmpty(text)) { XDocument xml = XDocument.Parse(text); LoadFromXml(configuration, modules, xml); } // Creating the default channel if no channel configuration supplied configuration.TelemetryChannel = configuration.TelemetryChannel ?? new InMemoryChannel(); // Creating the the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.GetTelemetryProcessorChainBuilder().Build(); } InitializeComponents(configuration, modules); }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules, string serializedConfiguration) { configuration.TelemetryInitializers.Add(new SdkVersionPropertyTelemetryInitializer()); #if !CORE_PCL configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer()); #endif // Load configuration from the specified configuration if (!string.IsNullOrEmpty(serializedConfiguration)) { XDocument xml = XDocument.Parse(serializedConfiguration); LoadFromXml(configuration, modules, xml); } // Creating the default channel if no channel configuration supplied configuration.TelemetryChannel = configuration.TelemetryChannel ?? new InMemoryChannel(); // Creating the the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.TelemetryProcessorChainBuilder.Build(); } InitializeComponents(configuration, modules); }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules, string serializedConfiguration) { try { SdkInternalOperationsMonitor.Enter(); if (modules != null && !modules.Modules.Any(module => module is DiagnosticsTelemetryModule)) { // Create diagnostics module so configuration loading errors are reported to the portal modules.Modules.Add(new DiagnosticsTelemetryModule()); } configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer()); // Load configuration from the specified configuration if (!string.IsNullOrEmpty(serializedConfiguration)) { try { XDocument xml = XDocument.Parse(serializedConfiguration); LoadFromXml(configuration, modules, xml); } catch (XmlException exp) { CoreEventSource.Log.ConfigurationFileCouldNotBeParsedError(exp.Message); } } // If an environment variable exists with an instrumentation key then use it (instead) for the "blackfield" scenario. string environmentInstrumentationKey = PlatformSingleton.Current.GetEnvironmentVariable(InstrumentationKeyWebSitesEnvironmentVariable); if (!string.IsNullOrEmpty(environmentInstrumentationKey)) { configuration.InstrumentationKey = environmentInstrumentationKey; } // Creating the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.TelemetryProcessorChainBuilder.Build(); } foreach (var telemetrySink in configuration.TelemetrySinks) { telemetrySink.Initialize(configuration); if (telemetrySink.TelemetryProcessorChain == null) { telemetrySink.TelemetryProcessorChainBuilder.Build(); } } InitializeComponents(configuration, modules); } finally { SdkInternalOperationsMonitor.Exit(); } }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules, string serializedConfiguration) { try { SdkInternalOperationsMonitor.Enter(); if (modules != null && !modules.Modules.Any(module => module is DiagnosticsTelemetryModule)) { // Create diagnostics module so configuration loading errors are reported to the portal modules.Modules.Add(new DiagnosticsTelemetryModule()); } configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer()); // Load configuration from the specified configuration if (!string.IsNullOrEmpty(serializedConfiguration)) { try { XDocument xml = XDocument.Parse(serializedConfiguration); LoadFromXml(configuration, modules, xml); } catch (XmlException exp) { CoreEventSource.Log.ConfigurationFileCouldNotBeParsedError(exp.Message); } } // Creating the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.TelemetryProcessorChainBuilder.Build(); } foreach (var telemetrySink in configuration.TelemetrySinks) { telemetrySink.Initialize(configuration); if (telemetrySink.TelemetryProcessorChain == null) { telemetrySink.TelemetryProcessorChainBuilder.Build(); } } this.SelectInstrumentationKey(configuration); InitializeComponents(configuration, modules); } finally { SdkInternalOperationsMonitor.Exit(); } }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules, string serializedConfiguration) { if (modules != null) { // Create diagnostics module so configuration loading errors are reported to the portal modules.Modules.Add(new DiagnosticsTelemetryModule()); } #if !CORE_PCL configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer()); #endif // Load configuration from the specified configuration if (!string.IsNullOrEmpty(serializedConfiguration)) { try { XDocument xml = XDocument.Parse(serializedConfiguration); LoadFromXml(configuration, modules, xml); } catch (XmlException exp) { CoreEventSource.Log.ConfigurationFileCouldNotBeParsedError(exp.Message); } } // If no instrumentation key is found, try to fall back to an environment variable (for blackfield scenario) if (string.IsNullOrEmpty(configuration.InstrumentationKey)) { configuration.InstrumentationKey = PlatformSingleton.Current.GetEnvironmentVariable(InstrumentationKeyWebSitesEnvironmentVariable) ?? string.Empty; } // Creating the default channel if no channel configuration supplied configuration.TelemetryChannel = configuration.TelemetryChannel ?? new InMemoryChannel(); // Creating the the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.TelemetryProcessorChainBuilder.Build(); } InitializeComponents(configuration, modules); }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules = null) { configuration.TelemetryInitializers.Add(new SdkVersionPropertyTelemetryInitializer()); // Load customizations from the ApplicationsInsights.config file string text = PlatformSingleton.Current.ReadConfigurationXml(); string instrumentationKey = this.GetInstrumentationKeyFromConfigFile(text); if (!string.IsNullOrEmpty(instrumentationKey)) { configuration.InstrumentationKey = instrumentationKey; } // Creating the default channel if no channel configuration supplied configuration.TelemetryChannel = configuration.TelemetryChannel ?? new InMemoryChannel(); // Creating the the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.GetTelemetryProcessorChainBuilder().Build(); } }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules = null) { configuration.TelemetryInitializers.Add(new SdkVersionPropertyTelemetryInitializer()); // Load customizations from the ApplicationsInsights.config file string text = PlatformSingleton.Current.ReadConfigurationXml(); string instrumentationKey = this.GetInstrumentationKeyFromConfigFile(text); if (!string.IsNullOrEmpty(instrumentationKey)) { configuration.InstrumentationKey = instrumentationKey; } // Creating the default channel if no channel configuration supplied configuration.TelemetryChannel = configuration.TelemetryChannel ?? new InMemoryChannel(); // Creating the the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.GetTelemetryProcessorChainBuilder().Build(); } }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules, string serializedConfiguration) { if (modules != null) { // Create diagnostics module so configuration loading errors are reported to the portal modules.Modules.Add(new DiagnosticsTelemetryModule()); } #if !CORE_PCL configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer()); #endif // Load configuration from the specified configuration if (!string.IsNullOrEmpty(serializedConfiguration)) { try { XDocument xml = XDocument.Parse(serializedConfiguration); LoadFromXml(configuration, modules, xml); } catch (XmlException exp) { CoreEventSource.Log.ConfigurationFileCouldNotBeParsedError(exp.Message); } } // Creating the default channel if no channel configuration supplied configuration.TelemetryChannel = configuration.TelemetryChannel ?? new InMemoryChannel(); // Creating the the processor chain with default processor (transmissionprocessor) if none configured if (configuration.TelemetryProcessors == null) { configuration.TelemetryProcessorChainBuilder.Build(); } InitializeComponents(configuration, modules); }
public static object LoadInstance(XElement definition, Type expectedType, object instance, TelemetryModules modules) { return(TelemetryConfigurationFactory.LoadInstance(definition, expectedType, instance, null, modules)); }
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules) { // Load customizations from the ApplicationsInsights.config file this.Initialize(configuration, modules, PlatformSingleton.Current.ReadConfigurationXml()); }
public static new void LoadFromXml(TelemetryConfiguration configuration, TelemetryModules modules, XDocument xml) { TelemetryConfigurationFactory.LoadFromXml(configuration, modules, xml); }
private static void InitializeComponents(TelemetryConfiguration configuration, TelemetryModules modules) { InitializeComponent(configuration.TelemetryChannel, configuration); InitializeComponents(configuration.TelemetryInitializers, configuration); InitializeComponents(configuration.TelemetryProcessorChain.TelemetryProcessors, configuration); if (modules != null) { InitializeComponents(modules.Modules, configuration); } }
public override void Initialize(TelemetryConfiguration configuration, TelemetryModules modules) { this.OnInitialize(configuration, modules); }
protected static void LoadInstances <T>(XElement definition, ICollection <T> instances, TelemetryModules modules) { if (definition != null) { foreach (XElement addElement in definition.Elements(XmlNamespace + AddElementName)) { object instance = null; XAttribute typeName = addElement.Attribute(TypeAttributeName); if (typeName != null) { // It is possible that configuration item of that type is already initialized, in that case we don't need to create it again. Type type = GetType(typeName.Value); instance = instances.FirstOrDefault(i => i.GetType() == type); } bool isNewInstance = instance == null; instance = LoadInstance(addElement, typeof(T), instance, null, modules); if (isNewInstance) { instances.Add((T)instance); } } } }
protected static void LoadProperties(XElement instanceDefinition, object instance, TelemetryModules modules) { List <XElement> propertyDefinitions = GetPropertyDefinitions(instanceDefinition).ToList(); if (propertyDefinitions.Count > 0) { Type instanceType = instance.GetType(); Dictionary <string, PropertyInfo> properties = instanceType.GetProperties().ToDictionary(p => p.Name); foreach (XElement propertyDefinition in propertyDefinitions) { string propertyName = propertyDefinition.Name.LocalName; PropertyInfo property; if (properties.TryGetValue(propertyName, out property)) { if (propertyName == "TelemetryProcessors") { BuildTelemetryProcessorChain(propertyDefinition, (TelemetryConfiguration)instance); } else { object propertyValue = property.GetValue(instance, null); propertyValue = LoadInstance(propertyDefinition, property.PropertyType, propertyValue, null, modules); if (property.CanWrite) { property.SetValue(instance, propertyValue, null); } } } else if (modules != null && propertyName == "TelemetryModules") { LoadInstance(propertyDefinition, modules.Modules.GetType(), modules.Modules, null, modules); } else if (instance is TelemetryConfiguration) { continue; // because Status Monitor, VS Tooling can define their own configuration sections we don't care about here. } else { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, "'{0}' is not a valid property name for type {1}.", propertyName, instanceType.AssemblyQualifiedName)); } } } }
protected static object LoadInstance(XElement definition, Type expectedType, object instance, object[] constructorArgs, TelemetryModules modules) { if (definition != null) { XAttribute typeName = definition.Attribute(TypeAttributeName); if (typeName != null) { // Type attribute is specified, instantiate a new object of that type // If configuration instance is already created with the correct type, don't create it just load its properties if (instance == null || instance.GetType() != GetType(typeName.Value)) { // Type specified, create a new instance instance = CreateInstance(expectedType, typeName.Value, constructorArgs); } } else if (!definition.Elements().Any() && !definition.Attributes().Any()) { // Type attribute is not specified and no child elements or attributes exist, so this must be a scalar value LoadInstanceFromValue(definition, expectedType, ref instance); } else if (instance == null && !expectedType.IsAbstract()) { instance = Activator.CreateInstance(expectedType); } else if (instance == null) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, "'{0}' element does not have a Type attribute, does not specify a value and is not a valid collection type", definition.Name.LocalName)); } if (instance != null) { LoadProperties(definition, instance, modules); Type elementType; if (GetCollectionElementType(instance.GetType(), out elementType)) { MethodInfo genericLoadInstances = LoadInstancesDefinition.MakeGenericMethod(elementType); genericLoadInstances.Invoke(null, new[] { definition, instance, modules }); } } } return(instance); }
protected static object LoadInstance(XElement definition, Type expectedType, object instance, object[] constructorArgs, TelemetryModules modules) { if (definition != null) { XAttribute typeName = definition.Attribute(TypeAttributeName); if (typeName != null) { // Type attribute is specified, instantiate a new object of that type // If configuration instance is already created with the correct type, don't create it just load its properties if (instance == null || instance.GetType() != GetType(typeName.Value)) { // Type specified, create a new instance instance = CreateInstance(expectedType, typeName.Value, constructorArgs); } } else if (!definition.Elements().Any() && !definition.Attributes().Any() && constructorArgs == null) { // Neither type attribute nor constructor args are specified, and no child elements or attributes exist, so this must be a scalar value. LoadInstanceFromValue(definition, expectedType, ref instance); } else if (instance == null && !expectedType.IsAbstract()) { instance = constructorArgs != null?Activator.CreateInstance(expectedType, constructorArgs) : Activator.CreateInstance(expectedType); } else if (instance == null) { CoreEventSource.Log.IncorrectInstanceAtributesConfigurationError(definition.Name.LocalName); } if (instance != null) { LoadProperties(definition, instance, modules); Type elementType; if (GetCollectionElementType(instance.GetType(), out elementType)) { MethodInfo genericLoadInstances = LoadInstancesDefinition.MakeGenericMethod(elementType); genericLoadInstances.Invoke(null, new[] { definition, instance, modules }); } } } return(instance); }
public static new void LoadInstances <T>(XElement definition, ICollection <T> instances, TelemetryModules modules) { TelemetryConfigurationFactory.LoadInstances(definition, instances, modules); }
protected static void LoadProperties(XElement instanceDefinition, object instance, TelemetryModules modules) { List <XElement> propertyDefinitions = GetPropertyDefinitions(instanceDefinition).ToList(); if (propertyDefinitions.Count > 0) { Type instanceType = instance.GetType(); Dictionary <string, PropertyInfo> properties = instanceType.GetProperties().ToDictionary(p => p.Name); foreach (XElement propertyDefinition in propertyDefinitions) { string propertyName = propertyDefinition.Name.LocalName; PropertyInfo property; if (properties.TryGetValue(propertyName, out property)) { if (propertyName == "TelemetryProcessors") { TelemetryProcessorChainBuilder builder = (instance as TelemetryConfiguration)?.TelemetryProcessorChainBuilder ?? (instance as TelemetrySink)?.TelemetryProcessorChainBuilder; if (builder != null) { BuildTelemetryProcessorChain(propertyDefinition, builder); } } else if (propertyName == "TelemetrySinks") { LoadTelemetrySinks(propertyDefinition, (TelemetryConfiguration)instance); } else { object propertyValue = property.GetValue(instance, null); propertyValue = LoadInstance(propertyDefinition, property.PropertyType, propertyValue, null, modules); if (propertyValue != null && property.CanWrite) { property.SetValue(instance, propertyValue, null); } } } else if (modules != null && propertyName == "TelemetryModules") { LoadInstance(propertyDefinition, modules.Modules.GetType(), modules.Modules, null, modules); } else if (instance is TelemetryConfiguration) { continue; // because Status Monitor, VS Tooling can define their own configuration sections we don't care about here. } else { CoreEventSource.Log.IncorrectPropertyConfigurationError(instanceType.AssemblyQualifiedName, propertyName); } } } }
protected static void LoadInstances <T>(XElement definition, ICollection <T> instances, TelemetryModules modules) { // This method is invoked through reflection. Do not delete. if (definition != null) { foreach (XElement addElement in definition.Elements(XmlNamespace + AddElementName)) { object instance = null; XAttribute typeName = addElement.Attribute(TypeAttributeName); if (typeName != null) { // It is possible that configuration item of that type is already initialized, in that case we don't need to create it again. Type type = GetType(typeName.Value); instance = instances.FirstOrDefault(i => i.GetType() == type); } if (instance == null) { instance = LoadInstance(addElement, typeof(T), instance, null, modules); if (instance != null) { instances.Add((T)instance); } } else { // Apply configuration overrides to element created in code LoadProperties(addElement, instance, null); } } } }
public static new void LoadProperties(XElement definition, object instance, TelemetryModules modules) { TelemetryConfigurationFactory.LoadProperties(definition, instance, modules); }
protected static void LoadFromXml(TelemetryConfiguration configuration, TelemetryModules modules, XDocument xml) { XElement applicationInsights = xml.Element(XmlNamespace + "ApplicationInsights"); LoadInstance(applicationInsights, typeof(TelemetryConfiguration), configuration, null, modules); }