问题
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