private static ZipkinTraceExporter CreateExporter(IServiceProvider p, IConfiguration config) { var h = p.GetRequiredService <IHostingEnvironment>(); var opts = new TraceExporterOptions(h.ApplicationName, config); var censusOpts = new ZipkinTraceExporterOptions() { Endpoint = new Uri(opts.Endpoint), TimeoutSeconds = TimeSpan.FromSeconds(opts.TimeoutSeconds), ServiceName = opts.ServiceName, UseShortTraceIds = opts.UseShortTraceIds }; var tracing = p.GetRequiredService <ITracing>(); if (!opts.ValidateCertificates) { var client = new HttpClient( new HttpClientHandler() { ServerCertificateCustomValidationCallback = (mesg, cert, chain, errors) => { return(true); } }); return(new ZipkinTraceExporter(censusOpts, tracing.ExportComponent, client)); } else { return(new ZipkinTraceExporter(censusOpts, tracing.ExportComponent)); } }
public void InitializedWithDefaults() { ConfigurationBuilder builder = new ConfigurationBuilder(); TraceExporterOptions opts = new TraceExporterOptions(null, builder.Build()); Assert.Equal("Unknown", opts.ServiceName); Assert.True(opts.ValidateCertificates); Assert.Equal(TraceExporterOptions.DEFAULT_TIMEOUT, opts.TimeoutSeconds); Assert.True(opts.UseShortTraceIds); Assert.Equal(TraceExporterOptions.DEFAULT_ENDPOINT, opts.Endpoint); }
public void InitializedWithDefaults() { var config = new ConfigurationBuilder().Build(); var opts = new TraceExporterOptions(new ApplicationInstanceInfo(config), config); Assert.Equal(TestHelpers.EntryAssemblyName, opts.ServiceName); Assert.True(opts.ValidateCertificates); Assert.Equal(TraceExporterOptions.DEFAULT_TIMEOUT, opts.TimeoutSeconds); Assert.True(opts.UseShortTraceIds); Assert.Equal(TraceExporterOptions.DEFAULT_ENDPOINT, opts.Endpoint); }
public void ApplicationName_ReturnsExpected() { // Finds spring app name var appsettings = new Dictionary <string, string>() { ["spring:application:name"] = "foobar" }; var config = TestHelpers.GetConfigurationFromDictionary(appsettings); var opts = new TraceExporterOptions(new ApplicationInstanceInfo(config), config); Assert.Equal("foobar", opts.ServiceName); // Management name overrides spring name appsettings = new Dictionary <string, string>() { ["spring:application:name"] = "foobar", ["management:tracing:exporter:zipkin:serviceName"] = "foobar2" }; config = TestHelpers.GetConfigurationFromDictionary(appsettings); opts = new TraceExporterOptions(new ApplicationInstanceInfo(config), config); Assert.Equal("foobar2", opts.ServiceName); // Default name returned appsettings = new Dictionary <string, string>(); config = TestHelpers.GetConfigurationFromDictionary(appsettings); opts = new TraceExporterOptions(new ApplicationInstanceInfo(config), config); Assert.Equal(TestHelpers.EntryAssemblyName, opts.ServiceName); // vcap app name overrides spring name appsettings = new Dictionary <string, string>() { ["vcap:application:name"] = "foobar", ["spring:application:name"] = "foobar", }; config = TestHelpers.GetConfigurationFromDictionary(appsettings); opts = new TraceExporterOptions(new ApplicationInstanceInfo(config), config); Assert.Equal("foobar", opts.ServiceName); // Management name overrides everything appsettings = new Dictionary <string, string>() { ["management:tracing:exporter:zipkin:serviceName"] = "foobar", ["vcap:application:name"] = "foobar1", ["spring:application:name"] = "foobar2", }; config = TestHelpers.GetConfigurationFromDictionary(appsettings); opts = new TraceExporterOptions(new ApplicationInstanceInfo(config), config); Assert.Equal("foobar", opts.ServiceName); }
public void BindsConfigurationCorrectly() { var appsettings = new Dictionary <string, string>() { ["management:tracing:exporter:zipkin:serviceName"] = "foobar", ["management:tracing:exporter:zipkin:validateCertificates"] = "false", ["management:tracing:exporter:zipkin:timeoutSeconds"] = "100", ["management:tracing:exporter:zipkin:useShortTraceIds"] = "true", ["management:tracing:exporter:zipkin:endpoint"] = "https://foo.com/api/v2/spans" }; var config = TestHelpers.GetConfigurationFromDictionary(appsettings); var opts = new TraceExporterOptions(new ApplicationInstanceInfo(config), config); Assert.Equal("foobar", opts.ServiceName); Assert.False(opts.ValidateCertificates); Assert.Equal(100, opts.TimeoutSeconds); Assert.True(opts.UseShortTraceIds); Assert.Equal("https://foo.com/api/v2/spans", opts.Endpoint); }
public void BindsConfigurationCorrectly() { var appsettings = new Dictionary <string, string>() { ["management:tracing:exporter:zipkin:serviceName"] = "foobar", ["management:tracing:exporter:zipkin:validateCertificates"] = "false", ["management:tracing:exporter:zipkin:timeoutSeconds"] = "100", ["management:tracing:exporter:zipkin:useShortTraceIds"] = "true", ["management:tracing:exporter:zipkin:endpoint"] = "http://foo.com/api/v2/spans" }; ConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(appsettings); TraceExporterOptions opts = new TraceExporterOptions(null, builder.Build()); Assert.Equal("foobar", opts.ServiceName); Assert.False(opts.ValidateCertificates); Assert.Equal(100, opts.TimeoutSeconds); Assert.True(opts.UseShortTraceIds); Assert.Equal("http://foo.com/api/v2/spans", opts.Endpoint); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { TracingConfiguration tracingConfig = Configuration.GetSection("TracingConfiguration").Get <TracingConfiguration>(); TraceExporterOptions exporter = (TraceExporterOptions)tracingConfig.Exporter; switch (exporter) { case TraceExporterOptions.JAEGER: services.AddOpenTelemetryTracing((builder) => builder .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName)) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddJaegerExporter(jaegerOptions => { jaegerOptions.AgentHost = tracingConfig.JaegerEndpoint.Host; jaegerOptions.AgentPort = tracingConfig.JaegerEndpoint.Port; })); break; case TraceExporterOptions.ZIPKIN: services.AddOpenTelemetryTracing((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddZipkinExporter(zipkinOptions => { zipkinOptions.Endpoint = new Uri(tracingConfig.ZipkinEndpoint); })); break; case TraceExporterOptions.OPENTELEMETRY_PROTOCOL: // Adding the OtlpExporter creates a GrpcChannel. // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service. // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); services.AddOpenTelemetryTracing((builder) => builder .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName)) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddOtlpExporter(otlpOptions => { otlpOptions.Endpoint = new Uri(tracingConfig.OltpEndpoint); })); break; default: services.AddOpenTelemetryTracing((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddConsoleExporter()); break; } services.AddRazorPages(); services.AddServerSideBlazor(); services.AddSingleton <InventoryService>(); services.AddSingleton <CartService>(); services.AddSingleton <PurchaseService>(); services.AddBlazoredToast(); }
public void ApplicationName_ReturnsExpected() { // Finds spring app name var appsettings = new Dictionary <string, string>() { ["spring:application:name"] = "foobar" }; ConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(appsettings); var config = builder.Build(); TraceExporterOptions opts = new TraceExporterOptions("default", config); Assert.Equal("foobar", opts.ServiceName); // Managment name overrides spring name appsettings = new Dictionary <string, string>() { ["spring:application:name"] = "foobar", ["management:tracing:exporter:zipkin:serviceName"] = "foobar2" }; builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(appsettings); config = builder.Build(); opts = new TraceExporterOptions(null, config); Assert.Equal("foobar2", opts.ServiceName); // Default name returned appsettings = new Dictionary <string, string>(); builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(appsettings); config = builder.Build(); opts = new TraceExporterOptions("default", config); Assert.Equal("default", opts.ServiceName); // No default name, returns unknown opts = new TraceExporterOptions(null, config); Assert.Equal("Unknown", opts.ServiceName); // vcap app name overrides spring name appsettings = new Dictionary <string, string>() { ["vcap:application:name"] = "foobar", ["spring:application:name"] = "foobar", }; builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(appsettings); config = builder.Build(); opts = new TraceExporterOptions(null, config); Assert.Equal("foobar", opts.ServiceName); // Management name overrides everything appsettings = new Dictionary <string, string>() { ["management:tracing:exporter:zipkin:serviceName"] = "foobar", ["vcap:application:name"] = "foobar1", ["spring:application:name"] = "foobar2", }; builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(appsettings); config = builder.Build(); opts = new TraceExporterOptions(null, config); Assert.Equal("foobar", opts.ServiceName); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { TracingConfiguration tracingConfig = Configuration.GetSection("TracingConfiguration").Get <TracingConfiguration>(); TraceExporterOptions exporter = (TraceExporterOptions)tracingConfig.Exporter; switch (exporter) { case TraceExporterOptions.JAEGER: services.AddOpenTelemetryTracing((builder) => builder .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName)) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddJaegerExporter(jaegerOptions => { jaegerOptions.AgentHost = tracingConfig.JaegerEndpoint.Host; jaegerOptions.AgentPort = tracingConfig.JaegerEndpoint.Port; }) .AddMongoDBInstrumentation()); break; case TraceExporterOptions.ZIPKIN: services.AddOpenTelemetryTracing((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddZipkinExporter(zipkinOptions => { zipkinOptions.Endpoint = new Uri(tracingConfig.ZipkinEndpoint); }) .AddMongoDBInstrumentation()); break; case TraceExporterOptions.OPENTELEMETRY_PROTOCOL: // Adding the OtlpExporter creates a GrpcChannel. // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service. // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); services.AddOpenTelemetryTracing((builder) => builder .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName)) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddOtlpExporter(otlpOptions => { otlpOptions.Endpoint = new Uri(tracingConfig.OltpEndpoint); }) .AddMongoDBInstrumentation()); break; default: services.AddOpenTelemetryTracing((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddConsoleExporter() .AddMongoDBInstrumentation()); break; } services.Configure <InventoryDatabaseSettings>( Configuration.GetSection(nameof(InventoryDatabaseSettings))); services.AddSingleton <IInventoryDatabaseSettings>(sp => sp.GetRequiredService <IOptions <InventoryDatabaseSettings> >().Value); services.AddScoped(typeof(IMongoRepository <>), typeof(MongoRepository <>)); services.AddScoped <IInventoryService, InventoryService>(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Cars Unlimited Inventory API", Version = "v1" }); }); services.AddHealthChecks(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { TracingConfiguration tracingConfig = Configuration.GetSection("TracingConfiguration").Get <TracingConfiguration>(); RedisSettings redisSettings = Configuration.GetSection("RedisSettings").Get <RedisSettings>(); var redisConfiguration = new RedisConfiguration() { AbortOnConnectFail = true, Hosts = new RedisHost[] { new RedisHost() { Host = redisSettings.Host, Port = redisSettings.Port }, }, AllowAdmin = false, Database = 0, ConnectTimeout = 10000, Ssl = redisSettings.Ssl, Password = redisSettings.Password, ServerEnumerationStrategy = new ServerEnumerationStrategy() { Mode = ServerEnumerationStrategy.ModeOptions.All, TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any, UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw }, MaxValueLength = 1024, PoolSize = 5 }; TraceExporterOptions exporter = (TraceExporterOptions)tracingConfig.Exporter; switch (exporter) { case TraceExporterOptions.JAEGER: services.AddOpenTelemetryTracing((builder) => builder .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName)) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddJaegerExporter(jaegerOptions => { jaegerOptions.AgentHost = tracingConfig.JaegerEndpoint.Host; jaegerOptions.AgentPort = tracingConfig.JaegerEndpoint.Port; })); break; case TraceExporterOptions.ZIPKIN: services.AddOpenTelemetryTracing((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddZipkinExporter(zipkinOptions => { zipkinOptions.Endpoint = new Uri(tracingConfig.ZipkinEndpoint); })); break; case TraceExporterOptions.OPENTELEMETRY_PROTOCOL: // Adding the OtlpExporter creates a GrpcChannel. // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service. // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); services.AddOpenTelemetryTracing((builder) => builder .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName)) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddOtlpExporter(otlpOptions => { otlpOptions.Endpoint = new Uri(tracingConfig.OltpEndpoint); })); break; default: services.AddOpenTelemetryTracing((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddConsoleExporter()); break; } services.AddStackExchangeRedisExtensions <SystemTextJsonSerializer>(redisConfiguration); services.AddScoped <IUpdateCartService, UpdateCartService>(); services.AddScoped <IGetCartItems, GetCartItems>(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Cars Unlimited Cart API", Version = "v1" }); }); services.AddHealthChecks(); }