Beispiel #1
0
        public AdoptionListController(IConfiguration configuration)
        {
            _configuration = configuration;
            httpClient     = new HttpClient(new HttpClientXRayTracingHandler(new HttpClientHandler()));

            AWSSDKHandler.RegisterXRayForAllServices();
        }
Beispiel #2
0
        public void TestDynamoDbClient()
        {
            AWSSDKHandler.RegisterXRayForAllServices(_path);
            // IAmazonDynamoDb will be registered. All new instances of AmazonServiceClient will be automatically registered.

            using (var client = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1))
            {
                string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere";
                CustomResponses.SetResponse(client, null, requestId, true);

                _recorder.BeginSegment("test", TraceId);
#if NET45
                client.ListTables();
#else
                client.ListTablesAsync().Wait();
#endif
                var segment    = TraceContext.GetEntity();
                var subsegment = segment.Subsegments[0];
                _recorder.EndSegment();

                Assert.AreEqual(segment.Subsegments.Count, 1);
                Assert.AreEqual(subsegment.Name, "DynamoDBv2");
                Assert.AreEqual(subsegment.Aws["region"], RegionEndpoint.USEast1.SystemName);
                Assert.AreEqual(subsegment.Aws["operation"], "ListTables");
                Assert.AreEqual(requestId, subsegment.Aws["request_id"]);
                Assert.AreEqual("aws", subsegment.Namespace);
            }
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            if (AwsUtilityMethods.IsRunningOnAWS)
            {
                app.UseXRay(new DynamicSegmentNamingStrategy("pss-ava-chatengine")); // name of the app
                ConfigureXRaySampling();
                AWSSDKHandler.RegisterXRayForAllServices();
            }

            // Register the Swagger generator and the Swagger UI middlewares
            app.UseSwagger();
            app.UseSwaggerUi3();

            app.UseSignalR(routes =>
            {
                routes.MapHub <NodeJSHub>("/nodeHub");
            });
            app.UseMvc();

            //loggerFactory.AddLog4Net(); // Log Microsoft ILogger to Log4Net
        }
Beispiel #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            // TODO3 BEGIN - enable X-Ray tracing here
            app.UseXRay("UrlRedirector");
            AWSSDKHandler.RegisterXRayForAllServices();
            // TODO 3 END

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
 private async Task <StartExecutionResponse> StartStepFunctionExecution(string petId, string petType)
 {
     /*
      *
      * // Code to invoke StepFunction through API Gateway
      * var stepFunctionInputModel = new StepFunctionInputModel()
      * {
      *  input = JsonSerializer.Serialize(new SearchParams() {petid = petId, pettype = petType}),
      *  name = $"{petType}-{petId}-{Guid.NewGuid()}",
      *  stateMachineArn = SystemsManagerConfigurationProviderWithReloadExtensions.GetConfiguration(_configuration,"petadoptionsstepfnarn")
      * };
      *
      * var content = new StringContent(
      *  JsonSerializer.Serialize(stepFunctionInputModel),
      *  Encoding.UTF8,
      *  "application/json");
      *
      * return await _httpClient.PostAsync(SystemsManagerConfigurationProviderWithReloadExtensions.GetConfiguration(_configuration,"petadoptionsstepfnurl"), content);
      *
      */
     // Console.WriteLine($"STEPLOG -ARN - {SystemsManagerConfigurationProviderWithReloadExtensions.GetConfiguration(_configuration,"petadoptionsstepfnarn")}");
     //Console.WriteLine($"STEPLOG - SERIALIZE - {JsonSerializer.Serialize(new SearchParams() {petid = petId, pettype = petType})}");
     AWSSDKHandler.RegisterXRay <IAmazonStepFunctions>();
     return(await new AmazonStepFunctionsClient().StartExecutionAsync(new StartExecutionRequest()
     {
         Input = JsonSerializer.Serialize(new SearchParams()
         {
             petid = petId, pettype = petType
         }),
         Name = $"{petType}-{petId}-{Guid.NewGuid()}",
         StateMachineArn = SystemsManagerConfigurationProviderWithReloadExtensions.GetConfiguration(_configuration, "petadoptionsstepfnarn")
     }));
 }
        public PhotosController(
            IPhotosService photosService,
            IUsersService usersService,
            ITextSplitter textSplitter,
            ISystem system,
            ILogWriterFactory loggerFactory)
        {
            if (textSplitter is null)
            {
                throw new ArgumentNullException(nameof(textSplitter));
            }


            if (loggerFactory is null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            this.photosService = photosService ?? throw new ArgumentNullException(nameof(photosService));
            this.usersService  = usersService ?? throw new ArgumentNullException(nameof(usersService));
            this.system        = system ?? throw new ArgumentNullException(nameof(system));
            logger             = loggerFactory.CreateLogger <PhotosController>();
            lazyClaims         = new Lazy <Claim[]>(() => GetUserClaims());


            var staticAssetHost = new Uri(system.Environment.GetVariable(Constants.EnvironmentVariables.StaticAssetHost));

            this.photoModelConverter = new PhotoModelConverter(staticAssetHost, textSplitter, loggerFactory);
            AWSSDKHandler.RegisterXRayForAllServices();
        }
 public async Task <IActionResult> Reject(Leave leave)
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     leave.LeaveStatus      = "Rejected";
     ViewData["SaveStatus"] = (await this.httpClient.PostAsJsonAsync(APIURL, leave)).IsSuccessStatusCode.ToString();
     return(View("Approve", leave));
 }
