Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolated Functions ApplicationInsights DependencyTracking (Sql/ServiceBus) #822

Closed
paul-datatech911 opened this issue Mar 8, 2022 · 20 comments

Comments

@paul-datatech911
Copy link

Based on the very limited documentation about enabling Sql query tracking in Azure Functions, I believe I have the correct configuration and proper packages installed, but I still get no Sql Logging to ApplicationInsights. I also get no ServiceBus dependency data via ApplicationInsights. I only ever get a top-level function call timing.

From the output ApplicationInsightsLoggerOptions that are in the process debug info below, it appears to have read the configuration properly and be configured. Looking at sample data in the portal shows no dependency data at all, including no sql (see screenshot).

image

.Net6
Functions v4
Isolated Functions worker

Direct Dependencies
-Microsoft.Azure.Functions.Worker 1.6.0
-Microsoft.Azure.Functions.Worker.Extensions.Http 3.0.12
-Microsoft.Azure.Functions.Worker.Extensions.ServiceBus 5.0.0-beta.6
-Microsoft.Azure.Functions.Worker.Extensions.Storage 5.0.0
-Microsoft.Azure.Functions.Worker.Extensions.Timer 4.0.1
-Microsoft.Azure.Functions.Worker.Sdk 1.3.0
-Micosoft.ApplicationInsights.WorkerService 2.20.0

Indirect Dependencies
-Microsoft.EntityFrameworkCore.SqlServer 6.0.3
--Microsoft.Data.SqlClient 2.1.4

host.json

{
    "version": "2.0",
    "logging": {
      "applicationInsights": {
        "samplingSettings": {
          "isEnabled": true,
          "excludedTypes": "Request"
        },
        "EnableDependencyTracking": true,
        "DependencyTrackingOptions": {
          "enableSqlCommandTextInstrumentation": true 
        }
      }
    }
}

process debug info

Azure Functions Core Tools
Core Tools Version:       4.0.3971 Commit hash: d0775d487c93ebd49e9c1166d5c3c01f3c76eaaf  (64-bit)
Function Runtime Version: 4.0.1.16815

