Application Insights with AWS Elastic Beanstalk

谁都会走 提交于 2019-12-23 05:34:05

问题


I'm trying to get Application Insights running on an application on hosted on multiple instances in an AWS Elastic Beanstalk. The problem is that the servers are all seen as a single server. I think this is because they all have the same HostName.

Does anyone know how I can:

  • Set the ServerName property in Application Insights manually on startup? or
  • Force AWS to give each instance a different HostName?

回答1:


You can change set the value with Telemetry Initializer if the field is public, alternatively you can create your own property to store the correct name. Either way, Telemetry Initializer looks like a way to go:

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      
    }

As you can see, you can access the existing properties of the telemetry item as well as add new ones if required. I hope this helps.



来源:https://stackoverflow.com/questions/43020484/application-insights-with-aws-elastic-beanstalk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!