1. 程式人生 > >New AWS X-Ray .NET Core Support

New AWS X-Ray .NET Core Support

In our AWS re:Invent talk this year, we preannounced support for .NET Core 2.0 with AWS Lambda and support for .NET Core 2.0 with AWS X-Ray. Last month we released the AWS Lambda support for .NET Core 2.0. This week we released the AWS X-Ray support for .NET Core 2.0, with new 2.0 beta versions of the AWS X-Ray SDK for .NET NuGet packages.

AWS X-Ray is a service that collects data about requests that your application serves. X-Ray provides tools you can use to view, filter, and gain insights into that data to identify issues and opportunities for optimization. For any traced request to your application, you can see detailed information in the

AWS X-Ray console. This includes information not only about the request and response, but also about calls that your application makes to downstream AWS resources, microservices, databases, and HTTP web APIs.

In our .NET re:Invent talk, we showed a demo using X-Ray with Lambda, ASP.NET Core, and a couple AWS services to detect a performance problem. To better understand how you can use X-Ray to detect and diagnose performance problems with your application, check out the

AWS X-Ray developer guide.

The biggest feature with the 2.0 beta release is support for .NET Core 2.0, which means you can use X-Ray with all of your AWS .NET Core applications. The 2.0 beta release also has new features such as improved integration with the AWS SDK for .NET, asynchronous support, and improved ASP.NET tracing support.

The 2.0 beta release is a major release for the AWS X-Ray SDK for .NET, so our initial release is a beta release. We encourage you to try it out now and give us feedback. You can do that through the new GitHub repository for the AWS X-Ray SDK for .NET. To add the 2.0 beta release to your project in Visual Studio, be sure to check the Include prerelease check box.

Adding X-Ray to your application

For X-Ray to provide the details of how your application is performing, your application must be instrumented to send tracing data to X-Ray. The AWS X-Ray SDK for .NET provides NuGet packages to make it easy to instrument your application for common scenarios.

AWS SDK for .NET

If your application is using the AWS SDK for .NET to access other AWS services, use the AWSXRayRecorder.Handlers.AwsSdk NuGet package to enable the collection of tracing data for your AWS requests.

For the 2.0 beta release we simplified how to integrate X-Ray with the AWS SDK for .NET. In the previous version of the X-Ray SDK, you had to register every instance of an AWS service client that you created with X-Ray. This caused you to add X-Ray to all parts of your application that were using AWS. That can be challenging if the service clients were created outside of your application code, for example, in a third-party library or a dependency injection framework like the one provided in ASP.NET Core applications.

With the new release, you just add a little bit of code at the start of your application and any AWS service clients created in your applications, including those created by third-party libraries or dependency injection frameworks, are enabled for X-Ray.

To register all AWS service clients, add the following line at the start of your application.


Amazon.XRay.Recorder.Handlers.AwsSdk.AWSSDKHandler.RegisterXRayForAllServices();

To register only certain AWS service clients with X-Ray, use the following command.


Amazon.XRay.Recorder.Handlers.AwsSdk.AWSSDKHandler.RegisterXRay<Amazon.S3.IAmazonS3>();

After these lines of code run, all AWS service clients created after this point are enabled to collect tracing data for X-Ray.

ASP.NET Applications

We’ve also improved support for collecting tracing data in ASP.NET applications. In the previous release, tracing data was collected only for web API controllers. For the 2.0 beta release, we’ve deprecated the AWSXRayRecorder.Handlers.AspNet.WebApi NuGet package in favor of the new AWSXRayRecorder.Handlers.AspNet package. AWSXRayRecorder.Handlers.AspNet works for both web API controllers and MVC controllers. To use this new support, you must remove the deprecated AWSXRayRecorder.Handlers.AspNet.WebApi package.

To enable AWS X-Ray tracing in your ASP.NET application, override the init method in your Global.asax.cs file, and then call the RegisterXRay method.


public override void Init()
{
	base.Init();

	AWSXRayASPNET.RegisterXRay(this, "XRayAspNetSample"); // default name of the web app
}

ASP.NET Core Applications

.NET Core 2.0 support is the major feature of the 2.0 beta release, so of course we wanted to ensure getting tracing data from the ASP.NET Core HTTP request was also simple. You do this using the AWSXRayRecorder.Handlers.AspNetCore NuGet package. After you add the package, just add the “app.UseXRay(“XRayAspNetCoreSample”);” line of code in the Configure method for the Startup class. Here is a full example.


public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseBrowserLink();
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
    }

    app.UseXRay("XRayAspNetCoreSample");

    app.UseStaticFiles();
    app.UseMvc();
}