[2022-03-08T16:32:19.932Z] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: 'b21e89ff-fa0a-441f-9659-11f9eb939465'
[2022-03-08T16:32:19.936Z] Reading host configuration file 'G:\FR911Cloud\FR911.Functions.Reports.Isolated\bin\Debug\net6.0\host.json'
[2022-03-08T16:32:19.938Z] Host configuration file read:
[2022-03-08T16:32:19.939Z] {
[2022-03-08T16:32:19.939Z]   "version": "2.0",
[2022-03-08T16:32:19.940Z]   "logging": {
[2022-03-08T16:32:19.940Z]     "applicationInsights": {
[2022-03-08T16:32:19.941Z]       "samplingSettings": {
[2022-03-08T16:32:19.941Z]         "isEnabled": true,
[2022-03-08T16:32:19.941Z]         "excludedTypes": "Request"
[2022-03-08T16:32:19.942Z]       },
[2022-03-08T16:32:19.943Z]       "EnableDependencyTracking": true,
[2022-03-08T16:32:19.944Z]       "DependencyTrackingOptions": {
[2022-03-08T16:32:19.945Z]         "enableSqlCommandTextInstrumentation": true
[2022-03-08T16:32:19.945Z]       }
[2022-03-08T16:32:19.946Z]     }
[2022-03-08T16:32:19.947Z]   }
[2022-03-08T16:32:19.948Z] }
[2022-03-08T16:32:19.962Z] Loading functions metadata
[2022-03-08T16:32:19.965Z] Reading functions metadata
[2022-03-08T16:32:19.971Z] 0 functions found
[2022-03-08T16:32:19.976Z] 0 functions loaded
[2022-03-08T16:32:19.979Z] Loading extensions from G:\FR911Cloud\FR911.Functions.Reports.Isolated\bin\Debug\net6.0. BundleConfigured: False, PrecompiledFunctionApp: False, LegacyBundle: False
[2022-03-08T16:32:19.980Z] Script Startup resetting load context with base path: 'G:\FR911Cloud\FR911.Functions.Reports.Isolated\bin\Debug\net6.0\.azurefunctions'.
[2022-03-08T16:32:19.991Z] Loading startup extension 'Startup'
[2022-03-08T16:32:20.035Z] Loaded extension 'Startup' (1.0.0.0)
[2022-03-08T16:32:20.056Z] Loading startup extension 'ServiceBus'
[2022-03-08T16:32:20.059Z] Loaded extension 'ServiceBus' (5.0.0.0)
[2022-03-08T16:32:20.069Z] Reading host configuration file 'G:\FR911Cloud\FR911.Functions.Reports.Isolated\bin\Debug\net6.0\host.json'
[2022-03-08T16:32:20.070Z] Host configuration file read:
[2022-03-08T16:32:20.071Z] {
[2022-03-08T16:32:20.071Z]   "version": "2.0",
[2022-03-08T16:32:20.072Z]   "logging": {
[2022-03-08T16:32:20.072Z]     "applicationInsights": {
[2022-03-08T16:32:20.073Z]       "samplingSettings": {
[2022-03-08T16:32:20.074Z]         "isEnabled": true,
[2022-03-08T16:32:20.074Z]         "excludedTypes": "Request"
[2022-03-08T16:32:20.075Z]       },
[2022-03-08T16:32:20.076Z]       "EnableDependencyTracking": true,
[2022-03-08T16:32:20.076Z]       "DependencyTrackingOptions": {
[2022-03-08T16:32:20.077Z]         "enableSqlCommandTextInstrumentation": true
[2022-03-08T16:32:20.077Z]       }
[2022-03-08T16:32:20.078Z]     }
[2022-03-08T16:32:20.079Z]   }
[2022-03-08T16:32:20.079Z] }
[2022-03-08T16:32:20.684Z] Initializing Warmup Extension.
[2022-03-08T16:32:20.741Z] Initializing Host. OperationId: 'b21e89ff-fa0a-441f-9659-11f9eb939465'.
[2022-03-08T16:32:20.751Z] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=b21e89ff-fa0a-441f-9659-11f9eb939465
[2022-03-08T16:32:20.774Z] Loading functions metadata
[2022-03-08T16:32:20.775Z] Reading functions metadata
[2022-03-08T16:32:20.777Z] 0 functions found
[2022-03-08T16:32:20.839Z] 7 functions loaded
[2022-03-08T16:32:20.848Z] ApplicationInsightsLoggerOptions
[2022-03-08T16:32:20.849Z] {
[2022-03-08T16:32:20.850Z]   "SamplingSettings": {
[2022-03-08T16:32:20.851Z]     "EvaluationInterval": "00:00:15",
[2022-03-08T16:32:20.852Z]     "InitialSamplingPercentage": 100.0,
[2022-03-08T16:32:20.853Z]     "MaxSamplingPercentage": 100.0,
[2022-03-08T16:32:20.854Z]     "MaxTelemetryItemsPerSecond": 20.0,
[2022-03-08T16:32:20.855Z]     "MinSamplingPercentage": 0.1,
[2022-03-08T16:32:20.855Z]     "MovingAverageRatio": 0.25,
[2022-03-08T16:32:20.856Z]     "SamplingPercentageDecreaseTimeout": "00:02:00",
[2022-03-08T16:32:20.857Z]     "SamplingPercentageIncreaseTimeout": "00:15:00"
[2022-03-08T16:32:20.859Z]   },
[2022-03-08T16:32:20.860Z]   "SamplingExcludedTypes": "Request",
[2022-03-08T16:32:20.861Z]   "SamplingIncludedTypes": null,
[2022-03-08T16:32:20.862Z]   "SnapshotConfiguration": null,
[2022-03-08T16:32:20.862Z]   "EnablePerformanceCountersCollection": true,
[2022-03-08T16:32:20.863Z]   "HttpAutoCollectionOptions": {
[2022-03-08T16:32:20.864Z]     "EnableHttpTriggerExtendedInfoCollection": true,
[2022-03-08T16:32:20.865Z]     "EnableW3CDistributedTracing": true,
[2022-03-08T16:32:20.866Z]     "EnableResponseHeaderInjection": true
[2022-03-08T16:32:20.867Z]   },
[2022-03-08T16:32:20.868Z]   "LiveMetricsInitializationDelay": "00:00:15",
[2022-03-08T16:32:20.868Z]   "EnableLiveMetrics": true,
[2022-03-08T16:32:20.869Z]   "EnableDependencyTracking": true,
[2022-03-08T16:32:20.870Z]   "DependencyTrackingOptions": {
[2022-03-08T16:32:20.871Z]     "DisableRuntimeInstrumentation": false,
[2022-03-08T16:32:20.872Z]     "DisableDiagnosticSourceInstrumentation": false,
[2022-03-08T16:32:20.872Z]     "EnableLegacyCorrelationHeadersInjection": false,
[2022-03-08T16:32:20.875Z]     "EnableRequestIdHeaderInjectionInW3CMode": true,
[2022-03-08T16:32:20.876Z]     "EnableSqlCommandTextInstrumentation": true,
[2022-03-08T16:32:20.877Z]     "SetComponentCorrelationHttpHeaders": true,
[2022-03-08T16:32:20.877Z]     "EnableAzureSdkTelemetryListener": true
[2022-03-08T16:32:20.878Z]   }
[2022-03-08T16:32:20.879Z] }
[2022-03-08T16:32:20.880Z] LoggerFilterOptions
[2022-03-08T16:32:20.880Z] {
[2022-03-08T16:32:20.881Z]   "MinLevel": "None",
[2022-03-08T16:32:20.882Z]   "Rules": [
[2022-03-08T16:32:20.883Z]     {
[2022-03-08T16:32:20.884Z]       "ProviderName": null,
[2022-03-08T16:32:20.885Z]       "CategoryName": null,
[2022-03-08T16:32:20.885Z]       "LogLevel": null,
[2022-03-08T16:32:20.886Z]       "Filter": "<AddFilter>b__0"
[2022-03-08T16:32:20.887Z]     },
[2022-03-08T16:32:20.887Z]     {
[2022-03-08T16:32:20.888Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-03-08T16:32:20.889Z]       "CategoryName": null,
[2022-03-08T16:32:20.891Z]       "LogLevel": "None",
[2022-03-08T16:32:20.892Z]       "Filter": null
[2022-03-08T16:32:20.893Z]     },
[2022-03-08T16:32:20.894Z]     {
[2022-03-08T16:32:20.895Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-03-08T16:32:20.896Z]       "CategoryName": null,
[2022-03-08T16:32:20.896Z]       "LogLevel": null,
[2022-03-08T16:32:20.897Z]       "Filter": "<AddFilter>b__0"
[2022-03-08T16:32:20.898Z]     },
[2022-03-08T16:32:20.899Z]     {
[2022-03-08T16:32:20.900Z]       "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2022-03-08T16:32:20.900Z]       "CategoryName": null,
[2022-03-08T16:32:20.901Z]       "LogLevel": null,
[2022-03-08T16:32:20.902Z]       "Filter": "<AddFilter>b__0"
[2022-03-08T16:32:20.903Z]     },
[2022-03-08T16:32:20.904Z]     {
[2022-03-08T16:32:20.905Z]       "ProviderName": "Microsoft.Azure.WebJobs.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider",
[2022-03-08T16:32:20.908Z]       "CategoryName": null,
[2022-03-08T16:32:20.908Z]       "LogLevel": "Trace",
[2022-03-08T16:32:20.909Z]       "Filter": null
[2022-03-08T16:32:20.910Z]     }
[2022-03-08T16:32:20.911Z]   ]
[2022-03-08T16:32:20.912Z] }
[2022-03-08T16:32:20.912Z] LoggerFilterOptions
[2022-03-08T16:32:20.913Z] {
[2022-03-08T16:32:20.914Z]   "MinLevel": "None",
[2022-03-08T16:32:20.914Z]   "Rules": [
[2022-03-08T16:32:20.915Z]     {
[2022-03-08T16:32:20.916Z]       "ProviderName": null,
[2022-03-08T16:32:20.917Z]       "CategoryName": null,
[2022-03-08T16:32:20.918Z]       "LogLevel": null,
[2022-03-08T16:32:20.918Z]       "Filter": "<AddFilter>b__0"
[2022-03-08T16:32:20.919Z]     },
[2022-03-08T16:32:20.920Z]     {
[2022-03-08T16:32:20.922Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-03-08T16:32:20.923Z]       "CategoryName": null,
[2022-03-08T16:32:20.924Z]       "LogLevel": "None",
[2022-03-08T16:32:20.925Z]       "Filter": null
[2022-03-08T16:32:20.926Z]     },
[2022-03-08T16:32:20.927Z]     {
[2022-03-08T16:32:20.927Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2022-03-08T16:32:20.928Z]       "CategoryName": null,
[2022-03-08T16:32:20.929Z]       "LogLevel": null,
[2022-03-08T16:32:20.930Z]       "Filter": "<AddFilter>b__0"
[2022-03-08T16:32:20.931Z]     },
[2022-03-08T16:32:20.931Z]     {
[2022-03-08T16:32:20.932Z]       "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2022-03-08T16:32:20.933Z]       "CategoryName": null,
[2022-03-08T16:32:20.933Z]       "LogLevel": null,
[2022-03-08T16:32:20.934Z]       "Filter": "<AddFilter>b__0"
[2022-03-08T16:32:20.937Z]     },
[2022-03-08T16:32:20.937Z]     {
[2022-03-08T16:32:20.938Z]       "ProviderName": "Microsoft.Azure.WebJobs.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider",
[2022-03-08T16:32:20.939Z]       "CategoryName": null,
[2022-03-08T16:32:20.940Z]       "LogLevel": "Trace",
[2022-03-08T16:32:20.941Z]       "Filter": null
[2022-03-08T16:32:20.942Z]     }
[2022-03-08T16:32:20.943Z]   ]
[2022-03-08T16:32:20.943Z] }
[2022-03-08T16:32:20.944Z] ConcurrencyOptions
[2022-03-08T16:32:20.945Z] {
[2022-03-08T16:32:20.945Z]   "DynamicConcurrencyEnabled": false,
[2022-03-08T16:32:20.946Z]   "MaximumFunctionConcurrency": 500,
[2022-03-08T16:32:20.947Z]   "CPUThreshold": 0.8,
[2022-03-08T16:32:20.947Z]   "SnapshotPersistenceEnabled": true
[2022-03-08T16:32:20.948Z] }
[2022-03-08T16:32:20.949Z] FunctionResultAggregatorOptions
[2022-03-08T16:32:20.950Z] {
[2022-03-08T16:32:20.951Z]   "BatchSize": 1000,
[2022-03-08T16:32:20.953Z]   "FlushTimeout": "00:00:30",
[2022-03-08T16:32:20.954Z]   "IsEnabled": true
[2022-03-08T16:32:20.955Z] }
[2022-03-08T16:32:20.956Z] SingletonOptions
[2022-03-08T16:32:20.957Z] {
[2022-03-08T16:32:20.958Z]   "LockPeriod": "00:00:15",
[2022-03-08T16:32:20.959Z]   "ListenerLockPeriod": "00:00:15",
[2022-03-08T16:32:20.959Z]   "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[2022-03-08T16:32:20.960Z]   "LockAcquisitionPollingInterval": "00:00:05",
[2022-03-08T16:32:20.961Z]   "ListenerLockRecoveryPollingInterval": "00:01:00"
[2022-03-08T16:32:20.962Z] }
[2022-03-08T16:32:20.963Z] ServiceBusOptions
[2022-03-08T16:32:20.964Z] {
[2022-03-08T16:32:20.964Z]   "ClientRetryOptions": {
[2022-03-08T16:32:20.965Z]     "Mode": "Exponential",
[2022-03-08T16:32:20.966Z]     "TryTimeout": "00:01:00",
[2022-03-08T16:32:20.967Z]     "Delay": "00:00:00.8000000",
[2022-03-08T16:32:20.969Z]     "MaxDelay": "00:01:00",
[2022-03-08T16:32:20.970Z]     "MaxRetries": 3
[2022-03-08T16:32:20.971Z]   },
[2022-03-08T16:32:20.971Z]   "TransportType": "AmqpTcp",
[2022-03-08T16:32:20.972Z]   "WebProxy": "",
[2022-03-08T16:32:20.973Z]   "AutoCompleteMessages": true,
[2022-03-08T16:32:20.974Z]   "PrefetchCount": 0,
[2022-03-08T16:32:20.974Z]   "MaxAutoLockRenewalDuration": "00:05:00",
[2022-03-08T16:32:20.975Z]   "MaxConcurrentCalls": 192,
[2022-03-08T16:32:20.976Z]   "MaxConcurrentSessions": 8,
[2022-03-08T16:32:20.977Z]   "MaxMessageBatchSize": 1000,
[2022-03-08T16:32:20.977Z]   "SessionIdleTimeout": ""
[2022-03-08T16:32:20.978Z] }
[2022-03-08T16:32:20.980Z] Starting JobHost
[2022-03-08T16:32:20.984Z] Starting Host (HostId=desktopck2dlhf-843605399, InstanceId=f229297a-81f4-4415-87ea-a2da69aafc04, Version=4.0.1.16815, ProcessId=43300, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=~4)
[2022-03-08T16:32:20.999Z] Loading functions metadata
[2022-03-08T16:32:21.002Z] Reading functions metadata
[2022-03-08T16:32:21.005Z] 0 functions found
[2022-03-08T16:32:21.016Z] 7 functions loaded
[2022-03-08T16:32:21.054Z] Generating 7 job function(s)
[2022-03-08T16:32:21.108Z] Found the following functions:
[2022-03-08T16:32:21.109Z] Host.Functions.CacheSync1
[2022-03-08T16:32:21.110Z] Host.Functions.CacheSync2
[2022-03-08T16:32:21.111Z] Host.Functions.CacheSync3
[2022-03-08T16:32:21.112Z] Host.Functions.GenerateSummaryReportRequestsHttpFunc
[2022-03-08T16:32:21.114Z] Host.Functions.ProcessReportsQueue1
[2022-03-08T16:32:21.115Z] Host.Functions.ProcessReportsQueue2
[2022-03-08T16:32:21.115Z] Host.Functions.ProcessReportsQueue3
[2022-03-08T16:32:21.116Z]
[2022-03-08T16:32:21.123Z] The 'AutoCompleteMessages' option has been overriden to 'True' value for 'Functions.CacheSync1' function.
[2022-03-08T16:32:21.126Z] Azure Functions .NET Worker (PID: 32280) initialized in debug mode. Waiting for debugger to attach...
[2022-03-08T16:32:21.126Z] The 'AutoCompleteMessages' option has been overriden to 'True' value for 'Functions.CacheSync2' function.
[2022-03-08T16:32:21.130Z] The 'AutoCompleteMessages' option has been overriden to 'True' value for 'Functions.CacheSync3' function.
[2022-03-08T16:32:21.131Z] The 'AutoCompleteMessages' option has been overriden to 'True' value for 'Functions.ProcessReportsQueue1' function.
[2022-03-08T16:32:21.132Z] The 'AutoCompleteMessages' option has been overriden to 'True' value for 'Functions.ProcessReportsQueue2' function.
[2022-03-08T16:32:21.134Z] The 'AutoCompleteMessages' option has been overriden to 'True' value for 'Functions.ProcessReportsQueue3' function.
[2022-03-08T16:32:21.139Z] HttpOptions
[2022-03-08T16:32:21.140Z] {
[2022-03-08T16:32:21.141Z] Initializing function HTTP routes
[2022-03-08T16:32:21.141Z]   "DynamicThrottlesEnabled": false,
[2022-03-08T16:32:21.142Z] Mapped function route 'api/generateSummaryReports' [get,post] to 'GenerateSummaryReportRequestsHttpFunc'
[2022-03-08T16:32:21.144Z]   "EnableChunkedRequestBinding": false,
[2022-03-08T16:32:21.145Z]
[2022-03-08T16:32:21.146Z]   "MaxConcurrentRequests": -1,
[2022-03-08T16:32:21.148Z]   "MaxOutstandingRequests": -1,
[2022-03-08T16:32:21.149Z]   "RoutePrefix": "api"
[2022-03-08T16:32:21.150Z] }
[2022-03-08T16:32:21.157Z] Host initialized (159ms)
[2022-03-08T16:32:21.289Z] Host started (301ms)
[2022-03-08T16:32:21.290Z] Job host started

