Darko
Darko

Reputation: 25

How to configure telemetry from dapr to Application Insights in my local development environment?

I've been struggling with this issue for a few hours now and I can't find a good explanation or example in the documentation or any blog post. They all seem to say you can do it, but reference an example of how easy it is to configure the Zipkin server which pretty much works out of the box and is not a very useful example.

So far I've tried one approach referencing "Azure Application Insights exporter" installed in the Dapr runtime as a component and another using the Open Telemetry protocol. I'm not even sure what the endpoint for App Insights should be in either case. The microservices are simple .NET web apis.

Azure Application Insights exporter

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  tracing:
    enabled: true
    exporter:
      type: azure-appinsights
      config:
        instrumentationKey: 
        endpoint: https://westeurope-5.in.applicationinsights.azure.com/
components:
  exporters:
    azure-appinsights:
      type: exporters.azure.appinsights
      version: v1

Open Telemetry

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
  namespace: default
spec:
  tracing:
    samplingRate: "1"
    otel:
      endpointAddress: https://westeurope-5.in.applicationinsights.azure.com/

Has anyone managed to configure and send telemetry to App Insights from a local dev machine running dapr?

Upvotes: 0

Views: 849

Answers (1)

Suresh Chikkam
Suresh Chikkam

Reputation: 3415

  • Re-check your YAML file, make sure that the instrumentationKey is properly set to the key associated with your Application Insights resource.
  • You do not need to specify the Endpoint property in your YAML file. The exporter will automatically send telemetry to the correct endpoint based on the instrumentation key that you provide.
  • Endpoint and instrumentation key values may vary depending on the configuration of the Azure Application Insights resource.

I have installed Dapr, Open Telemetry .NET SDK and the Open Telemetry Exporter for Application Insights. Connected the Application Insights to the app by adding the below step. enter image description here

Manual using config.yaml file we can connect the app Insight but tried by adding through connected services check below. enter image description here

Configure Dapr to use OpenTelemetry by creating dapr.yaml:

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  tracing:
    samplingRate: "1"
    otel:
      endpointAddress: https://dc.services.visualstudio.com/v2/track

Here is the sample code:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenTelemetry.Exporter.AzureMonitor;
using OpenTelemetry.Trace;
 
public static void Main(string[] args)
{
    CreateHostBuilder(args).Build().Run();
}
 
public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureServices((hostContext, services) =>
        {
            services.AddOpenTelemetryTracing(builder =>
            {
                builder
                    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(hostContext.HostingEnvironment.ApplicationName))
                    .AddAspNetCoreInstrumentation()
                    .AddHttpClientInstrumentation()
                    .AddAzureMonitorExporter(o =>
                    {
                        o.ConnectionString = "InstrumentationKey=<Your-Instrumentation-Key>";
                    });
            });
            services.AddHostedService<Worker>();
        });
  • OpenTelemetry tracing using the AddOpenTelemetryTracing method configures an Azure Monitor exporter to send telemetry data to Azure Monitor. Finally, it adds a hosted service to run. enter image description here

Reference:

Upvotes: 0

Related Questions