Beispiel #8
0
        public static BudgetDetail GetBudget(string accessToken, string userId)
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetBudget()");
            try
            {
                // Local File
                BudgetDetail budget = GetLocalBudget(userId);
                if (budget != null)
                {
                    return(budget);
                }

                // S3 File
                budget = GetS3Budget(userId);
                if (budget != null)
                {
                    return(budget);
                }

                // API File
                budget = GetApiBudget(accessToken, userId);

                return(budget);
            }
            catch (Exception e)
            {
                AWSXRayRecorder.Instance.AddException(e);
                throw;
            }
            finally
            {
                AWSXRayRecorder.Instance.EndSubsegment();
            }
        }
        public UsersController(
            IUsersService usersService,
            IPhotosService photosService,
            ITextSplitter textSplitter,
            ISystem system,
            ILogWriterFactory logWriterFactory)
        {
            if (textSplitter is null)
            {
                throw new ArgumentNullException(nameof(textSplitter));
            }

            if (system is null)
            {
                throw new ArgumentNullException(nameof(system));
            }

            if (logWriterFactory is null)
            {
                throw new ArgumentNullException(nameof(logWriterFactory));
            }

            this.usersService  = usersService ?? throw new ArgumentNullException(nameof(usersService));
            this.photosService = photosService ?? throw new ArgumentNullException(nameof(photosService));

            var imageAssetHost = new Uri(system.Environment.GetVariable(Constants.EnvironmentVariables.StaticAssetHost));

            this.photoModelConverter = new PhotoModelConverter(imageAssetHost, textSplitter, logWriterFactory);

            AWSSDKHandler.RegisterXRayForAllServices();
        }
Beispiel #10
0
        internal static void Configure()
        {
            AWSSDKHandler.RegisterXRayForAllServices();
#if DEBUG
            AWSXRayRecorder.Instance.ContextMissingStrategy = Amazon.XRay.Recorder.Core.Strategies.ContextMissingStrategy.LOG_ERROR;
#endif
        }
        public Startup(IConfiguration configuration, IHostEnvironment environment)
        {
            Configuration      = configuration;
            CurrentEnvironment = environment;

            AWSSDKHandler.RegisterXRayForAllServices();
        }
        public PaymentController(IConfiguration configuration)
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            _configuration = configuration;

            _sqsClient = new AmazonSQSClient(Amazon.Util.EC2InstanceMetadata.Region);
        }