Functions:

        GenerateSummaryReportRequestsHttpFunc: [GET,POST] http://localhost:7071/api/generateSummaryReports

        CacheSync1: serviceBusTrigger

        CacheSync2: serviceBusTrigger

        CacheSync3: serviceBusTrigger

        ProcessReportsQueue1: serviceBusTrigger

        ProcessReportsQueue2: serviceBusTrigger

        ProcessReportsQueue3: serviceBusTrigger

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 POST http://127.0.0.1:60983/AzureFunctionsRpcMessages.FunctionRpc/EventStream application/grpc -
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'gRPC - /AzureFunctionsRpcMessages.FunctionRpc/EventStream'
[2022-03-08T16:32:32.259Z] 2022-03-08 16:32:32,258 Microsoft.Hosting.Lifetime : INFO, Application started. Press Ctrl+C to shut down.
[2022-03-08T16:32:32.261Z] 2022-03-08 16:32:32,261 Microsoft.Hosting.Lifetime : INFO, Hosting environment: Development
[2022-03-08T16:32:32.263Z] 2022-03-08 16:32:32,262 Microsoft.Hosting.Lifetime : INFO, Content root path: G:\FR911Cloud\FR911.Functions.Reports.Isolated\bin\Debug\net6.0\
[2022-03-08T16:32:32.263Z] {
[2022-03-08T16:32:32.265Z]   "ProcessId": 32280,
[2022-03-08T16:32:32.266Z]   "WorkerVersion": "1.4.0.0",
[2022-03-08T16:32:32.266Z]   "ProductVersion": "1.4.0\u002B96ec4146d89fc22491e01bc86438c8cb0fb3a0d9",
[2022-03-08T16:32:32.267Z]   "FrameworkDescription": ".NET 6.0.1",
[2022-03-08T16:32:32.268Z]   "OSDescription": "Microsoft Windows 10.0.22000",
[2022-03-08T16:32:32.269Z]   "OSArchitecture": "X64",
[2022-03-08T16:32:32.270Z]   "RuntimeIdentifier": "win10-x64",
[2022-03-08T16:32:32.270Z]   "CommandLine": "G:\\FR911Cloud\\FR911.Functions.Reports.Isolated\\bin\\Debug\\net6.0\\FR911.Functions.Reports.Isolated.dll --host 127.0.0.1 --port 60983 --workerId 0d01af61-b22e-4dac-88ca-1e4312991972 --requestId 55ab6235-dcc1-4e68-8490-bb5655c9061f --grpcMaxMessageLength 2147483647"
[2022-03-08T16:32:32.272Z] }
[2022-03-08T16:32:32.319Z] Worker process started and initialized.
@ghost ghost assigned fabiocav Mar 8, 2022
@bbieniek
Copy link

