I dont know if it’s posssible to create full TelemetryConfiguration without applicationInsight.config
I see there are TelemetryInitializers.Add it working well
but nothing for the configs
- TelemetryModules (present in config file but not on the class)
- DefaultTelemetrySink.TelemetryProcessors (present in the config file but there are no Add method in the class)
I serarched everywhere for an example of complete configuration via code but did not find anything. I want to get rid of the config file, because I want to use the TelemetryConfiguration in a common library. And don’t want to pupulate many config files in end up librairies.
I looking in debug mode and seen many differences between class obtained with TelemetryConfiguration.CreateDefault() when I have the config file obtained from nuget package, and the one obtained when I have no config file. This is the reason of my question.
what I have sofar
internal class ApplicationInsightConfig
{
public TelemetryConfiguration Config { get; }
public ApplicationInsightConfig()
{
Config = TelemetryConfiguration.CreateDefault();
Config.InstrumentationKey = ConfigurationManager.GetSetting(new ConfigKey("ApplicationInsightKey"));
Config.ApplicationIdProvider = new ApplicationInsightsApplicationIdProvider();
Config.TelemetryChannel.DeveloperMode = false;
DefineTelemetryInitializers();
DefineDefaultTelemetrySink();
}
private void DefineDefaultTelemetrySink()
{
var tp = Config.DefaultTelemetrySink.TelemetryProcessors;
Config.DefaultTelemetrySink.TelemetryChannel = new ServerTelemetryChannel();
}
private void DefineTelemetryInitializers()
{
Config.TelemetryInitializers.Add(new AzureAppServiceRoleNameFromHostNameHeaderInitializer());
Config.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
Config.TelemetryInitializers.Add(new AzureRoleEnvironmentTelemetryInitializer());
Config.TelemetryInitializers.Add(new BuildInfoConfigComponentVersionTelemetryInitializer());
Config.TelemetryInitializers.Add(new WebTestTelemetryInitializer());
Config.TelemetryInitializers.Add(new SyntheticUserAgentTelemetryInitializer { Filters = "search|spider|crawl|Bot|Monitor|AlwaysOn" });
Config.TelemetryInitializers.Add(new ClientIpHeaderTelemetryInitializer());
Config.TelemetryInitializers.Add(new OperationNameTelemetryInitializer());
Config.TelemetryInitializers.Add(new UserTelemetryInitializer());
Config.TelemetryInitializers.Add(new AuthenticatedUserIdTelemetryInitializer());
Config.TelemetryInitializers.Add(new AccountIdTelemetryInitializer());
Config.TelemetryInitializers.Add(new SessionTelemetryInitializer());
}
}
Thank you for help!
2
Answers
For those how want te final version here is the code :
I think you are on the right track. Setting the telemetry channel could be done slightly different:
Telemetry modules all implement
ITelemetryModule
, which defines avoid Initialize(TelemetryConfiguration configuration)
method to wire up the module:Telemetry processors can be added using the
TelemetryProcessorChainBuilder
:Then the final step is to use the config: