1

I’ve an isolated .NET 7 Azure Function App running in Azure. The Function App is connected to an Application Insights when created in Azure Portal.

Currently it uses Serilog to push all logs to Datadog. But it still ingest a lot of traces to Application Insights.

I prefer Datadog to analyze the application logs, but also think that Application Insights has some useful visualizations, e.g. function calls, failed calls etc.

Is it possible to keep using both Datadog and Application Insights, but stop ingesting the trace logs to Application Insights?

2
  • You'll need to create a custom telemetry processor that filters out the traces you don't want to be sent to Application Insights, then configure Application Insights to use the processor. In other words, you need to write some code, there is no one click way to do this. Commented Sep 16, 2023 at 23:22
  • @dhrm Can you please share your code? Commented Sep 27, 2023 at 9:01

1 Answer 1

0

I agree with @Ziya Mert Karakas

But, I have used simple another workaround.

You can use "logLevel" in your host.json to send the logs in your traces table in application insights. If you do not use loglevel by default it is set to use Information level.

enter image description here

In My host.json, I have set it to "Warning" so I will get warning level and higher logs.

host.json:

{
    "version": "2.0",
    "logging": {
      "logLevel": {
        "default": "Warning"
      },
        "applicationInsights": {
        "samplingSettings": {
          "isEnabled": true,
          "excludedTypes": "Request"
        },
        "enableLiveMetricsFilters": true
    }
  }
}

I have Created a simple timer trigger to send log to Datadog and application insights.

Function.cs:


using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using Serilog;
using System;

public static class Function1
{
    [Function("MyFunction")]
    public static void Run(
        [TimerTrigger("*/30 * * * * *")] FunctionContext context)
    {
        // Log using Serilog
        Log.Information("C# Timer trigger function executed at: {time}", DateTime.Now);
        Log.Information("Time in UTC: {time}", DateTime.UtcNow);
        Log.Information("This is Datadog LOG");
        


        // Log using the ILogger provided by Azure Functions
        var logger = context.GetLogger("Function1");
        logger.LogInformation("This is an Azure Functions log message.");
        logger.LogWarning("This is a Warning message");
        logger.LogError("this is a error message");

    }
}

program.cs:

    using Microsoft.Extensions.Hosting;
    using Serilog;
    using Serilog.Sinks.Datadog.Logs;
    using Microsoft.ApplicationInsights.Channel;
    using Microsoft.ApplicationInsights.Extensibility;
    
    var host = new HostBuilder()
        .ConfigureFunctionsWorkerDefaults()
        .ConfigureServices(services =>
        {
            // Configure Serilog for Datadog
            Log.Logger = new LoggerConfiguration()
                .WriteTo.DatadogLogs(apiKey: "xxxxxxxxxxxx")
                .CreateLogger();
        })
        .Build();
    
    host.Run();

Output: Without using : loglevel

other trace log are also available. enter image description here

enter image description here

enter image description here

enter image description here

With : logLevel

only logs which is equal or higher severityLevel of Warning are available.

enter image description here

enter image description here

enter image description here enter image description here

For Reference check this MS Doc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.