I am facing the same issue.
It looks like the "_MS.Links" property is not correctly propagated with the different Operation Ids.

@fabiocav
Copy link
Member

@paul-datatech911 can you share your bootstrapping code? The App Insights configuration in host.json will configure the behavior for the host, but the worker, which is the process you're issuing SQL queries from, won't be automatically configured to emit those traces.

@pseabury
Copy link

Here's an example from one of our FunctionApps. This also shows, btw, how we init required ServiceBus endpoints/subscriptions. RegisterContainerDI() is just the SimpleInjector container DI setup elsewhere to keep the bootstrapping as clean as possible.

namespace FR911.Functions.Reports.Isolated
{
    public class Program
    {
        public async static Task Main()
        {
            //log4net.Util.LogLog.InternalDebugging = true;

            var fr911Config = new FR911Config();
            var sbInitConfig = new SBInitConfig();
            var container = new Container();            

            var host = new HostBuilder()
                .ConfigureFunctionsWorkerDefaults()
                .ConfigureAppConfiguration(config =>
                {
                    config
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("local.settings.json", true);
                    var configRoot = config.Build();
                    configRoot.GetSection("FR911Config").Bind(fr911Config);
                    configRoot.GetSection("SBInitConfig").Bind(sbInitConfig);
                })                
                .ConfigureServices(services => 
                {
                    services.AddFR911Log4NetConfig();
                    services.AddSimpleInjector(container, options => 
                    {
                        // TODO - Any non-default cross-wiring?
                    });
                    services.AddTransient<ICommandProcessor, CommandProcessor>();
                    services.AddSingleton<IFR911RepositoryFactory>(services => { return new FR911RepositoryFactorySql(fr911Config); });
                    services.AddSingleton(container);
                })               
                .Build()
                .UseSimpleInjector(container);

            // Must be called after IHost.UseSimpleInjector()
            container.RegisterContainerDI();

            // This ensures that all required ServiceBus Endpoints exist
            var cp = new CommandProcessor(container, new FR911RepositoryFactorySql(fr911Config));
            await cp.Handle(new ServiceBusInitCommand() { CQIdentity = FR911Constants.AUTH_ANONYMOUS_USER, SBInitConfig = sbInitConfig });

            // Now start the Functions Host
            await host.RunAsync();
        }
    }
}

