Reputation: 131
I have created a Service bus triggered Azure function and want to log custom events in application insights.
private static string key = TelemetryConfiguration.Active.InstrumentationKey =
System.Environment.GetEnvironmentVariable(
"APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process);
private static TelemetryClient telemetryClient =
new TelemetryClient() { InstrumentationKey = key };
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("xxxxx", "xxxxx", AccessRights.Manage, Connection = "SBConnectionKey")]string mySbMsg, ILogger logger, TraceWriter log)
{
log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
telemetryClient.Context.Cloud.RoleName = "AIFunction";
logger.LogMetric("test", 123);
telemetryClient.TrackEvent("Ack123 Recieved");
telemetryClient.TrackMetric("Test Metric", DateTime.Now.Millisecond);
}
I can see only log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
this logs in the trace. But custom events and metrics are not logging to application insights.
Any ideas what could be going on?
Upvotes: 4
Views: 2567
Reputation: 1194
Answering your explicit question:
What is wrong with the telemetry that I send or where to find it in Application Insights Portal?
I created the function with almost the same code and tested. You can analyse the repo. I deployed the function and got the following results:
Answering your implicit question:
How to use Application Insights?
It is tricky at the beginning to use App Insights query language, I found this succinct file helpful. Other elements to consider in working with this monitoring tool:
Upvotes: 4