private void ConfigureLogging(IServiceCollection services) { if (!GlobalTracer.IsRegistered()) { var key = configuration.GetSection("ApplicationInsights").GetSection("InstrumentationKey").Value; var config = new TelemetryConfiguration { InstrumentationKey = key }; var tracer = new ApplicationInsightsTracer(config); GlobalTracer.Register(tracer); // The tracer itself is a single instance during the durantion of the whole request. // Specifying the type here is option since it could decipher it, but adding it for explicity services.AddSingleton <OpenTracing.ITracer>(tracer); // Scoped services are created per client request services.AddScoped <ICustomLogger, CustomLogger>(); } }
private static void Main(string[] args) { var appId = Environment.GetEnvironmentVariable("APP_INSIGHTS_INSTRUMENTATION_KEY"); if (string.IsNullOrEmpty(appId)) { Console.WriteLine("Unable to read environment variable [APP_INSIGHTS_APPID]."); Console.WriteLine("Please set this value equal to your Application Insights AppId"); return; } var config = new TelemetryConfiguration(appId); var actorSystem = ActorSystem.Create("MySys"); var tracer = new ApplicationInsightsTracer(config); var loggingActor = actorSystem.ActorOf(Props.Create(() => new TracerActor(tracer))); tracer.Client.TrackRequest("start app", DateTimeOffset.Now, TimeSpan.FromSeconds(1), "200", true); Console.WriteLine("Press enter at any time to end this sample."); Console.ReadLine(); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); }) .ConfigureServices(s => { s.AddSingleton <ITracer>(sp => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = sp.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(true); var telemetryConfig = new TelemetryConfiguration("eb9eab65-f8b2-4af5-9c4c-1fc7912b8ac3"); var builder = telemetryConfig.TelemetryProcessorChainBuilder; builder.Use((next) => new AppinsightsOpenTracingInterceptor(next)); builder.Build(); ApplicationInsightsTracer tracer = new ApplicationInsightsTracer(telemetryConfig); //ITracer tracer = new Tracer.Builder(serviceName) // .WithLoggerFactory(loggerFactory) // .WithSampler(sampler) // .Build(); GlobalTracer.Register(tracer); return(tracer); }); s.AddOpenTracing(); s.AddHostedService <OrleansService>(); s.AddSingleton(sp => GetSiloClusterClient()); });
public AppInsightsDependencyEnd2EndSpecs(AppInsightsFixture fixture) { _fixture = fixture; _tracer = new ApplicationInsightsTracer(fixture.TelemetryConfiguration); }
public B3PropagatorSpecs() { // use whatever the active TelemetryConfiguration is, if any (probably none) Tracer = new ApplicationInsightsTracer(TelemetryConfiguration.Active); }
public AppInsightsRequestEnd2EndSpec(AppInsightsFixture fixture) { _fixture = fixture; _tracer = new ApplicationInsightsTracer(fixture.TelemetryConfiguration); }