@pseabury
Copy link

Also @fabiocav - is there documentation other than what I linked to in the original issue post that describes what other bootstrapping is needed? I guess for ASP.NET applications everything is magically wired up, but not sure where to do this for Generic Host stuff.

@ghost ghost added the no-recent-activity label Mar 20, 2022
@ghost
Copy link

ghost commented Mar 20, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@paul-datatech911
Copy link
Author

I have provided author feedback.

@fabiocav
Copy link
Member

@paul-datatech911 / @pseabury the documentation I would recommend as reference would be this, towards the end (in the next steps section), you'll also see a link for documentation on how to enable dependency tracking.

Hope this helps!

@paul-datatech911
Copy link
Author

@fabiocav So should we be using the guidance here regarding non-AspNet applications for isolated functions also? In other words, would you recommend using the Microsoft.ApplicationInsights.WorkerService
and then calling services.AddApplicationInsightsTelemetryWorkerService();?

Paul

@fabiocav
Copy link
Member

@paul-datatech911 we don't have validation in place for that at the moment, but that seems suitable. Should do exactly what you're looking for.

@emiledawalibi
Copy link

hi @fabiocav, will using Microsoft.ApplicationInsights.WorkerService as above resolve issues being reported around dependency logging not being correlated with request?

@fabiocav
Copy link
Member

