在应用程序Insights中使用Azure函数的间接日志记录问题

问题描述 投票:0回答:1

我们正在遇到间歇性问题,以登录我们的Azure功能。有时,日志是在应用程序见解中捕获的,但是有时即使没有太多流量,也不会捕获。这是细节。

我们还验证了正确设置的

APPLICATIONINSIGHTS_CONNECTION_STRING

。还检查了
host.json
的日志级别设置。

enter image description here

enter image description here 贝洛是

host.json

文件。

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "CardAlertsEventSubscriber": "Information"
    },
    "applicationInsights": {
      "samplingExcludedTypes": "Request",
      "samplingSettings": {
        "isEnabled": true
      }
    }
  }
}

贝洛(Below)是服务总线主题触发azure函数:
public async Task RunAsync([ServiceBusTrigger("%ServiceBusConfigOption:TopicEventTypes%", "%ServiceBusConfigOption:TopicCardAlertsEventSubscription%",
Connection = "ServiceBusConfigOption:ConnectionString")]
string sbMsg, CancellationToken cancellationToken)
{
    try
    {
        _logger.LogInformation(Constants.Logger.LogStart, nameof(CardAlertsEventSubscriber), nameof(RunAsync));

        var message = sbMsg.AsPoco<CardAlertEvent>();
        var validationResult = _validator.Validate(message);

        if (!validationResult.IsValid)
        {
            await HandleInvalidMessageAsync(message, validationResult, cancellationToken);
            return;
        }

        await ProcessEventAsync(message, sbMsg, cancellationToken);

        _logger.LogInformation(Constants.Logger.LogEnd, nameof(CardAlertsEventSubscriber), nameof(RunAsync));
    }
    catch (Exception ex)
    {
        LogError(ex, sbMsg);
        throw;
    }
}

below是csproj

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup Label="Globals">
        <SccProjectName>SAK</SccProjectName>
        <SccProvider>SAK</SccProvider>
        <SccAuxPath>SAK</SccAuxPath>
        <SccLocalPath>SAK</SccLocalPath>
    </PropertyGroup>
    <PropertyGroup>
        <TargetFramework>net6</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    </PropertyGroup>
    
    <ItemGroup>
        <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.17.5" />
        <PackageReference Include="FluentValidation" Version="9.5.2" />
        <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.27.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.15.1" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
        <PackageReference Include="IEvangelist.Azure.CosmosRepository" Version="3.5.3" />
        <PackageReference Include="system.drawing.common" Version="8.0.5" />
        <PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.8" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
        <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="5.7.0" />
        <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.7.0" />
    </ItemGroup>
    <ItemGroup>
        <None Update="host.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
</Project>

什么可能导致应用程序见解中间歇性记录问题?

我应该检查还有其他配置或设置吗?
    

如果Azure函数应用程序在消费计划上运行,该应用程序允许动态缩放,则可能会导致记录一致性的问题,因为功能根据负载而定缩放或向下缩放。

间歇性网络问题可能导致日志不会被应用程序见解摄入。检查是否有任何网络限制可能会影响到应用程序见解端点的连接。 我创建了一个服务总线触发Azure功能,并能够使用Azure Application Insight配置记录。

c# azure-functions azure-application-insights
1个回答
0
投票

public class Function1 { [FunctionName("Function1")] public void Run([ServiceBusTrigger("topic1", "sub1", Connection = "demo")]string mySbMsg, CancellationToken cancellationToken, ILogger log) { try { log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}"); for (int i = 0; i < 10; i++) { if (cancellationToken.IsCancellationRequested) { log.LogInformation("Cancellation requested. Exiting function gracefully."); return; } log.LogInformation($"Processing step {i + 1}"); Task.Delay(1000); } log.LogInformation("Finished processing the message successfully."); } catch (Exception ex) { log.LogError($"Exception occurred: {ex.Message}"); throw; } } }

-host.json:

{ "version": "2.0", "logging": { "logLevel": { "Function1": "Information" }, "applicationInsights": { "samplingExcludedTypes": "Request", "samplingSettings": { "isEnabled": true } } } }

.csproj:

<ItemGroup> <PackageReference Include="Azure.Identity" Version="1.13.0" /> <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.4" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.5.0" /> </ItemGroup> Console输出:

Functions:

        Function1: serviceBusTrigger

For detailed output, run func with --verbose flag.
[2025-02-03T11:55:38.639Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2025-02-03T11:57:33.015Z] Executing 'Function1' (Reason='(null)', Id=25069f26-368c-4175-9a4c-075afa0f2c21)
[2025-02-03T11:57:33.030Z] Trigger Details: MessageId: e6cfe1d7eeb243758ae295938e43adfa, SequenceNumber: 4, DeliveryCount: 2, EnqueuedTimeUtc: 2025-02-03T11:56:22.5050000+00:00, LockedUntilUtc: 2025-02-03T11:58:22.6760000+00:00, SessionId: (null)
[2025-02-03T11:57:53.403Z] C# ServiceBus topic trigger function processed message: Hi Pravallika, Welcome!
[2025-02-03T11:57:53.486Z] Processing step 1
[2025-02-03T11:57:53.554Z] Processing step 2
[2025-02-03T11:57:53.645Z] Processing step 3
[2025-02-03T11:57:53.745Z] Processing step 4
[2025-02-03T11:57:53.783Z] Processing step 5
[2025-02-03T11:57:53.852Z] Processing step 6
[2025-02-03T11:57:53.919Z] Processing step 7
[2025-02-03T11:57:53.993Z] Processing step 8
[2025-02-03T11:57:54.139Z] Processing step 9
[2025-02-03T11:57:54.264Z] Processing step 10
[2025-02-03T11:57:54.285Z] Finished processing the message successfully.
[2025-02-03T11:57:54.437Z] Executed 'Function1' (Succeeded, Id=25069f26-368c-4175-9a4c-075afa0f2c21, Duration=21778ms)

Application Insights:


    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.