├── .gitignore ├── DotNET-Agent ├── SampleWebApplication.sln └── src │ ├── App_Start │ └── WebApiConfig.cs │ ├── Controllers │ └── ProductsController.cs │ ├── Global.asax │ ├── Global.asax.cs │ ├── Models │ └── Product.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── SampleWebApplication.csproj │ ├── Web.config │ ├── index.html │ └── packages.config ├── DotNET ├── SampleEBWebApplication.sln └── src │ ├── .ebextensions │ ├── create-dynamodb-table.config │ ├── options.config │ └── xray.config │ ├── App_Start │ └── WebApiConfig.cs │ ├── Controllers │ └── ProductsController.cs │ ├── Global.asax │ ├── Global.asax.cs │ ├── Models │ └── Product.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── SampleEBWebApplication.csproj │ ├── Web.config │ ├── index.html │ └── packages.config ├── DotNETCore-Agent ├── Controllers │ └── ProductsController.cs ├── Models │ ├── ErrorViewModel.cs │ └── Product.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── SampleASPNETCoreApplication.csproj ├── SampleASPNETCoreApplication.sln ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── log4net.config └── wwwroot │ ├── favicon.ico │ └── index.html ├── DotNETCore ├── .ebextensions │ ├── create-dynamodb-table.config │ ├── options.config │ └── xray.config ├── Controllers │ └── ProductsController.cs ├── Models │ ├── ErrorViewModel.cs │ └── Product.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── SampleEBASPNETCoreApplication.csproj ├── SampleEBASPNETCoreApplication.sln ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── aws-beanstalk-tools-defaults.json ├── log4net.config └── wwwroot │ ├── favicon.ico │ └── index.html ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | StyleCop.Cache 2 | # Nuget auto restored packages 3 | packages/ 4 | 5 | # User-specific files 6 | *.suo 7 | *.user 8 | *.sln.docstates 9 | *.vs 10 | # Elastic Beanstalk Files 11 | 12 | .elasticbeanstalk/* 13 | 14 | !.elasticbeanstalk/*.cfg.yml 15 | 16 | !.elasticbeanstalk/*.global.yml 17 | 18 | # Build results 19 | 20 | [Dd]ebug/ 21 | [Rr]elease/ 22 | x64/ 23 | build/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | 27 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 28 | !packages/*/build/ 29 | -------------------------------------------------------------------------------- /DotNET-Agent/SampleWebApplication.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.1209 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApplication", "src\SampleWebApplication.csproj", "{D795CC28-3121-4294-B19B-20986B8F4292}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D795CC28-3121-4294-B19B-20986B8F4292}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D795CC28-3121-4294-B19B-20986B8F4292}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D795CC28-3121-4294-B19B-20986B8F4292}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D795CC28-3121-4294-B19B-20986B8F4292}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E2119FF5-B6C6-4468-B9D4-51A930B7ED0D} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /DotNET-Agent/src/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | 3 | namespace SampleWebApplication 4 | { 5 | public static class WebApiConfig 6 | { 7 | public static void Register(HttpConfiguration config) 8 | { 9 | // Add the message handler to HttpCofiguration 10 | 11 | // Web API routes 12 | config.MapHttpAttributeRoutes(); 13 | 14 | config.Routes.MapHttpRoute( 15 | name: "DefaultApi", 16 | routeTemplate: "api/{controller}/{id}", 17 | defaults: new { id = RouteParameter.Optional } 18 | ); 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DotNET-Agent/src/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.Data.SqlClient; 4 | using System.Net; 5 | using System.Web.Http; 6 | using Amazon; 7 | using Amazon.DynamoDBv2; 8 | using Amazon.DynamoDBv2.DocumentModel; 9 | using Amazon.Util; 10 | using SampleWebApplication.Models; 11 | 12 | namespace SampleWebApplication.Controllers 13 | { 14 | public class ProductsController : ApiController 15 | { 16 | private static readonly Lazy LazyDdbClient = new Lazy(() => 17 | { 18 | var client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); // When running locally, configure with desired region and comment above line of client creation. 19 | return client; 20 | }); 21 | 22 | private static readonly Lazy LazyTable = new Lazy
(() => 23 | { 24 | var tableName = ConfigurationManager.AppSettings["DDB_TABLE_NAME"]; 25 | return Table.LoadTable(LazyDdbClient.Value, tableName); 26 | }); 27 | 28 | public IHttpActionResult GetProduct(int id) 29 | { 30 | try 31 | { 32 | // Trace DynamoDB requests 33 | var product = QueryProduct(id); 34 | 35 | // Trace out-going HTTP request 36 | MakeHttpRequest(); 37 | 38 | // Trace SQL query 39 | // QuerySql(id); 40 | 41 | return Ok(product); 42 | } 43 | catch(ProductNotFoundException) 44 | { 45 | return NotFound(); 46 | } 47 | } 48 | 49 | public IHttpActionResult PostProduct(Product product) 50 | { 51 | try 52 | { 53 | AddProduct(product); 54 | return StatusCode(HttpStatusCode.Created); 55 | } 56 | catch (Exception) 57 | { 58 | return StatusCode(HttpStatusCode.InternalServerError); 59 | } 60 | } 61 | 62 | private void MakeHttpRequest() 63 | { 64 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.amazon.com"); 65 | using (var response = request.GetResponse()) { } 66 | } 67 | 68 | private void QuerySql(int id) 69 | { 70 | var connectionString = ConfigurationManager.AppSettings["RDS_CONNECTION_STRING"]; 71 | using (var sqlConnection = new SqlConnection(connectionString)) 72 | using (var sqlCommand = new SqlCommand("SELECT " + id, sqlConnection)) 73 | { 74 | sqlCommand.Connection.Open(); 75 | sqlCommand.ExecuteNonQuery(); 76 | } 77 | } 78 | 79 | private Product QueryProduct(int id) 80 | { 81 | var item = LazyTable.Value.GetItem(id); 82 | if (item == null) 83 | { 84 | throw new ProductNotFoundException("Can't find a product with id = " + id); 85 | } 86 | 87 | return BuildProduct(item); 88 | } 89 | 90 | private void AddProduct(Product product) 91 | { 92 | var document = new Document(); 93 | document["Id"] = product.Id; 94 | document["Name"] = product.Name; 95 | document["Price"] = product.Price; 96 | 97 | LazyTable.Value.PutItem(document); 98 | } 99 | 100 | private Product BuildProduct(Document document) 101 | { 102 | var product = new Product(); 103 | product.Id = document["Id"].AsInt(); 104 | product.Name = document["Name"].AsString(); 105 | product.Price = document["Price"].AsDecimal(); 106 | return product; 107 | } 108 | 109 | private class ProductNotFoundException : Exception 110 | { 111 | public ProductNotFoundException(string message) : base(message) { } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /DotNET-Agent/src/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="SampleWebApplication.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /DotNET-Agent/src/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | 3 | namespace SampleWebApplication 4 | { 5 | public class WebApiApplication : System.Web.HttpApplication 6 | { 7 | public override void Init() 8 | { 9 | base.Init(); 10 | } 11 | 12 | protected void Application_Start() 13 | { 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DotNET-Agent/src/Models/Product.cs: -------------------------------------------------------------------------------- 1 | namespace SampleWebApplication.Models 2 | { 3 | public class Product 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | public decimal Price { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DotNET-Agent/src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SampleCloudDebuggerApplication")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SampleCloudDebuggerApplication")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4261ea4f-cfd5-4122-afff-6292758e828e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /DotNET-Agent/src/SampleWebApplication.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 9 | 2.0 10 | {D795CC28-3121-4294-B19B-20986B8F4292} 11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 12 | Library 13 | Properties 14 | SampleWebApplication 15 | SampleWebApplication 16 | v4.5 17 | true 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | true 27 | full 28 | false 29 | bin\ 30 | DEBUG;TRACE 31 | prompt 32 | 4 33 | 34 | 35 | pdbonly 36 | true 37 | bin\ 38 | TRACE 39 | prompt 40 | 4 41 | 42 | 43 | 44 | ..\packages\AWSSDK.Core.3.3.107.25\lib\net45\AWSSDK.Core.dll 45 | 46 | 47 | ..\packages\AWSSDK.DynamoDBv2.3.3.106.33\lib\net45\AWSSDK.DynamoDBv2.dll 48 | 49 | 50 | ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll 51 | 52 | 53 | 54 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll 55 | 56 | 57 | 58 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll 71 | 72 | 73 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | Designer 88 | 89 | 90 | 91 | 92 | 93 | 94 | Global.asax 95 | 96 | 97 | 98 | 99 | 100 | 101 | Designer 102 | 103 | 104 | 105 | Web.config 106 | 107 | 108 | Web.config 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 10.0 119 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | True 129 | True 130 | 1162 131 | / 132 | http://localhost:1172/ 133 | False 134 | False 135 | 136 | 137 | False 138 | 139 | 140 | 141 | 142 | 149 | -------------------------------------------------------------------------------- /DotNET-Agent/src/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 |
9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /DotNET-Agent/src/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Product App - .NET 5 | 6 | 7 | 8 |
9 |

Sample App for .NET

10 |

11 |

Get Product by Id

12 | 13 | 14 | 15 |

16 |

17 |
18 |
19 |

Add New Product

20 |

21 | 22 | 23 |

24 |

25 | 26 | 27 |

28 |

29 | 30 | 31 |

32 | 33 | 34 | 35 |
36 | 37 | 38 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /DotNET-Agent/src/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /DotNET/SampleEBWebApplication.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleEBWebApplication", "src\SampleEBWebApplication.csproj", "{D795CC28-3121-4294-B19B-20986B8F4292}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D795CC28-3121-4294-B19B-20986B8F4292}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D795CC28-3121-4294-B19B-20986B8F4292}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D795CC28-3121-4294-B19B-20986B8F4292}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D795CC28-3121-4294-B19B-20986B8F4292}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /DotNET/src/.ebextensions/create-dynamodb-table.config: -------------------------------------------------------------------------------- 1 | Resources: 2 | SampleProduct: 3 | Type: AWS::DynamoDB::Table 4 | Properties: 5 | KeySchema: 6 | HashKeyElement: {AttributeName: Id, AttributeType: N} 7 | ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1} -------------------------------------------------------------------------------- /DotNET/src/.ebextensions/options.config: -------------------------------------------------------------------------------- 1 | option_settings: 2 | aws:elasticbeanstalk:application:environment: 3 | DDB_TABLE_NAME: '`{"Ref" : "SampleProduct"}`' -------------------------------------------------------------------------------- /DotNET/src/.ebextensions/xray.config: -------------------------------------------------------------------------------- 1 | container_commands: 2 | 01-execute-config-scirpt: 3 | command: Powershell.exe -ExecutionPolicy Bypass -File c:\\temp\\installDaemon.ps1 4 | waitAfterCompletion: 0 5 | 6 | files: 7 | "c:/temp/installDaemon.ps1": 8 | content: | 9 | if ( Get-Service "AWSXRayDaemon" -ErrorAction SilentlyContinue ){ 10 | sc.exe stop AWSXRayDaemon 11 | sc.exe delete AWSXRayDaemon 12 | } 13 | if ( Get-Process "AWSXRayDaemon" -ErrorAction SilentlyContinue ){ 14 | Stop-Process -processname "AWSXRayDaemon" -Force -ErrorAction SilentlyContinue 15 | } 16 | if ( Get-Item -path aws-xray-daemon -ErrorAction SilentlyContinue ) { 17 | Remove-Item -Recurse -Force aws-xray-daemon 18 | } 19 | 20 | $currentLocation = "c:\temp" 21 | $zipFileName = "aws-xray-daemon-windows-service-3.x.zip" 22 | $zipPath = "$currentLocation\$zipFileName" 23 | $destPath = "$currentLocation\aws-xray-daemon" 24 | $daemonPath = "$destPath\xray.exe" 25 | $daemonLogPath = "C:\logs\xray-daemon.log" 26 | $url = "https://s3.amazonaws.com/aws-xray-assets.us-east-1/xray-daemon/aws-xray-daemon-windows-service-3.x.zip" 27 | 28 | Invoke-WebRequest -Uri $url -OutFile $zipPath 29 | Add-Type -Assembly "System.IO.Compression.Filesystem" 30 | [io.compression.zipfile]::ExtractToDirectory($zipPath, $destPath) 31 | 32 | sc.exe create AWSXRayDaemon binPath= "$daemonPath -f $daemonLogPath" 33 | sc.exe start AWSXRayDaemon 34 | encoding: plain 35 | "c:/Program Files/Amazon/ElasticBeanstalk/config/taillogs.d/xray-daemon.conf" : 36 | mode: "000644" 37 | owner: root 38 | group: root 39 | content: | 40 | C:\logs\xray-daemon.log 41 | -------------------------------------------------------------------------------- /DotNET/src/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | 3 | namespace SampleEBWebApplication 4 | { 5 | public static class WebApiConfig 6 | { 7 | public static void Register(HttpConfiguration config) 8 | { 9 | // Add the message handler to HttpCofiguration 10 | 11 | // Web API routes 12 | config.MapHttpAttributeRoutes(); 13 | 14 | config.Routes.MapHttpRoute( 15 | name: "DefaultApi", 16 | routeTemplate: "api/{controller}/{id}", 17 | defaults: new { id = RouteParameter.Optional } 18 | ); 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DotNET/src/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.Data.SqlClient; 4 | using System.Net; 5 | using System.Web.Http; 6 | using Amazon; 7 | using Amazon.DynamoDBv2; 8 | using Amazon.DynamoDBv2.DocumentModel; 9 | using Amazon.Util; 10 | using Amazon.XRay.Recorder.Core; 11 | using Amazon.XRay.Recorder.Handlers.SqlServer; 12 | using Amazon.XRay.Recorder.Handlers.System.Net; 13 | using SampleEBWebApplication.Models; 14 | 15 | namespace SampleEBWebApplication.Controllers 16 | { 17 | public class ProductsController : ApiController 18 | { 19 | private static readonly Lazy LazyDdbClient = new Lazy(() => 20 | { 21 | var client = new AmazonDynamoDBClient(EC2InstanceMetadata.Region ?? RegionEndpoint.USWest2); 22 | 23 | // var client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); // When running locally, configure with desired region and comment above line of client creation. 24 | return client; 25 | }); 26 | 27 | private static readonly Lazy
LazyTable = new Lazy
(() => 28 | { 29 | var tableName = ConfigurationManager.AppSettings["DDB_TABLE_NAME"]; 30 | return Table.LoadTable(LazyDdbClient.Value, tableName); 31 | }); 32 | 33 | public IHttpActionResult GetProduct(int id) 34 | { 35 | try 36 | { 37 | // Trace DynamoDB requests 38 | var product = AWSXRayRecorder.Instance.TraceMethod("QueryProduct", () => QueryProduct(id)); 39 | 40 | // Trace out-going HTTP request 41 | AWSXRayRecorder.Instance.TraceMethod("Outgoing Http Request", MakeHttpRequest); 42 | 43 | // Trace SQL query 44 | // AWSXRayRecorder.Instance.TraceMethod("Query SQL", () => QuerySql(id)); 45 | 46 | CustomSubsegment(); // generate custom subsegment 47 | 48 | return Ok(product); 49 | } 50 | catch(ProductNotFoundException) 51 | { 52 | return NotFound(); 53 | } 54 | } 55 | 56 | private void CustomSubsegment() 57 | { 58 | try 59 | { 60 | AWSXRayRecorder.Instance.BeginSubsegment("CustomSubsegment"); 61 | // Custom logic 62 | } 63 | catch (Exception e) 64 | { 65 | AWSXRayRecorder.Instance.AddException(e); 66 | } 67 | finally 68 | { 69 | AWSXRayRecorder.Instance.EndSubsegment(); 70 | } 71 | } 72 | 73 | public IHttpActionResult PostProduct(Product product) 74 | { 75 | try 76 | { 77 | AWSXRayRecorder.Instance.TraceMethod("AddProduct", () => AddProduct(product)); 78 | return StatusCode(HttpStatusCode.Created); 79 | } 80 | catch (Exception) 81 | { 82 | return StatusCode(HttpStatusCode.InternalServerError); 83 | } 84 | } 85 | 86 | private void MakeHttpRequest() 87 | { 88 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.amazon.com"); 89 | request.GetResponseTraced(); 90 | } 91 | 92 | private void QuerySql(int id) 93 | { 94 | var connectionString = ConfigurationManager.AppSettings["RDS_CONNECTION_STRING"]; 95 | using (var sqlConnection = new SqlConnection(connectionString)) 96 | using (var sqlCommand = new TraceableSqlCommand("SELECT " + id, sqlConnection)) 97 | { 98 | sqlCommand.Connection.Open(); 99 | sqlCommand.ExecuteNonQuery(); 100 | } 101 | } 102 | 103 | private Product QueryProduct(int id) 104 | { 105 | var item = LazyTable.Value.GetItem(id); 106 | if (item == null) 107 | { 108 | throw new ProductNotFoundException("Can't find a product with id = " + id); 109 | } 110 | 111 | return BuildProduct(item); 112 | } 113 | 114 | private void AddProduct(Product product) 115 | { 116 | var document = new Document(); 117 | document["Id"] = product.Id; 118 | document["Name"] = product.Name; 119 | document["Price"] = product.Price; 120 | 121 | LazyTable.Value.PutItem(document); 122 | } 123 | 124 | private Product BuildProduct(Document document) 125 | { 126 | var product = new Product(); 127 | product.Id = document["Id"].AsInt(); 128 | product.Name = document["Name"].AsString(); 129 | product.Price = document["Price"].AsDecimal(); 130 | return product; 131 | } 132 | 133 | private class ProductNotFoundException : Exception 134 | { 135 | public ProductNotFoundException(string message) : base(message) { } 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /DotNET/src/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="SampleEBWebApplication.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /DotNET/src/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using Amazon.XRay.Recorder.Handlers.AspNet; 2 | using Amazon.XRay.Recorder.Handlers.AwsSdk; 3 | using System.Web.Http; 4 | 5 | namespace SampleEBWebApplication 6 | { 7 | public class WebApiApplication : System.Web.HttpApplication 8 | { 9 | public override void Init() 10 | { 11 | base.Init(); 12 | AWSXRayASPNET.RegisterXRay(this, "ASPNETSampleApp"); // Configuring web app with X-Ray 13 | AWSSDKHandler.RegisterXRayForAllServices(); // Configure AWS SDK Handler for X-Ray 14 | } 15 | protected void Application_Start() 16 | { 17 | GlobalConfiguration.Configure(WebApiConfig.Register); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DotNET/src/Models/Product.cs: -------------------------------------------------------------------------------- 1 | namespace SampleEBWebApplication.Models 2 | { 3 | public class Product 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | public decimal Price { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /DotNET/src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SampleCloudDebuggerApplication")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SampleCloudDebuggerApplication")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4261ea4f-cfd5-4122-afff-6292758e828e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /DotNET/src/SampleEBWebApplication.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 9 | 2.0 10 | {D795CC28-3121-4294-B19B-20986B8F4292} 11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 12 | Library 13 | Properties 14 | SampleEBWebApplication 15 | SampleEBWebApplication 16 | v4.5 17 | true 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | true 27 | full 28 | false 29 | bin\ 30 | DEBUG;TRACE 31 | prompt 32 | 4 33 | 34 | 35 | pdbonly 36 | true 37 | bin\ 38 | TRACE 39 | prompt 40 | 4 41 | 42 | 43 | 44 | ..\packages\AWSSDK.Core.3.3.31.6\lib\net45\AWSSDK.Core.dll 45 | 46 | 47 | ..\packages\AWSSDK.DynamoDBv2.3.3.17.4\lib\net45\AWSSDK.DynamoDBv2.dll 48 | 49 | 50 | ..\packages\AWSSDK.XRay.3.3.5.15\lib\net45\AWSSDK.XRay.dll 51 | 52 | 53 | ..\packages\AWSXRayRecorder.Core.2.5.0\lib\net45\AWSXRayRecorder.Core.dll 54 | 55 | 56 | ..\packages\AWSXRayRecorder.Handlers.AspNet.2.5.0\lib\net45\AWSXRayRecorder.Handlers.AspNet.dll 57 | 58 | 59 | ..\packages\AWSXRayRecorder.Handlers.AwsSdk.2.5.0\lib\net45\AWSXRayRecorder.Handlers.AwsSdk.dll 60 | 61 | 62 | ..\packages\AWSXRayRecorder.Handlers.SqlServer.2.5.0\lib\net45\AWSXRayRecorder.Handlers.SqlServer.dll 63 | 64 | 65 | ..\packages\AWSXRayRecorder.Handlers.System.Net.2.5.0\lib\net45\AWSXRayRecorder.Handlers.System.Net.dll 66 | 67 | 68 | ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll 69 | 70 | 71 | 72 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll 73 | 74 | 75 | 76 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll 89 | 90 | 91 | ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | Designer 104 | 105 | 106 | 107 | 108 | Designer 109 | 110 | 111 | 112 | 113 | 114 | 115 | Global.asax 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | Designer 125 | 126 | 127 | Web.config 128 | 129 | 130 | Web.config 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 10.0 142 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | True 152 | True 153 | 1162 154 | / 155 | http://localhost:1172/ 156 | False 157 | False 158 | 159 | 160 | False 161 | 162 | 163 | 164 | 165 | 172 | -------------------------------------------------------------------------------- /DotNET/src/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 |
9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /DotNET/src/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Product App - .NET 5 | 6 | 7 | 8 |
9 |

Sample App for .NET

10 |

11 |

Get Product by Id

12 | 13 | 14 | 15 |

16 |

17 |
18 |
19 |

Add New Product

20 |

21 | 22 | 23 |

24 |

25 | 26 | 27 |

28 |

29 | 30 | 31 |

32 | 33 | 34 | 35 |
36 | 37 | 38 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /DotNET/src/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /DotNETCore-Agent/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.SqlClient; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using Amazon; 7 | using Amazon.DynamoDBv2; 8 | using Amazon.DynamoDBv2.DocumentModel; 9 | using Amazon.Util; 10 | using Microsoft.AspNetCore.Mvc; 11 | using SampleASPNETCoreApplication.Models; 12 | 13 | namespace SampleASPNETCoreApplication.Controllers 14 | { 15 | [Produces("application/json")] 16 | [Route("api/Products")] 17 | public class ProductsController : Controller 18 | { 19 | static ProductsController() 20 | { 21 | 22 | LazyDdbClient = new Lazy(() => 23 | { 24 | var client = new AmazonDynamoDBClient(RegionEndpoint.USEast1); // When running locally, configure with desired region and comment above line of client creation. 25 | 26 | return client; 27 | }); 28 | 29 | LazyTable = new Lazy
(() => 30 | { 31 | var tableName = "SampleProduct"; 32 | return Table.LoadTable(LazyDdbClient.Value, tableName); 33 | }); 34 | 35 | } 36 | 37 | private static readonly Lazy LazyDdbClient; 38 | private static readonly Lazy
LazyTable; 39 | 40 | // GET: api/Products 41 | [HttpGet] 42 | public IEnumerable Get() 43 | { 44 | return new string[] { "value1", "value2" }; 45 | } 46 | 47 | // GET: api/Products/5 48 | [HttpGet("{id}", Name = "Get")] 49 | public string Get(int id) 50 | { 51 | try 52 | { 53 | var product = QueryProduct(id); 54 | 55 | // Trace out-going HTTP request 56 | MakeHttpWebRequest(id); 57 | 58 | // Trace SQL query 59 | // QuerySql(id); 60 | 61 | return product.ToString();// Ok(product); 62 | } 63 | catch (ProductNotFoundException e) 64 | { 65 | return "Product not found !";// NotFound(); 66 | } 67 | } 68 | 69 | // POST: api/Products 70 | [HttpPost] 71 | public void Post(Product product)//[FromBody]string value) 72 | { 73 | AddProduct(product).Wait(); 74 | } 75 | 76 | // PUT: api/Products/5 77 | [HttpPut("{id}")] 78 | public void Put(int id, [FromBody]string value) 79 | { 80 | } 81 | 82 | private static void MakeHttpWebRequest(int id) 83 | { 84 | HttpWebRequest request = null; 85 | request = (HttpWebRequest) WebRequest.Create("http://www.amazon.com"); 86 | using (var response = request.GetResponse()) { } 87 | } 88 | 89 | private Product QueryProduct(int id) 90 | { 91 | var item = LazyTable.Value.GetItemAsync(id).Result; 92 | if (item == null) 93 | { 94 | throw new ProductNotFoundException("Can't find a product with id = " + id); 95 | } 96 | 97 | return BuildProduct(item); 98 | } 99 | 100 | private async Task AddProduct(Product product) 101 | { 102 | var document = new Document(); 103 | document["Id"] = product.Id; 104 | document["Name"] = product.Name; 105 | document["Price"] = product.Price; 106 | 107 | return await LazyTable.Value.PutItemAsync(document); 108 | } 109 | 110 | private Product BuildProduct(Document document) 111 | { 112 | var product = new Product(); 113 | product.Id = document["Id"].AsInt(); 114 | product.Name = document["Name"].AsString(); 115 | product.Price = document["Price"].AsDecimal(); 116 | return product; 117 | } 118 | 119 | private void QuerySql(int id) 120 | { 121 | var connectionString = ""; // Configure Connection string -> Format : "Data Source=(RDS endpoint),(port number);User ID=(your user name);Password=(your password);" 122 | using (var sqlConnection = new SqlConnection(connectionString)) 123 | using (var sqlCommand = new SqlCommand("SELECT " + id, sqlConnection)) 124 | { 125 | sqlCommand.Connection.Open(); 126 | sqlCommand.ExecuteNonQuery(); 127 | } 128 | } 129 | 130 | private class ProductNotFoundException : Exception 131 | { 132 | public ProductNotFoundException(string message) : base(message) { } 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /DotNETCore-Agent/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SampleASPNETCoreApplication.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DotNETCore-Agent/Models/Product.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace SampleASPNETCoreApplication.Models 3 | { 4 | public class Product 5 | { 6 | public int Id { get; set; } 7 | public string Name { get; set; } 8 | public decimal Price { get; set; } 9 | public override string ToString() 10 | { 11 | return "Product Found: " + " Name: " + Name + " Price: " + Price; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DotNETCore-Agent/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace SampleASPNETCoreApplication 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DotNETCore-Agent/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:64944/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "index.html", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "SampleASPNETCoreApplication": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "index.html", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:64945/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DotNETCore-Agent/SampleASPNETCoreApplication.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /DotNETCore-Agent/SampleASPNETCoreApplication.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2018 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleASPNETCoreApplication", "SampleASPNETCoreApplication.csproj", "{C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7502934A-781E-4425-93E5-7239D3B4776F} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /DotNETCore-Agent/Startup.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Reflection; 3 | using log4net; 4 | using log4net.Config; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace SampleASPNETCoreApplication 11 | { 12 | public class Startup 13 | { 14 | public static ILog log; 15 | public IConfiguration Configuration { get; } 16 | 17 | static Startup() // create log4j instance 18 | { 19 | var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); 20 | XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); 21 | log = LogManager.GetLogger(typeof(Startup)); 22 | } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddMvc(); 28 | } 29 | 30 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 31 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 32 | { 33 | 34 | if (env.IsDevelopment()) 35 | { 36 | app.UseDeveloperExceptionPage(); 37 | app.UseBrowserLink(); 38 | } 39 | else 40 | { 41 | app.UseExceptionHandler("/Home/Error"); 42 | } 43 | app.UseStaticFiles(); 44 | app.UseMvc(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /DotNETCore-Agent/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DotNETCore-Agent/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "XRay": { 9 | "DisableXRayTracing": "false", 10 | "AWSXRayPlugins": "EC2Plugin", 11 | "UseRuntimeErrors": "true", 12 | "ServiceName": "SampleAspNetCoreForAgent" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DotNETCore-Agent/log4net.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /DotNETCore-Agent/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-xray-dotnet-webapp/58593dd269754bc60d9c4af508a8b9ec302b564b/DotNETCore-Agent/wwwroot/favicon.ico -------------------------------------------------------------------------------- /DotNETCore-Agent/wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Product App - .NET Core 5 | 6 | 7 | 8 |
9 |

Sample App for .NET Core

10 |

11 |

Get Product by Id

12 | 13 | 14 | 15 |

16 |

17 |
18 |
19 |

Add New Product

20 |

21 | 22 | 23 |

24 |

25 | 26 | 27 |

28 |

29 | 30 | 31 |

32 | 33 | 34 | 35 |
36 | 37 | 38 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /DotNETCore/.ebextensions/create-dynamodb-table.config: -------------------------------------------------------------------------------- 1 | Resources: 2 | SampleProduct: 3 | Type: AWS::DynamoDB::Table 4 | Properties: 5 | TableName: SampleProduct 6 | KeySchema: 7 | HashKeyElement: {AttributeName: Id, AttributeType: N} 8 | ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1} -------------------------------------------------------------------------------- /DotNETCore/.ebextensions/options.config: -------------------------------------------------------------------------------- 1 | option_settings: 2 | aws:elasticbeanstalk:application:environment: 3 | DDB_TABLE_NAME: '`{"Ref" : "SampleProduct"}`' -------------------------------------------------------------------------------- /DotNETCore/.ebextensions/xray.config: -------------------------------------------------------------------------------- 1 | container_commands: 2 | 01-execute-config-scirpt: 3 | command: Powershell.exe -ExecutionPolicy Bypass -File c:\\temp\\installDaemon.ps1 4 | waitAfterCompletion: 0 5 | 6 | files: 7 | "c:/temp/installDaemon.ps1": 8 | content: | 9 | if ( Get-Service "AWSXRayDaemon" -ErrorAction SilentlyContinue ){ 10 | sc.exe stop AWSXRayDaemon 11 | sc.exe delete AWSXRayDaemon 12 | } 13 | if ( Get-Process "AWSXRayDaemon" -ErrorAction SilentlyContinue ){ 14 | Stop-Process -processname "AWSXRayDaemon" -Force -ErrorAction SilentlyContinue 15 | } 16 | if ( Get-Item -path aws-xray-daemon -ErrorAction SilentlyContinue ) { 17 | Remove-Item -Recurse -Force aws-xray-daemon 18 | } 19 | 20 | $currentLocation = "c:\temp" 21 | $zipFileName = "aws-xray-daemon-windows-service-3.x.zip" 22 | $zipPath = "$currentLocation\$zipFileName" 23 | $destPath = "$currentLocation\aws-xray-daemon" 24 | $daemonPath = "$destPath\xray.exe" 25 | $daemonLogPath = "C:\logs\xray-daemon.log" 26 | $url = "https://s3.amazonaws.com/aws-xray-assets.us-east-1/xray-daemon/aws-xray-daemon-windows-service-3.x.zip" 27 | 28 | Invoke-WebRequest -Uri $url -OutFile $zipPath 29 | Add-Type -Assembly "System.IO.Compression.Filesystem" 30 | [io.compression.zipfile]::ExtractToDirectory($zipPath, $destPath) 31 | 32 | sc.exe create AWSXRayDaemon binPath= "$daemonPath -f $daemonLogPath" 33 | sc.exe start AWSXRayDaemon 34 | encoding: plain 35 | "c:/Program Files/Amazon/ElasticBeanstalk/config/taillogs.d/xray-daemon.conf" : 36 | mode: "000644" 37 | owner: root 38 | group: root 39 | content: | 40 | C:\logs\xray-daemon.log -------------------------------------------------------------------------------- /DotNETCore/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.SqlClient; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using Amazon; 7 | using Amazon.DynamoDBv2; 8 | using Amazon.DynamoDBv2.DocumentModel; 9 | using Amazon.Util; 10 | using Amazon.XRay.Recorder.Core; 11 | using Amazon.XRay.Recorder.Handlers.SqlServer; 12 | using Amazon.XRay.Recorder.Handlers.System.Net; 13 | using Microsoft.AspNetCore.Mvc; 14 | using SampleEBASPNETCoreApplication.Models; 15 | 16 | namespace SampleEBASPNETCoreApplication.Controllers 17 | { 18 | [Produces("application/json")] 19 | [Route("api/Products")] 20 | public class ProductsController : Controller 21 | { 22 | static ProductsController() 23 | { 24 | 25 | LazyDdbClient = new Lazy(() => 26 | { 27 | var client = new AmazonDynamoDBClient(EC2InstanceMetadata.Region ?? RegionEndpoint.USWest2); 28 | 29 | //var client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); // When running locally, configure with desired region and comment above line of client creation. 30 | 31 | return client; 32 | }); 33 | 34 | LazyTable = new Lazy
(() => 35 | { 36 | var tableName = "SampleProduct"; 37 | return Table.LoadTable(LazyDdbClient.Value, tableName); 38 | }); 39 | 40 | } 41 | private static readonly Lazy LazyDdbClient; 42 | private static readonly Lazy
LazyTable; 43 | // GET: api/Products 44 | [HttpGet] 45 | public IEnumerable Get() 46 | { 47 | return new string[] { "value1", "value2" }; 48 | } 49 | 50 | // GET: api/Products/5 51 | [HttpGet("{id}", Name = "Get")] 52 | public string Get(int id) 53 | { 54 | try 55 | { 56 | AWSXRayRecorder.Instance.AddAnnotation("Get", id); 57 | 58 | var product = AWSXRayRecorder.Instance.TraceMethod("QueryProduct", () => QueryProduct(id)); 59 | 60 | // Trace out-going HTTP request 61 | AWSXRayRecorder.Instance.TraceMethod("Outgoing Http Web Request", () => MakeHttpWebRequest(id)); 62 | 63 | CustomSubsegment(); // create custom Subsegment 64 | 65 | // Trace SQL query 66 | // AWSXRayRecorder.Instance.TraceMethod("Query SQL", () => QuerySql(id)); 67 | 68 | return product.ToString();// Ok(product); 69 | } 70 | catch (ProductNotFoundException e) 71 | { 72 | return "Product not found !";// NotFound(); 73 | } 74 | } 75 | 76 | private void CustomSubsegment() 77 | { 78 | try 79 | { 80 | AWSXRayRecorder.Instance.BeginSubsegment("CustomSubsegment"); 81 | // business logic 82 | } 83 | catch (Exception e) 84 | { 85 | AWSXRayRecorder.Instance.AddException(e); 86 | } 87 | finally 88 | { 89 | AWSXRayRecorder.Instance.EndSubsegment(); 90 | } 91 | } 92 | 93 | // POST: api/Products 94 | [HttpPost] 95 | public void Post(Product product)//[FromBody]string value) 96 | { 97 | AWSXRayRecorder.Instance.TraceMethodAsync("AddProduct", () => AddProduct(product)); 98 | } 99 | 100 | // PUT: api/Products/5 101 | [HttpPut("{id}")] 102 | public void Put(int id, [FromBody]string value) 103 | { 104 | } 105 | private static void MakeHttpWebRequest(int id) 106 | { 107 | AWSXRayRecorder.Instance.AddAnnotation("WebRequestCall", id); 108 | HttpWebRequest request = null; 109 | request = (HttpWebRequest) WebRequest.Create("http://www.amazon.com"); 110 | request.GetResponseTraced(); 111 | } 112 | 113 | private Product QueryProduct(int id) 114 | { 115 | var item = LazyTable.Value.GetItemAsync(id).Result; 116 | if (item == null) 117 | { 118 | throw new ProductNotFoundException("Can't find a product with id = " + id); 119 | } 120 | 121 | return BuildProduct(item); 122 | } 123 | 124 | private async Task AddProduct(Product product) 125 | { 126 | var document = new Document(); 127 | document["Id"] = product.Id; 128 | document["Name"] = product.Name; 129 | document["Price"] = product.Price; 130 | 131 | return await LazyTable.Value.PutItemAsync(document); 132 | } 133 | 134 | private Product BuildProduct(Document document) 135 | { 136 | var product = new Product(); 137 | product.Id = document["Id"].AsInt(); 138 | product.Name = document["Name"].AsString(); 139 | product.Price = document["Price"].AsDecimal(); 140 | return product; 141 | } 142 | 143 | private void QuerySql(int id) 144 | { 145 | var connectionString = ""; // Configure Connection string -> Format : "Data Source=(RDS endpoint),(port number);User ID=(your user name);Password=(your password);" 146 | using (var sqlConnection = new SqlConnection(connectionString)) 147 | using (var sqlCommand = new TraceableSqlCommand("SELECT " + id, sqlConnection)) 148 | { 149 | sqlCommand.Connection.Open(); 150 | sqlCommand.ExecuteNonQuery(); 151 | } 152 | } 153 | private class ProductNotFoundException : Exception 154 | { 155 | public ProductNotFoundException(string message) : base(message) { } 156 | } 157 | } 158 | } -------------------------------------------------------------------------------- /DotNETCore/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SAmpleEBASPNETCoreApplication.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } -------------------------------------------------------------------------------- /DotNETCore/Models/Product.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace SampleEBASPNETCoreApplication.Models 3 | { 4 | public class Product 5 | { 6 | public int Id { get; set; } 7 | public string Name { get; set; } 8 | public decimal Price { get; set; } 9 | public override string ToString() 10 | { 11 | return "Product Found: " + " Name: " + Name + " Price: " + Price; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DotNETCore/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace SAmpleEBASPNETCoreApplication 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DotNETCore/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:64944/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "index.html", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "SAmpleEBASPNETCoreApplication": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "index.html", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:64945/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DotNETCore/SampleEBASPNETCoreApplication.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | PreserveNewest 33 | 34 | 35 | PreserveNewest 36 | 37 | 38 | PreserveNewest 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /DotNETCore/SampleEBASPNETCoreApplication.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2018 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleEBASPNETCoreApplication", "SampleEBASPNETCoreApplication.csproj", "{C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C1AF87D4-B0DB-41B0-8D7C-CCD075092E3E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7502934A-781E-4425-93E5-7239D3B4776F} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /DotNETCore/Startup.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Reflection; 3 | using Amazon; 4 | using Amazon.XRay.Recorder.Core; 5 | using Amazon.XRay.Recorder.Handlers.AwsSdk; 6 | using log4net; 7 | using log4net.Config; 8 | using Microsoft.AspNetCore.Builder; 9 | using Microsoft.AspNetCore.Hosting; 10 | using Microsoft.Extensions.Configuration; 11 | using Microsoft.Extensions.DependencyInjection; 12 | 13 | namespace SAmpleEBASPNETCoreApplication 14 | { 15 | public class Startup 16 | { 17 | public static ILog log; 18 | public IConfiguration Configuration { get; } 19 | 20 | static Startup() // create log4j instance 21 | { 22 | var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); 23 | XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); 24 | log = LogManager.GetLogger(typeof(Startup)); 25 | AWSXRayRecorder.RegisterLogger(LoggingOptions.Log4Net); 26 | } 27 | 28 | 29 | public Startup(IConfiguration configuration) 30 | { 31 | AWSXRayRecorder.InitializeInstance(configuration: Configuration); // Inititalizing Configuration object with X-Ray recorder 32 | AWSSDKHandler.RegisterXRayForAllServices(); // All AWS SDK requests will be traced 33 | } 34 | 35 | // This method gets called by the runtime. Use this method to add services to the container. 36 | public void ConfigureServices(IServiceCollection services) 37 | { 38 | services.AddMvc(); 39 | } 40 | 41 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 42 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 43 | { 44 | 45 | if (env.IsDevelopment()) 46 | { 47 | app.UseDeveloperExceptionPage(); 48 | app.UseBrowserLink(); 49 | } 50 | else 51 | { 52 | app.UseExceptionHandler("/Home/Error"); 53 | } 54 | app.UseXRay("ASPNETCoreSampleApp"); // Integrate ASPNETCore app with X-Ray 55 | app.UseStaticFiles(); 56 | app.UseMvc(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DotNETCore/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DotNETCore/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "XRay": { 9 | "DisableXRayTracing": "false", 10 | "AWSXRayPlugins": "EC2Plugin", 11 | "UseRuntimeErrors": "true" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DotNETCore/aws-beanstalk-tools-defaults.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "comment" : "This file is used to help set default values when using the dotnet CLI extension Amazon.ElasticBeanstalk.Tools. For more information run \"dotnet eb --help\" from the project root.", 4 | "profile" : "default", 5 | "region" : "us-west-2", 6 | "application" : "SampleEBASPNETCoreApplication", 7 | "environment" : "ttttttttttt", 8 | "cname" : "ttttttttttt", 9 | "solution-stack" : "64bit Windows Server 2016 v1.2.0 running IIS 10.0", 10 | "environment-type" : "SingleInstance", 11 | "instance-profile" : "AdminDynamo", 12 | "service-role" : "aws-elasticbeanstalk-service-role", 13 | "health-check-url" : "/", 14 | "instance-type" : "t2.micro", 15 | "key-pair" : "daemon", 16 | "iis-website" : "Default Web Site", 17 | "app-path" : "/", 18 | "enable-xray" : true 19 | } -------------------------------------------------------------------------------- /DotNETCore/log4net.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /DotNETCore/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-xray-dotnet-webapp/58593dd269754bc60d9c4af508a8b9ec302b564b/DotNETCore/wwwroot/favicon.ico -------------------------------------------------------------------------------- /DotNETCore/wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Product App - .NET Core 5 | 6 | 7 | 8 |
9 |

Sample App for .NET Core

10 |

11 |

Get Product by Id

12 | 13 | 14 | 15 |

16 |

17 |
18 |
19 |

Add New Product

20 |

21 | 22 | 23 |

24 |

25 | 26 | 27 |

28 |

29 | 30 | 31 |

32 | 33 | 34 | 35 |
36 | 37 | 38 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aws-xray-dotnet-webapp 2 | 3 | Folder `DotNET` and `DotNETCore` contains ASP.NET and ASP.NET Core applications that have been instrumented for [AWS X-Ray](https://aws.amazon.com/xray/) and are written to be deployed with Elastic Beanstalk or run locally. 4 | 5 | Folder `DotNET-Agent` and `DotNETCore-Agent` contains ASP.NET and ASP.NET Core applications that are for [AWS X-Ray .NET Agent](https://github.com/aws/aws-xray-dotnet-agent) and are written to run locally. 6 | 7 | ## How to Run The App for X-Ray .NET SDK 8 | 9 | ### Elastic beanstalk 10 | 11 | ##### *Deploy* 12 | 13 | 1. Attach an IAM role to your EC2 instance with the [policy](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/README.md#policy) 14 | 2. Deploy the application to Elastic Beanstalk. [Steps](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_NET.quickstart.html#aws-elastic-beanstalk-tutorial-step-2-publish-application) 15 | 3. Configure Sampling Rules in the [AWS X-Ray Console](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-sampling.html) 16 | 17 | ##### *EbExtensions* 18 | 19 | The App uses .ebextensions to setup AWS resources and configuration, which includes: 20 | 21 | 1. Create a DynamoDB table with name `SampleProduct` 22 | 2. Set an application config DDB_TABLE_NAME with the create DynamoDB table name 23 | 3. Install AWS X-Ray daemon as a [Windows service](https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-local.html) 24 | 25 | ### Locally 26 | 27 | 1. AWS Credentials on the local box should have the [policy](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/README.md#policy) 28 | 2. Create a DynamoDB table with name `SampleProduct` in the desired region. The partion key for the table should be `Id` and of type `Number`. 29 | 3. Install AWS X-Ray daemon as a [Windows service](https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-local.html) 30 | 4. Comment DDB client creation for [.NET](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNET/src/Controllers/ProductsController.cs#L21) and [.NET Core](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNETCore/Controllers/ProductsController.cs#L27), which is used for Elasticbeanstalk and uncomment line for [.NET](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNET/src/Controllers/ProductsController.cs#L23) and [.NET Core](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNETCore/Controllers/ProductsController.cs#L29) 31 | 5. Make sure, the region is same for DDB table on the AWS console and DDB client in the code for [.NET](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNET/src/Controllers/ProductsController.cs#L23) and [.NETCore](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNETCore/Controllers/ProductsController.cs#L29) 32 | 6. Configure Sampling Rules in the [AWS X-Ray Console](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-sampling.html). 33 | 7. The X-Ray daemon running locally should be configured in the same region as that of sampling rules through X-Ray console 34 | 35 | ### Enable SQL query (optional) 36 | 37 | 1. By default, SQL query is disabled. 38 | 2. Create a RDS SQL Server DB instance. [Steps](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.SQLServer.html#CHAP_GettingStarted.Creating.SQLServer) 39 | 3. Construct the connection string for SQL Server `"Data Source=(RDS endpoint),(port number);User ID=(your user name);Password=(your password);"` 40 | 4. Fill it into web.config key "RDS_CONNECTION_STRING" for [.NET](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNET/src/Web.config#L38) and fill the string for [.NETCore](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNETCore/Controllers/ProductsController.cs#L142) 41 | 5. Uncomment call to `QuerySql()` for [.NET](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNET/src/Controllers/ProductsController.cs#L42) and [.NETCore](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNETCore/Controllers/ProductsController.cs#L64) 42 | 43 | ## How to Run The App for X-Ray .NET Agent 44 | 45 | Sample apps for .NET Agent are identical to the ones for .NET SDK, except that the later have been instrumented with X-Ray .NET SDK, while the former are not. 46 | 47 | You can install .NET Agent to automatically instrument .NET SDK into the sample applications by following the requirement and steps below. 48 | 49 | ### Requirement 50 | 51 | 1. AWS Credentials on the local box should have the [policy](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/README.md#policy) 52 | 2. Create a DynamoDB table with name `SampleProduct` in the desired region. The partion key for the table should be `Id` and of type `Number`. 53 | 3. Install AWS X-Ray daemon as a [Windows service](https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-local.html) 54 | 4. Make sure, the region is same for DDB table on the AWS console and DDB client in the code for [.NET](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNET-Agent/src/Controllers/ProductsController.cs#L18) and [.NETCore](https://github.com/aws-samples/aws-xray-dotnet-webapp/blob/master/DotNETCore-Agent/Controllers/ProductsController.cs#L24) 55 | 5. Configure Sampling Rules in the [AWS X-Ray Console](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-sampling.html). 56 | 6. The X-Ray daemon running locally should be configured in the same region as that of sampling rules through X-Ray console 57 | 7. If host sample application on IIS, make sure you follow the instructions [here](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1) to complete the setups and configurations before installing .NET Agent. 58 | 59 | ### Installation 60 | 61 | Below are the general steps to install .NET Agent. For more information, please take reference to [page](https://github.com/aws/aws-xray-dotnet-agent). 62 | 63 | 1. Make sure you meet the [prerequisites](https://github.com/aws/aws-xray-dotnet-agent#prerequisites) and [minimum requirements](https://github.com/aws/aws-xray-dotnet-agent#minimum-requirements) for using/building the .NET agent. 64 | 2. Follow the [steps](https://github.com/aws/aws-xray-dotnet-agent#internet-information-services-iis) if you're running on IIS or [steps](https://github.com/aws/aws-xray-dotnet-agent#others-not-iis) otherwise on how to install X-Ray .NET Agent for your apps. 65 | 3. Launch your application, open the web link in the browser, perform some operations, and you can see traces in the AWS X-Ray Console. 66 | 67 | ## URL for the Apps 68 | 69 | Access the application : /index.html. 70 | 71 | ## Policy 72 | 73 | ```json 74 | { 75 | "Version": "2012-10-17", 76 | "Statement": [ 77 | { 78 | "Action": [ 79 | "sns:Publish", 80 | "xray:PutTraceSegments", 81 | "xray:PutTelemetryRecords", 82 | "xray:GetSamplingRules", 83 | "xray:GetSamplingTargets", 84 | "xray:GetSamplingStatisticSummaries", 85 | "dynamodb:PutItem", 86 | "dynamodb:GetItem", 87 | "dynamodb:DescribeTable" 88 | ], 89 | "Resource": [ 90 | "*" 91 | ], 92 | "Effect": "Allow" 93 | } 94 | ] 95 | } 96 | ``` 97 | 98 | ## Documentation 99 | 100 | 1. Code repository for [AWS X-Ray .NET SDK](https://github.com/aws/aws-xray-sdk-dotnet) and for [AWS X-Ray .NET Agent](https://github.com/aws/aws-xray-dotnet-agent) 101 | 2. AWS Documentation for using X-Ray .NET SDK and X-Ray .NET Agent can be found [here](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet.html) 102 | 103 | ## FAQ 104 | 105 | 1. What to do if I get an "Error: Internal Server Error"? 106 | * You can use AWS X-Ray to debug this. Go to AWS X-Ray console and find the failed trace, and look for Exception. Probably because you EC2 instance don't have the enough permission to access DynamoDB or RDS DB instance. 107 | 108 | --------------------------------------------------------------------------------