@emiledawalibi it should. Have you found problems with it?

@paul-datatech911 / @pseabury have you been able to validate the functionality?

@paul-datatech911
Copy link
Author

@fabiocav - I expect to get back to that task in the next few days and can report back then.

@paul-datatech911
Copy link
Author

@fabiocav No, for a v4 Isolated Function, adding Microsoft.ApplicationInsights.WorkerService and then calling services.AddApplicationInsightsTelemetryWorkerService(); (with an AI key in config) did not log the dependencies as I had hoped. I should be seeing SQL logging.

        var host = new HostBuilder()
            .ConfigureFunctionsWorkerDefaults()
            .ConfigureAppConfiguration(config =>
            {
                config
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddJsonFile("local.settings.json", true);
                var configRoot = config.Build();
                configRoot.GetSection("FR911Config").Bind(fr911Config);
                configRoot.GetSection("SBInitConfig").Bind(sbInitConfig);
            })                
            .ConfigureServices(services => 
            {
                services.AddFR911Log4NetConfig();
                services.AddSimpleInjector(container, options => 
                {
                    // TODO - Any non-default cross-wiring?
                });
                services.AddTransient<ICommandProcessor, CommandProcessor>();
                services.AddSingleton<IFR911RepositoryFactory>(services => { return new FR911RepositoryFactorySql(fr911Config); });
                services.AddSingleton(container);
                services.AddApplicationInsightsTelemetryWorkerService();
            })               
            .Build()
            .UseSimpleInjector(container);

