// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSession(); //Enable middleware to serve generated Swagger as a JSON endpoint, and generate swagger-ui (HTML, etc) app.UseSwagger(x => x.RouteTemplate = "api/cart/{documentName}/swagger.json"); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/api/cart/docs/swagger.json", "re:Invent WIN401 Cart API"); c.RoutePrefix = "api/cart/swagger"; }); AWSXRayRecorder.InitializeInstance(Configuration); app.UseXRay("CartService"); app.MergeAuthorizationHeaderWithSession(); app.UseAuthentication(); app.UseCors("AllowAllOrigins"); app.UseMvc(); }
/// <summary> /// Initializes a new instance of the <see cref="AWSXRayMiddleware" /> class. /// </summary> /// <param name="next">Instance of <see cref="RequestDelegate"/></param> /// <param name="segmentNamingStrategy">The segment naming strategy.</param> /// <param name="configuration">The instance of <see cref="IConfiguration" />.</param> /// <exception cref="ArgumentNullException">segmentNamingStrategy is null.</exception> public AWSXRayMiddleware(RequestDelegate next, SegmentNamingStrategy segmentNamingStrategy, IConfiguration configuration) { AWSXRayRecorder.InitializeInstance(configuration); _recorder = AWSXRayRecorder.Instance; _next = next; SegmentNamingStrategy = segmentNamingStrategy ?? throw new ArgumentNullException("segmentNamingStrategy"); }
public void Initialize() { Environment.SetEnvironmentVariable(AWSXRayRecorder.LambdaTaskRootKey, "test"); Environment.SetEnvironmentVariable(AWSXRayRecorder.LambdaTraceHeaderKey, _traceHeaderValue); _recorder = new AWSXRayRecorderBuilder().Build(); AWSXRayRecorder.InitializeInstance(recorder: _recorder); }
public async Task TestXrayContextMissingStrategySendAsync() // Test that respects ContextMissingStrategy { _recorder = new MockAWSXRayRecorder(); #if NET45 AWSXRayRecorder.InitializeInstance(_recorder); #else AWSXRayRecorder.InitializeInstance(recorder: _recorder); #endif AWSXRayRecorder.Instance.ContextMissingStrategy = Core.Strategies.ContextMissingStrategy.LOG_ERROR; Assert.IsFalse(AWSXRayRecorder.Instance.IsTracingDisabled()); _recorder.EndSegment(); // The test should not break. No segment is available in the context, however, since the context missing strategy is log error, // no exception should be thrown by below code. var request = new HttpRequestMessage(HttpMethod.Get, URL); using (var response = await _httpClient.SendAsync(request)) { Assert.IsNotNull(response); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); } }
public void TestInitializeInstanceWithRecorder3() // setting custom daemon address to DefaultSamplingStrategy() { string daemonAddress = "udp:127.0.0.2:2001 tcp:127.0.0.1:2000"; IPEndPoint expectedUDPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2001); IPEndPoint expectedTCPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2000); AWSXRayRecorder recorder = BuildAWSXRayRecorder(daemonAddress: daemonAddress); #if NET45 AWSXRayRecorder.InitializeInstance(recorder); #else AWSXRayRecorder.InitializeInstance(recorder: recorder); #endif Assert.AreEqual(AWSXRayRecorder.Instance.SamplingStrategy, recorder.SamplingStrategy); Assert.AreEqual(typeof(DefaultSamplingStrategy), recorder.SamplingStrategy.GetType()); // Default startegy set Assert.AreEqual(typeof(UdpSegmentEmitter), recorder.Emitter.GetType()); // Default emitter set var udpEmitter = (UdpSegmentEmitter)recorder.Emitter; Assert.AreEqual(expectedUDPEndpoint, udpEmitter.EndPoint); var defaultStartegy = (DefaultSamplingStrategy)recorder.SamplingStrategy; Assert.AreEqual(expectedUDPEndpoint, defaultStartegy.DaemonCfg.UDPEndpoint); Assert.AreEqual(expectedTCPEndpoint, defaultStartegy.DaemonCfg.TCPEndpoint); recorder.Dispose(); }
/// <summary> /// Instrument tracing configurations, such as pluggins, sampling rules, service name, etc., from AspNet Core application. /// </summary> public static XRayAutoInstrumentationOptions Register() { IConfiguration configuration = null; try { // Get the json file configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); } catch (Exception e) { _logger.Error(e, "Can't fetch configuration from appsettings.json file."); } // Initialize a new instance of the AWSXRayRecorder with given instance of IConfiguration. // If configuration is null, default value will be set. AWSXRayRecorder.InitializeInstance(configuration); var xrayAutoInstrumentationOptions = GetXRayAutoInstrumentationOptions(configuration); // Set daemon address AWSXRayRecorder.Instance.SetDaemonAddress(xrayAutoInstrumentationOptions.DaemonAddress); return(xrayAutoInstrumentationOptions); }
public BlogPostsUpdate() { secrets = GetSecrets.GetSecretsDictionary(); string connstr = GetSecrets.GetSecretConnectionString(); bpc = GetConnectionString.GetContext(connstr); AWSXRayRecorder.InitializeInstance(); }
public Startup(IConfiguration configuration) { AWSXRayRecorder.InitializeInstance(configuration); AWSXRayRecorder.RegisterLogger(Amazon.LoggingOptions.Console); AWSSDKHandler.RegisterXRayForAllServices(); Configuration = configuration; }
public Startup(IConfiguration configuration) { Configuration = configuration; // AWS X-Ray // pass IConfiguration object that reads appsettings.json file AWSXRayRecorder.InitializeInstance(configuration); }
public void TestExceptionStrategy1() // valid input { var exceptionStrategy = new DefaultExceptionSerializationStrategy(10); var recorder = new AWSXRayRecorderBuilder().WithExceptionSerializationStrategy(exceptionStrategy).Build(); // set custom stackframe size AWSXRayRecorder.InitializeInstance(recorder: recorder); Assert.AreSame(exceptionStrategy, AWSXRayRecorder.Instance.ExceptionSerializationStrategy); }
public Startup(IConfiguration configuration, IWebHostEnvironment env) { _env = env; Configuration = configuration; AWSXRayRecorder.InitializeInstance(configuration); AWSSDKHandler.RegisterXRayForAllServices(); AWSXRayRecorder.Instance.ContextMissingStrategy = ContextMissingStrategy.LOG_ERROR; }
public void TestInitialize() { _recorder = new AWSXRayRecorder(); AWSXRayRecorder.InitializeInstance(recorder: _recorder); // In-memory database only exists while the connection is open connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); }
public void TestInitialize() { _recorder = new AWSXRayRecorder(); #if NET45 AWSXRayRecorder.InitializeInstance(_recorder); #else AWSXRayRecorder.InitializeInstance(recorder: _recorder); #endif }
/// <summary> /// Configures tracing services on the service collection. /// </summary> /// <param name="services">The service collection to configure.</param> public static void ConfigureTracingServices(this IServiceCollection services) { AWSXRayRecorder.InitializeInstance(); services.AddSingleton <DelegatingHandler, HttpClientXRayTracingHandler>(); services.TryAddSingleton <ITracingService, AwsXRayTracingService>(); services.TryAddSingleton <ITracingIdService, AwsXRayTracingIdService>(); services.TryAddSingleton <IAWSXRayRecorder>(AWSXRayRecorder.Instance); }
public void TestCollecSqlQueriesTrue() { IConfiguration configuration = BuildConfiguration("CollectSqlQueriesTrue.json"); _xRayOptions = XRayConfiguration.GetXRayOptions(configuration); AWSXRayRecorder.InitializeInstance(configuration); Assert.IsTrue(_xRayOptions.CollectSqlQueries); }
public BlogPostsGetAll() { secrets = GetSecrets.GetSecretsDictionary(); string connstr = GetSecrets.GetSecretConnectionString(); Console.WriteLine($"Connection string:: {connstr}"); bpc = GetConnectionString.GetContext(connstr); AWSXRayRecorder.InitializeInstance(); }
public void TestCollectSqlQueriesFalse_WhenNotSpecifiedInJson() { IConfiguration configuration = BuildConfiguration("DisabledXRayMissing.json"); _xRayOptions = XRayConfiguration.GetXRayOptions(configuration); AWSXRayRecorder.InitializeInstance(configuration); Assert.IsFalse(_xRayOptions.CollectSqlQueries); }
public void TestExceptionStrategy2() // invalid input { var exceptionStrategy = new DefaultExceptionSerializationStrategy(-10); var recorder = new AWSXRayRecorderBuilder().WithExceptionSerializationStrategy(exceptionStrategy).Build(); // set custom stackframe size AWSXRayRecorder.InitializeInstance(recorder: recorder); DefaultExceptionSerializationStrategy actual = AWSXRayRecorder.Instance.ExceptionSerializationStrategy as DefaultExceptionSerializationStrategy; Assert.AreEqual(DefaultExceptionSerializationStrategy.DefaultStackFrameSize, actual.MaxStackFrameSize); }
public Startup(IConfiguration configuration) { Configuration = configuration; // XRayRecorderの初期化 AWSXRayRecorder.InitializeInstance(configuration); // (App Mesh時はコメントアウト) SDKリクエストをすべてトレース対象とする AWSSDKHandler.RegisterXRayForAllServices(); }
public void TestExceptionStrategy5() // Test custom exception strategy { List <Type> l = new List <Type>(); l.Add(typeof(ArgumentNullException)); var recorder = new AWSXRayRecorderBuilder().WithExceptionSerializationStrategy(new DefaultExceptionSerializationStrategy(10, l)).Build(); // set custom stackframe size AWSXRayRecorder.InitializeInstance(recorder: recorder); AWSXRayRecorder.Instance.BeginSegment("parent", TraceId); var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); try { recorder.BeginSubsegment("child1"); try { try { recorder.BeginSubsegment("child2"); throw new AmazonServiceException(); } catch (AmazonServiceException e) { recorder.AddException(e); recorder.EndSubsegment(); throw new ArgumentNullException("value"); } } catch (ArgumentNullException e) { recorder.AddException(e); recorder.EndSubsegment(); throw new EntityNotAvailableException("Dummy message", e); } } catch (EntityNotAvailableException e) { recorder.AddException(e); recorder.EndSegment(); } Assert.AreEqual("Dummy message", segment.Cause.ExceptionDescriptors[0].Message); Assert.AreEqual("EntityNotAvailableException", segment.Cause.ExceptionDescriptors[0].Type); Assert.IsFalse(segment.Cause.ExceptionDescriptors[0].Remote); // default false Assert.AreEqual(segment.Cause.ExceptionDescriptors[0].Cause, segment.Subsegments[0].Cause.ExceptionDescriptors[0].Id); Assert.AreEqual(1, segment.Cause.ExceptionDescriptors.Count); Assert.AreEqual("ArgumentNullException", segment.Subsegments[0].Cause.ExceptionDescriptors[0].Type); Assert.IsTrue(segment.Subsegments[0].Cause.ExceptionDescriptors[0].Remote); // set to true Assert.AreEqual("AmazonServiceException", segment.Subsegments[0].Subsegments[0].Cause.ExceptionDescriptors[0].Type); Assert.IsTrue(segment.Subsegments[0].Subsegments[0].Cause.ExceptionDescriptors[0].Remote); // set to true }
public void TestUseRuntimeErrorsDefaultsTrue_WhenNotSpecifiedInJson() { IConfiguration configuration = BuildConfiguration("DisabledXRayMissing.json"); _xRayOptions = XRayConfiguration.GetXRayOptions(configuration); AWSXRayRecorder.InitializeInstance(configuration); Assert.IsTrue(_xRayOptions.UseRuntimeErrors); Assert.AreEqual(AWSXRayRecorder.Instance.ContextMissingStrategy, Core.Strategies.ContextMissingStrategy.RUNTIME_ERROR); }
public void TestUseRuntimeErrorsTrue() { IConfiguration configuration = BuildConfiguration("UseRuntimeErrorsTrue.json"); _xRayOptions = XRayConfiguration.GetXRayOptions(configuration); AWSXRayRecorder.InitializeInstance(configuration); Assert.IsTrue(_xRayOptions.UseRuntimeErrors); Assert.AreEqual(AWSXRayRecorder.Instance.ContextMissingStrategy, Core.Strategies.ContextMissingStrategy.RUNTIME_ERROR); }
public void TestInitializeInstanceWithRecorde4() // Set custom trace context { AWSXRayRecorder recorder = BuildAWSXRayRecorder(traceContext: new DummyTraceContext()); #if NET45 AWSXRayRecorder.InitializeInstance(recorder); #else AWSXRayRecorder.InitializeInstance(recorder: recorder); #endif Assert.AreEqual(typeof(DummyTraceContext), AWSXRayRecorder.Instance.TraceContext.GetType()); // Custom trace context recorder.Dispose(); }
public void TestExceptionStrategy6() // Setting stack frame size to 0, so no stack trace is recorded { int stackFrameSize = 0; var recorder = new AWSXRayRecorderBuilder().WithExceptionSerializationStrategy(new DefaultExceptionSerializationStrategy(stackFrameSize)).Build(); // set custom stackframe size AWSXRayRecorder.InitializeInstance(recorder: recorder); AWSXRayRecorder.Instance.BeginSegment("parent", TraceId); var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity(); try { recorder.BeginSubsegment("child1"); try { try { recorder.BeginSubsegment("child2"); throw new AmazonServiceException(); } catch (AmazonServiceException e) { recorder.AddException(e); recorder.EndSubsegment(); throw new ArgumentNullException("value"); } } catch (ArgumentNullException e) { recorder.AddException(e); recorder.EndSubsegment(); throw new EntityNotAvailableException("Dummy message", e); } } catch (EntityNotAvailableException e) { recorder.AddException(e); recorder.EndSegment(); } Assert.AreEqual("Dummy message", segment.Cause.ExceptionDescriptors[0].Message); Assert.AreEqual("EntityNotAvailableException", segment.Cause.ExceptionDescriptors[0].Type); Assert.IsFalse(segment.Cause.ExceptionDescriptors[0].Remote); // default false Assert.AreEqual(segment.Cause.ExceptionDescriptors[0].Cause, segment.Subsegments[0].Cause.ExceptionDescriptors[0].Id); Assert.AreEqual(segment.Cause.ExceptionDescriptors[0].Stack.Length, stackFrameSize); // no stack frames should be recorded Assert.IsTrue(segment.Cause.ExceptionDescriptors[0].Truncated > 0); Assert.AreEqual(1, segment.Cause.ExceptionDescriptors.Count); Assert.AreEqual("ArgumentNullException", segment.Subsegments[0].Cause.ExceptionDescriptors[0].Type); Assert.AreEqual("AmazonServiceException", segment.Subsegments[0].Subsegments[0].Cause.ExceptionDescriptors[0].Type); }
public void TestInitializeInstanceWithRecorder1() { AWSXRayRecorder recorder = BuildAWSXRayRecorder(new TestSamplingStrategy()); #if NET45 AWSXRayRecorder.InitializeInstance(recorder); #else AWSXRayRecorder.InitializeInstance(recorder: recorder); #endif Assert.AreEqual(AWSXRayRecorder.Instance.SamplingStrategy, recorder.SamplingStrategy); // Custom recorder set in AWSXRayRecorder.Instance.TraceContext Assert.AreEqual(typeof(TestSamplingStrategy), recorder.SamplingStrategy.GetType()); // custom strategy set Assert.AreEqual(typeof(UdpSegmentEmitter), recorder.Emitter.GetType()); // Default emitter set recorder.Dispose(); }
public void TestInitializeInstance() { IConfiguration configuration = BuildConfiguration("DisabledXRayTrue.json"); AWSXRayRecorder.InitializeInstance(configuration); _xRayOptions = AWSXRayRecorder.Instance.XRayOptions; Assert.IsTrue(_xRayOptions.IsXRayTracingDisabled); Assert.IsNull(_xRayOptions.AwsServiceHandlerManifest); Assert.IsNull(_xRayOptions.PluginSetting); Assert.IsNull(_xRayOptions.SamplingRuleManifest); AWSXRayRecorder.Instance.Dispose(); }
/// <summary> /// Default set up. /// </summary> public static void SetUp() { Configuration = new ConfigurationBuilder() .SetBasePath(Path.Combine(Directory.GetCurrentDirectory())) .AddJsonFile("appsettings.json") .AddEnvironmentVariables() .Build(); AWSXRayRecorder.InitializeInstance(Configuration); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) .CreateLogger(); Audit.Core.Configuration.Setup().UseSerilog(); Audit.Core.Configuration.AuditDisabled = true; }
public static IServiceCollection AddAppAWS(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment) { if (!environment.IsEnvironment("Testing")) { AWSXRayRecorder recorder = new AWSXRayRecorderBuilder().Build(); AWSXRayRecorder.InitializeInstance(configuration, recorder); AWSSDKHandler.RegisterXRayForAllServices(); } services.AddAWSService <IAmazonSimpleNotificationService>(); return(services); }
public void TestInitialize() { _recorder = new AWSXRayRecorder(); AWSXRayRecorder.InitializeInstance(recorder: _recorder); var subscription = new List <DiagnosticListenerBase>() { new EntityFrameworkCoreDiagnosticListener() }; _subscription = DiagnosticListener.AllListeners.Subscribe(new DiagnosticListenerObserver(subscription)); // In-memory database only exists while the connection is open connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); }
public void TestInitializeInstanceWithRecorder() { IConfiguration configuration = BuildConfiguration("DisabledXRayTrue.json"); AWSXRayRecorder recorder = BuildAWSXRayRecorder(); AWSXRayRecorder.InitializeInstance(configuration, recorder); _xRayOptions = recorder.XRayOptions; Assert.IsTrue(_xRayOptions.IsXRayTracingDisabled); Assert.IsNull(_xRayOptions.AwsServiceHandlerManifest); Assert.IsNull(_xRayOptions.PluginSetting); Assert.IsNull(_xRayOptions.SamplingRuleManifest); Assert.AreEqual(AWSXRayRecorder.Instance.SamplingStrategy, recorder.SamplingStrategy); // Custom recorder set in TraceContext recorder.Dispose(); }