Beispiel #13
0
        public ImageResizeHandler()
        {
            S3Client = new AmazonS3Client();
            remoteFileRepositoryFactory = logWriterFactory => new S3FileRepository(logWriterFactory);
            var system = new DefaultSystem(new SystemEnvironment(), new SystemTime());
            var dynamoDbClientFactory = new DynamoDbClientFactory(string.Empty);

            dataRepositoryFactory = logWriterFactory =>
                                    new DynamoDbPhotoRepository(
                new ScoreCalculator(system, logWriterFactory),
                new DynamoDbCore(dynamoDbClientFactory, logWriterFactory),
                system,
                logWriterFactory);


            photosServiceFactory = logWriterFactory => new PhotosService(
                dataRepositoryFactory(logWriterFactory),
                remoteFileRepositoryFactory(logWriterFactory),
                new TextSplitter(new HttpHelper(), logWriterFactory),
                logWriterFactory);
            imageScalerFactory      = logWriterFactory => new ImageScaler(logWriterFactory);
            logWriterFactoryFactory = lambdaLogger => new LambdaLogWriterFactory(lambdaLogger);

            AWSSDKHandler.RegisterXRayForAllServices();
        }
Beispiel #14
0
        public void TestLambdaInvokeSubsegmentContainsFunctionNameForAWSSDKHandler()
        {
            String temp_path = @"JSONs\AWSRequestInfoWithLambda.json"; //registering manifest file with Lambda

            AWSSDKHandler.RegisterXRayManifest(temp_path);
            var lambda = new AmazonLambdaClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);

            CustomResponses.SetResponse(lambda, null, null, true);
            AWSXRayRecorder.Instance.BeginSegment("lambda", TraceId);
#if NET45
            lambda.Invoke(new InvokeRequest
            {
                FunctionName = "testFunction"
            });
#else
            lambda.InvokeAsync(new InvokeRequest
            {
                FunctionName = "testFunction"
            }).Wait();
#endif
            var segment = TraceContext.GetEntity();
            AWSXRayRecorder.Instance.EndSegment();

            Assert.AreEqual("Invoke", segment.Subsegments[0].Aws["operation"]);
            Assert.AreEqual("testFunction", segment.Subsegments[0].Aws["function_name"]);
        }
Beispiel #15
0
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     //AWSSDKHandler.RegisterXRay<IAmazonS3>();
     //AWSSDKHandler.RegisterXRay<IAmazonSQS>();
     AWSSDKHandler.RegisterXRayForAllServices();
 }
Beispiel #16
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            // Add S3 to the ASP.NET Core dependency injection framework.
            services.AddAWSService <Amazon.S3.IAmazonS3>();
            AWSSDKHandler.RegisterXRayForAllServices();
        }
 public Startup(IConfiguration configuration, IWebHostEnvironment env)
 {
     _env          = env;
     Configuration = configuration;
     AWSXRayRecorder.InitializeInstance(configuration);
     AWSSDKHandler.RegisterXRayForAllServices();
     AWSXRayRecorder.Instance.ContextMissingStrategy = ContextMissingStrategy.LOG_ERROR;
 }
Beispiel #18
0
        public SearchController(IConfiguration configuration)
        {
            _configuration = configuration;

            AWSSDKHandler.RegisterXRayForAllServices();
            ddbClient = new  AmazonDynamoDBClient();
            s3Client  = new AmazonS3Client();
        }
Beispiel #19
0
        public Startup(IConfiguration configuration)
        {
            AWSXRayRecorder.InitializeInstance(configuration);
            AWSXRayRecorder.RegisterLogger(Amazon.LoggingOptions.Console);
            AWSSDKHandler.RegisterXRayForAllServices();

            Configuration = configuration;
        }
        public LambdaFunction()
        {
            AWSSDKHandler.RegisterXRayForAllServices();

            var sender = LambdaConfig.CreateSender();

            _handler = LambdaPluginConfig.CreateHandler(sender);
        }
Beispiel #21
0
        public AdoptionController(IConfiguration configuration)
        {
            _configuration = configuration;

            //_searchApiurl = _configuration["searchapiurl"];
            _searchApiurl = SystemsManagerConfigurationProviderWithReloadExtensions.GetConfiguration(_configuration, "searchapiurl");

            AWSSDKHandler.RegisterXRayForAllServices();
        }
        public async Task <IActionResult> LeavesList()
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            var leavesList = await this.httpClient.GetStringAsync(APIURL);

            var myobject = JsonConvert.DeserializeObject <Leave[]>(leavesList);

            return(View(myobject));
        }