The order in which features are registered to the IApplicationBuilder controls the order in which the features, like X-Ray, are called. Because we want X-Ray to capture as much request data as possible, we highly recommended that you add the UseXRay call earlier in the Configure method, but after the UseExceptionHandler. The exception handler will take away some of the exception data for the tracing if it’s registered after X-Ray.

Deploying Applications Enabled for X-Ray

To send tracing data collected by the AWS X-Ray SDK for .NET to the X-Ray service, the X-Ray daemon must be running in the same environment as the application. For AWS Elastic Beanstalk and AWS Lambda, this is taken care of for you when you enable X-Ray during the deployment. With the latest release of the AWS Toolkit for Visual Studio, the Elastic Beanstalk and Lambda deployment wizards are updated to enable X-Ray.

In the Elastic Beanstalk deployment wizard, enable X-Ray on the Application Options page.

In the Lambda deployment wizard, enable X-Ray on the Advanced Function Details page.

If you’re deploying Lambda functions as a serverless application, you can enable X-Ray in the serverless.template file by setting the Tracing property of your AWS::Serverless::Function resource to Active.


{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Transform" : "AWS::Serverless-2016-10-31",
  "Resources" : {
    "Get" : {
      "Type" : "AWS::Serverless::Function",
      "Properties": {
        "Handler": "XRayServerlessSample::XRayServerlessSample.Functions::Get",
        "Runtime": "dotnetcore2.0",
        "CodeUri": "",
        "MemorySize": 256,
        "Timeout": 30,
        "Policies": [ "AWSLambdaBasicExecutionRole" ],

        "Tracing" : "Active",

        "Events": {
          "PutResource": {
            "Type": "Api",
            "Properties": {
              "Path": "/",
              "Method": "GET"
            }
          }
        }
      }
    }
  },
  "Outputs" : {

  }

}

In addition, the Amazon.Lambda.Tools and Amazon.ElasticBeanstalk.Tools extensions to the dotnet CLI were updated to support enabling X-Ray tracing in the target deployment environments.

Conclusion

I think .NET developers will be very excited to see the type of data AWS X-Ray can show about their applications, so we hope you check out this new update. Also, you’ll find a lot more information on the advanced configuration you can do with X-Ray on the AWS X-Ray SDK for .NET GitHub repository. If you have any issues with the 2.0 beta release, let us know by opening an issue in our GitHub repository.

相關推薦

New AWS X-Ray .NET Core Support

In our AWS re:Invent talk this year, we preannounced support for .NET Core 2.0 with AWS Lambda and support for .NET Core 2.0 with AWS X-Ray. Last

料金- AWS X-Ray

1 時間あたり 2,000 件の受信リクエストを受け取るアプリケーションを使用していて 10% のサンプリングの頻度を使用している場合、料金は以下のように計算されます。 記録されたトレース

AWS X-Ray Resources

Amazon Web Services is Hiring. Amazon Web Services (AWS) is a dynamic, growing business unit within Amazon.com. We are currently hiring So

AWS Lambda .NET Core 2.0 Support Released

Today we’ve released the highly anticipated .NET Core 2.0 AWS Lambda runtime that is available in all Lambda-supported regions. With .NET Core 2.0

.Net 4.X 提前用上 .Net Core 的配置模式以及熱重載配置

returns ets manage 自動生成 studio 127.0.0.1 文件中 讀取配置 應用程序 1. 前言 在提倡微服務及 Serverless 越來越普及的當下,傳統 .Net 應用的配置模式往往依賴於一個名為 web.config 的 XML 文件,在可擴

再談使用X.PagedList.Mvc 分頁(ASP.NET Core 2.1)

