Skip to content

Latest commit

 

History

History
186 lines (138 loc) · 6.54 KB

azure-monitor.md

File metadata and controls

186 lines (138 loc) · 6.54 KB

Set up Application Insights for distributed tracing

Dapr integrates with Application Insights through OpenTelemetry's default exporter along with a dedicated agent known as the Local Forwarder.

Note: The local forwarder is still under preview, but being deprecated. The Application Insights team recommends using Opentelemetry collector (which is in alpha state) for the future so we're working on moving from local forwarder to Opentelemetry collector.

How to configure distributed tracing with Application insights

The following steps show you how to configure Dapr to send distributed tracing data to Application insights.

Setup Application Insights

  1. First, you'll need an Azure account. Please see instructions here to apply for a free Azure account.
  2. Follow instructions here to create a new Application Insights resource.
  3. Get Application insights Intrumentation key from your application insights page
  4. On the Application Insights side menu, go to Configure -> API Access
  5. Click Create API Key
  6. Select all checkboxes under Choose what this API key will allow apps to do:
    • Read telemetry
    • Write annotations
    • Authenticate SDK control channel
  7. Generate Key and get API key

Setup the Local Forwarder

Self hosted environment

This is for running the local forwarder on your machine.

  1. Run the local fowarder
docker run -e APPINSIGHTS_INSTRUMENTATIONKEY=<Your Instrumentation Key> -e APPINSIGHTS_LIVEMETRICSSTREAMAUTHENTICATIONAPIKEY=<Your API Key> -d -p 55678:55678 daprio/dapr-localforwarder:latest

Note: dapr-localforwarder is the forked version of ApplicationInsights Localforwarder, that includes the minor changes for Dapr. We're working on migrating to opentelemetry-sdk and opentelemetry collector.

  1. Create the following YAML files. Copy the native.yaml component file and tracing.yaml configuration file to the components/ sub-folder under the same folder where you run your application.
  • native.yaml component
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: native
  namespace: default
spec:
  type: exporters.native
  metadata:
  - name: enabled
    value: "true"
  - name: agentEndpoint
    value: "localhost:55678"
  • tracing.yaml configuration
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: tracing
  namespace: default
spec:
  tracing:
    samplingRate: "1"
  1. When running in the local self hosted mode, you need to launch Dapr with the --config parameter:
dapr run --app-id mynode --app-port 3000 --config ./components/tracing.yaml node app.js

Kubernetes environment

  1. Download dapr-localforwarder.yaml
  2. Replace <APPINSIGHT INSTRUMENTATIONKEY> with your Instrumentation Key and <APPINSIGHT API KEY> with the generated key in the file
          - name: APPINSIGHTS_INSTRUMENTATIONKEY
            value: <APPINSIGHT INSTRUMENTATIONKEY> # Replace with your ikey
          - name: APPINSIGHTS_LIVEMETRICSSTREAMAUTHENTICATIONAPIKEY
            value: <APPINSIGHT API KEY> # Replace with your generated api key
  1. Deploy dapr-localfowarder.yaml
kubectl apply -f ./dapr-localforwarder.yaml
  1. Create the following YAML files
  • native.yaml component
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: native
  namespace: default
spec:
  type: exporters.native
  metadata:
  - name: enabled
    value: "true"
  - name: agentEndpoint
    value: "<Local forwarder address, e.g. dapr-localforwarder.default.svc.cluster.local:55678>"
  • tracing.yaml configuration
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: tracing
  namespace: default
spec:
  tracing:
    samplingRate: "1"
  1. Use kubectl to apply the above CRD files:
kubectl apply -f tracing.yaml
kubectl apply -f native.yaml
  1. Deploy your app with tracing

When running in Kubernetes mode, apply the configuration by adding a dapr.io/config annotation to the container that you want to participate in the distributed tracing, as shown in the following example:

apiVersion: apps/v1
kind: Deployment
metadata:
  ...
spec:
  ...
  template:
    metadata:
      ...
      annotations:
        dapr.io/enabled: "true"
        dapr.io/id: "calculator-front-end"
        dapr.io/port: "8080"
        dapr.io/config: "tracing"

That's it! There's no need include any SDKs or instrument your application code. Dapr automatically handles the distributed tracing for you.

NOTE: You can register multiple exporters at the same time, and the tracing logs are forwarded to all registered exporters.

Deploy and run some applications. After a few minutes, you should see tracing logs appearing in your Application Insights resource. You can also use Application Map to examine the topology of your services, as shown below:

Application map

Tracing configuration

The tracing section under the Configuration spec contains the following properties:

tracing:
    samplingRate: "1"

The following table lists the different properties.

Property Type Description
samplingRate string Set sampling rate for tracing to be enabled or disabled.

samplingRate is used to enable or disable the tracing. To disable the sampling rate , set samplingRate : "0" in the configuration. The valid range of samplingRate is between 0 and 1 inclusive. The sampling rate determines whether a trace span should be sampled or not based on value. samplingRate : "1" will always sample the traces.By default, the sampling rate is 1 in 10,000

References