Beispiel #23
0
        public SearchController(IConfiguration configuration)
        {
            _configuration = configuration;

            AWSSDKHandler.RegisterXRayForAllServices();
            ddbClient = new AmazonDynamoDBClient();
            AWSConfigsS3.UseSignatureVersion4 = true;
            s3Client = new AmazonS3Client();
        }
        private async Task <PublishResponse> SendNotification(string petId)
        {
            AWSSDKHandler.RegisterXRay <IAmazonService>();

            var snsClient = new AmazonSimpleNotificationServiceClient();

            return(await snsClient.PublishAsync(topicArn : _configuration["snsarn"],
                                                message : $"PetId {petId} was adopted on {DateTime.Now}"));
        }
Beispiel #25
0
        public Function()
        {
            _apiKey           = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
            _toEmail          = Environment.GetEnvironmentVariable("TO_EMAIL");
            _fromEmail        = Environment.GetEnvironmentVariable("FROM_EMAIL");
            _testingCentreUrl = Environment.GetEnvironmentVariable("TESTING_CENTRE_URL");

            AWSSDKHandler.RegisterXRayForAllServices();
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            AWSSDKHandler.RegisterXRayForAllServices();

            using (var container = CreateContainer())
            {
                var loggerFactory = container.Resolve <ILoggerFactory>();
                var logger        = loggerFactory.CreateCurrentClassLogger();

                var service = HostFactory.New(cfg =>
                {
                    cfg.UseWindsorContainer(container);

                    cfg.Service <WcfServiceHost <StorageResourceAccess> >(svc =>
                    {
                        svc.BeforeStartingService(sc => sc.RequestAdditionalTime(TimeSpan.FromMinutes(1)));
                        svc.BeforeStoppingService(sc => sc.RequestAdditionalTime(TimeSpan.FromMinutes(1)));

                        svc.ConstructUsingWindsorContainer();

                        svc.WhenStarted(host =>
                        {
                            logger.LogInformation($"Starting {ServiceName}");
                            host.Start();
                            logger.LogInformation($"{ServiceName} started");
                        });
                        svc.WhenStopped(host =>
                        {
                            logger.LogInformation($"Stopping {ServiceName}");
                            host.Stop();
                            logger.LogInformation($"{ServiceName} stopped");
                        });
                    });

                    cfg.SetDisplayName("XRaySample StorageResourceAccess");
                    cfg.SetServiceName(ServiceName);

                    cfg.EnableServiceRecovery(rc => rc.RestartService(1).RestartService(5).RestartService(10).SetResetPeriod(1));

                    cfg.RunAsLocalSystem();
                    cfg.StartAutomaticallyDelayed();
                    cfg.SetStopTimeout(TimeSpan.FromMinutes(5));
                });

                try
                {
                    service.Run();
                }
                catch (Exception ex)
                {
                    logger.LogError(ex);
                }

                container.Release(loggerFactory);
            }
        }
        private static void ConfigureAwsServices(IServiceCollection services)
        {
            services.AddSingleton <IAmazonSimpleNotificationService, AmazonSimpleNotificationServiceClient>();
            AWSSDKHandler.RegisterXRay <IAmazonSimpleNotificationService>();

            services.AddSingleton <IAmazonCloudWatch, AmazonCloudWatchClient>();
            AWSSDKHandler.RegisterXRay <IAmazonCloudWatch>();

            services.AddSingleton <IAmazonSQS, AmazonSQSClient>();
        }
Beispiel #28
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            // XRayRecorderの初期化
            AWSXRayRecorder.InitializeInstance(configuration);

            // (App Mesh時はコメントアウト) SDKリクエストをすべてトレース対象とする
            AWSSDKHandler.RegisterXRayForAllServices();
        }
        static async void initialize()
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            lambdaClient = new AmazonLambdaClient();
            AmazonDynamoDBClient dynamodbClient = new AmazonDynamoDBClient();
            DynamoDBContext      ctx            = new DynamoDBContext(dynamodbClient);

            table = new ShortUrlTable(ctx);
            await callLambda();
        }
        public FunctionHandler(
            IAmazonSimpleEmailService emailService,
            IDynamoDBContext dynamo)
        {
            // Enable XRay...
            AWSSDKHandler.RegisterXRayForAllServices();

            this.emailService = emailService;
            this.dynamo       = dynamo;
        }