Implementing Application Insights - Create a workspace-based Application Insights resource (backed by Log Analytics). - For Azure Functions (isolated worker model): add Microsoft.ApplicationInsights.WorkerService and Microsoft.Azure.Functions.Worker.ApplicationInsights, then call builder.Services.AddApplicationInsightsTelemetryWorkerService(); builder.Services.ConfigureFunctionsApplicationInsights(); - Set APPLICATIONINSIGHTS_CONNECTION_STRING in the app settings (connection strings replace instrumentation keys). - For ASP.NET Core APIs: AddApplicationInsightsTelemetry(), or the Azure Monitor OpenTelemetry Distro (UseAzureMonitor()), which Microsoft now recommends for new apps. - Log through ILogger with structured messages; requests, dependencies (SQL, HTTP, Service Bus) and exceptions are collected automatically. Adjust log levels and sampling in host.json and appsettings. Two functions in two solutions sharing one Application Insights Yes — configure both Function Apps with the same connection string. All telemetry goes to the same resource, which is useful when the functions are parts of one system, because end-to-end transactions and the application map show calls across both. Differentiating their logs 1. Cloud role name (the main mechanism): each app reports cloud_RoleName, which defaults to the Function App name. You can set it explicitly with a telemetry initializer or the OTEL_SERVICE_NAME / service.name resource attribute. Then query: traces | where cloud_RoleName == "orders-func" | order by timestamp desc 2. Function name: Azure Functions adds the function name to telemetry (operation_Name, Category such as Function.ProcessOrder), so you can filter per function as well. 3. Custom dimensions: add properties like Module or Environment with logging scopes or telemetry initializers. 4. Cloud role instance identifies the individual instance. Correlation Operation IDs propagate across HTTP and Service Bus calls, so a request handled by function A and continued by function B appears as one transaction. When to use separate resources instead Different teams, retention or access requirements, separate environments (always separate dev, test and prod), or very high volume where cost tracking per app matters.
Ravindra Wadile · · 0 likes