I also have host.config as follows:

{
    "version": "2.0",
    "logging": {
      "applicationInsights": {
        "samplingSettings": {
          "isEnabled": true,
          "excludedTypes": "Request"
        },
        "EnableDependencyTracking": true,
        "DependencyTrackingOptions": {
          "enableSqlCommandTextInstrumentation": true 
        }
      }
    }
}

image

@paul-datatech911
Copy link
Author

@fabiocav OK another update - if I use the Microsoft.ApplicationInsights.WorkerService package AND configure it to use the legacy headers, it works. I feel like this might be more of a workaround than a solution. Official guidance for a situation like this would be beneficial.

services.AddApplicationInsightsTelemetryWorkerService(opts =>
{
    opts.DependencyCollectionOptions.EnableLegacyCorrelationHeadersInjection = true;                        
});

@fabiocav
Copy link
Member

Thank you for the update. We'll be flagging this as a scenario we need to investigate to define the work needed to remove this friction.

Thanks for the update. Glad to hear this seems to be working for you at this point

@black-byte
Copy link

I've managed to solve this issue partially, I do get the end result as expected with correlated traces with dependencies. The only downside of my solution is you end up with two-parent operations.
I am trying to revisit this issue and find a better way to solve it.
In my case
opts.DependencyCollectionOptions.EnableLegacyCorrelationHeadersInjection = true;
It didn't work at all all dependencies were unparented.

