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?