2
votes

I'm building a small library that use Application Insights.

Is there a possibility Application Insights working without ApplicationInsights.config file?

I tried remove and add the modules manually at constructor, but it didn't work.

Edited

I did something like that:

dependencies = new DependencyTrackingTelemetryModule();
dependencies.Initialize(configuration);

exceptionTelemetryModule = new UnhandledExceptionTelemetryModule();
exceptionTelemetryModule.Initialize(configuration);

unobservedExceptionTelemetry = new UnobservedExceptionTelemetryModule();
unobservedExceptionTelemetry.Initialize(configuration);

serverTelemetryChannel = new ServerTelemetryChannel();
serverTelemetryChannel.DeveloperMode = true;
serverTelemetryChannel.Initialize(configuration);

azureInstanceMetadataTelemetry = new AzureInstanceMetadataTelemetryModule();
azureInstanceMetadataTelemetry.Initialize(configuration);

var developer = new DeveloperModeWithDebuggerAttachedTelemetryModule();
developer.Initialize(configuration);

configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());

client = new TelemetryClient(configuration);
1
Absolutely, it is possible. Can you post what you have got so far as a starting point? - Peter Bons
@PeterBons I edited my post, with code that I tried - novac
And you are using this client throughout your codebase? - Peter Bons

1 Answers

3
votes

A minimalistic setup can be done like this.

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DependencyCollector;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;

.. .. ..

  private static void setupApplicationInsights()
    {
        // Setup Channel, Initializers, and Sampling
        // Nugets Required: "Microsoft.ApplicationInsights", "Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel"

        var channel = new ServerTelemetryChannel();            
        var config = TelemetryConfiguration.Active;
        config.InstrumentationKey = "putikey"; 

        channel.Initialize(config);
        TelemetryConfiguration.Active.TelemetryChannel = channel;

        //Setup TelemetryInitializers...
        config.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());

        //Setup Sampling
        config.TelemetryProcessorChainBuilder.UseAdaptiveSampling();

        // Setup modules...
        // Nugets : Microsoft.ApplicationInsights.DependencyCollector
        DependencyTrackingTelemetryModule dep = new DependencyTrackingTelemetryModule();
        dep.Initialize(config);

    }