asp ram 默認 mvc 文本 它的 otn package www. 在以前的博文中寫過使用X.PagedList.Mvc組件來對ASP.NET MVC應用程序進行分頁,可以參考此篇隨筆:Asp.net MVC 使用PagedList(新的已更名 為X.PagedLi

發布 ASP.NET Core 2.x 應用到 Ubuntu

bsp 返回 proxy 地址 direct color rev 默認 info 簡單紹一下如何將ASP.NET Core 應用發布到Linux (Ubuntu)服務器上,都是文檔的東西。 服務器結構 ASP.NET Core 2.x 有兩種server:

.net core 2.x - 微信、QQ 授權登入

上一篇是關於模擬請求配置,包括域名問題的解決,本篇就說下授權登入。嗯,比較閒。以前的fx 開發web的時候好像使用的 微信提供的js外掛生成二維碼,然後掃碼登入,,,記不清了,好久不開發微信了。   1.準備工作。 1.1.單獨解決ajax的跨域問題 首先考慮到web端(ajax)

.net core 2.x - 微信、QQ 授權登錄

img ray lba creating 針對 們的 side over ase 上一篇是關於模擬請求配置,包括域名問題的解決,本篇就說下授權登錄。嗯,比較閑。以前的fx 開發web的時候好像使用的 微信提供的js插件生成二維碼,然後掃碼登錄,,,記不清了,好久不開發微信

net core 2.x - 日誌 - to elasiticsearch

記錄日誌到elasticsearch(es),下面簡寫es,然後我們可以通過kibana視覺化的觀察日誌資訊以及統計分析等. 1.起源   年中旬時候,公司有個需求是需要分析使用者的地址,需要先分詞處理然後通過搜尋引擎匹配相關資料,當然這個不是這裡說的重點,主題還是日誌 to es,也就是日誌傳

net core 2.x - 日誌 - to elasticsearch - (2)

你可能會有疑惑,怎麼又來一偏,,,其實我也好奇,因為我已經忘記哪個能跑起來了,,,記憶中,這個好像是沒問題的. 1.使用到的資源   關於es(elasticseach)在.net中的訪問,可以參考es的官網,有很明確的說明了可以使用elasticsearch.net和nest, 需要詳細瞭解的

Net core 2.x - docker(for windows)-linux配置及項目發布

區別 默認 context aml 配置說明 nds cor 開篇 -- 將.net core2.x+sqlserver項目發布到docker.呵呵,操作很自如,如下. 1.羅嗦幾句 在跑起來之前浪費了不少時間和精力,起初是將docker for windows的環境轉

在ASP.NET Core 2.x中獲取客戶端IP地址

一、前言 大家也知道服務端請求時我們獲取的IP地址是包含在請求頭中,因此這也大大便利了IP的獲取。 在ASP.NET中,可以通過以下方式獲取客戶端的IP地址。 HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]

.net core——打造自己的 dotnet new 微服務解決方案模板

目錄 1. 建立新的微服務 2.準備環境 3.以現有的微服務專案為模板 4.分發模板 5.nuget pack打包 6.本地安裝 7.使用新模板 8.完整程式碼參看github 引用連結 1. 建立新的微

釋出 ASP.NET Core 2.x 應用到 Ubuntu

簡單紹一下如何將ASP.NET Core 應用釋出到Linux (Ubuntu)伺服器上,都是文件的東西。 伺服器結構 ASP.NET Core 2.x 有兩種server: HTTP.sys 只支援Windows,並支援一些Windows獨有的特性。 Kestrel,跨平臺的伺服器,高度優化

.net core 2.x - docker-linux容器-持續整合(jenkins)

  1.準備工作      先說明哈,以下操作都是在windows中:      a).需要下載安裝 jenkins 的windows版本      b).需要下載安裝 docker for windows,安裝之後使用的 linux容器,如果不知道的,可以看上一篇      c).我們這裡的演示使

.NET Core 2.x中使用Named Options處理多個強型別配置例項

來源: Using multiple instances of strongly-typed settings with named options in .NET Core 2.x 作者: Andrew Lock 譯者: Lamond Lu .NET Core從1.0版本開始,就已經開始使用

.net core 2.x

好久不進行微信開發了,有些遺忘了,在做identity微信授權登入,所以配置下賬號。 1.環境搭建和配置;   你可能說這個有什麼好說的,那麼問題就來了,收取按域名問題,這是個頭等問題,下面看操作:      你可能會問這是啥東西,嗯,這是內網穿透的一個功能靈感源自QQ瀏覽器的外掛(已被下架)。這個東西是

net core 2.x

你可能會有疑惑,怎麼又來一偏,,,其實我也好奇,因為我已經忘記哪個能跑起來了,,,記憶中,這個好像是沒問題的. 1.使用到的資源   關於es(elasticseach)在.net中的訪問,可以參考es的官網,有很明確的說明了可以使用elasticsearch.net和nest, 需要詳細瞭解的 點這裡

.NET Core多平臺開發體驗[2]: Mac OS X

除了微軟自家的Windows平臺, .NET Core針對Mac OS以及各種Linux(RHEL、Ubuntu、Debian、Fedora、CentOS和SUSE等)都提供了很好的支援,我們先來體驗一下使用Mac來開發.NET Core應用,在這之前我們照例先得構建我們的開發環境。一、安裝開發環境和Wind