Awesome
aws-xray-dotnet-webapp
Folder DotNET
and DotNETCore
contains ASP.NET and ASP.NET Core applications that have been instrumented for AWS X-Ray and are written to be deployed with Elastic Beanstalk or run locally.
Folder DotNET-Agent
and DotNETCore-Agent
contains ASP.NET and ASP.NET Core applications that are for AWS X-Ray .NET Agent and are written to run locally.
How to Run The App for X-Ray .NET SDK
Elastic beanstalk
Deploy
- Attach an IAM role to your EC2 instance with the policy
- Deploy the application to Elastic Beanstalk. Steps
- Configure Sampling Rules in the AWS X-Ray Console
EbExtensions
The App uses .ebextensions to setup AWS resources and configuration, which includes:
- Create a DynamoDB table with name
SampleProduct
- Set an application config DDB_TABLE_NAME with the create DynamoDB table name
- Install AWS X-Ray daemon as a Windows service
Locally
- AWS Credentials on the local box should have the policy
- Create a DynamoDB table with name
SampleProduct
in the desired region. The partion key for the table should beId
and of typeNumber
. - Install AWS X-Ray daemon as a Windows service
- Comment DDB client creation for .NET and .NET Core, which is used for Elasticbeanstalk and uncomment line for .NET and .NET Core
- Make sure, the region is same for DDB table on the AWS console and DDB client in the code for .NET and .NETCore
- Configure Sampling Rules in the AWS X-Ray Console.
- The X-Ray daemon running locally should be configured in the same region as that of sampling rules through X-Ray console
Enable SQL query (optional)
- By default, SQL query is disabled.
- Create a RDS SQL Server DB instance. Steps
- Construct the connection string for SQL Server
"Data Source=(RDS endpoint),(port number);User ID=(your user name);Password=(your password);"
- Fill it into web.config key "RDS_CONNECTION_STRING" for .NET and fill the string for .NETCore
- Uncomment call to
QuerySql()
for .NET and .NETCore
How to Run The App for X-Ray .NET Agent
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.
You can install .NET Agent to automatically instrument .NET SDK into the sample applications by following the requirement and steps below.
Requirement
- AWS Credentials on the local box should have the policy
- Create a DynamoDB table with name
SampleProduct
in the desired region. The partion key for the table should beId
and of typeNumber
. - Install AWS X-Ray daemon as a Windows service
- Make sure, the region is same for DDB table on the AWS console and DDB client in the code for .NET and .NETCore
- Configure Sampling Rules in the AWS X-Ray Console.
- The X-Ray daemon running locally should be configured in the same region as that of sampling rules through X-Ray console
- If host sample application on IIS, make sure you follow the instructions here to complete the setups and configurations before installing .NET Agent.
Installation
Below are the general steps to install .NET Agent. For more information, please take reference to page.
- Make sure you meet the prerequisites and minimum requirements for using/building the .NET agent.
- Follow the steps if you're running on IIS or steps otherwise on how to install X-Ray .NET Agent for your apps.
- Launch your application, open the web link in the browser, perform some operations, and you can see traces in the AWS X-Ray Console.
URL for the Apps
Access the application : <Default_URL>/index.html.
Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sns:Publish",
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:DescribeTable"
],
"Resource": [
"*"
],
"Effect": "Allow"
}
]
}
Documentation
- Code repository for AWS X-Ray .NET SDK and for AWS X-Ray .NET Agent
- AWS Documentation for using X-Ray .NET SDK and X-Ray .NET Agent can be found here
FAQ
- What to do if I get an "Error: Internal Server Error"?
- 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.