I've provided a few details on StackOverflow.

https://stackoverflow.com/questions/71997797/azure-functions-dependency-tracking-for-sql-server-and-service-bus-into-applicat/73119754#73119754

Let me know whether someone found any better way to solve this issue.

@brettsam
Copy link
Member

Please give the latest AppInsights package a try: #944 (comment).

This should hopefully take care of a lot of the issues found in this thread.

@jviau
Copy link
Contributor

jviau commented Jun 28, 2023

Reading the documentation linked earlier, it sounds like we will need some host side work to enable this.

With the dotnet isolated, the user can no longer configure the host's DependencyTrackingTelemetryModule, meaning they can never set this value. We either need to come up with some way for customers to easily configure host app insights, or live with this gap between host and worker (at least until the host shifts to OTel).

@mirekkukla
Copy link

mirekkukla commented Oct 13, 2023

Isolated function dependency tracking is now supported, although it doesn't work out-of-the-box (announcement here, for more details see #822).

Note that you'll have to configure things such that workers emit logs directly as detailed here.

@jviau
Copy link
Contributor

jviau commented Apr 3, 2024

Reading the documentation linked earlier, it sounds like we will need some host side work to enable this.

With the dotnet isolated, the user can no longer configure the host's DependencyTrackingTelemetryModule, meaning they can never set this value. We either need to come up with some way for customers to easily configure host app insights, or live with this gap between host and worker (at least until the host shifts to OTel).

Disregard this comment, I misunderstood the original issue. The issue is the SQL / ServiceBus calls are coming from customer code in the worker, not the host. This is now supported through the ApplicationInsights Worker package. Please see https://azure.microsoft.com/en-us/updates/generally-available-application-insights-integration-for-the-azure-functions-net-worker/. You will need to configure the app insights dependency tracking module there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants