【问题标题】:Application Insights with AWS Elastic Beanstalk使用 AWS Elastic Beanstalk 的 Application Insights
【发布时间】:2017-08-18 15:07:56
【问题描述】:

我正在尝试让 Application Insights 在托管在 AWS Elastic Beanstalk 中的多个实例上的应用程序上运行。问题是服务器都被视为单个服务器。我认为这是因为它们都有相同的主机名。

有谁知道我该怎么做:

  • 在启动时手动设置 Application Insights 中的 ServerName 属性? 或
  • 强制 AWS 为每个实例指定不同的主机名?

【问题讨论】:

    标签: amazon-web-services amazon-ec2 amazon-elastic-beanstalk azure-application-insights


    【解决方案1】:

    如果字段是公共的,您可以使用 Telemetry Initializer 更改设置值,或者您可以创建自己的属性来存储正确的名称。无论哪种方式,Telemetry Initializer 看起来都是一条路:

    public class MyTelemetryInitializer : ITelemetryInitializer
    {
        public void Initialize(ITelemetry telemetry)
        {
            var requestTelemetry = telemetry as RequestTelemetry;
            // Is this a TrackRequest() ?
            if (requestTelemetry == null) return;
            int code;
            bool parsed = Int32.TryParse(requestTelemetry.ResponseCode, out code);
            if (!parsed) return;
            if (code >= 400 && code < 500)
            {
                // If we set the Success property, the SDK won't change it:
                requestTelemetry.Success = true;
                // Allow us to filter these requests in the portal:
                requestTelemetry.Context.Properties["Overridden400s"] = "true";
            }
            // else leave the SDK to set the Success property      
        }
    

    如您所见,您可以访问遥测项的现有属性,也可以根据需要添加新属性。我希望这会有所帮助。

    【讨论】:

    • 这似乎是正确的路线,但我没有看到可以更改门户中显示的 ServerName 的任何地方。
    • 我认为它隐藏在遥测项目上下文中可用的 cloudRoleInstance 参数后面,您可以尝试使用TelemetryInitializer 修改它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2015-02-10
    • 2017-01-17
    • 2017-08-05
    • 2018-06-05
    • 2019-03-09
    • 2019-02-05
    相关资源
    最近更新 更多