5.6 KiB
Set up distributed tracing with Application insights
Dapr integrates with Application Insights through OpenTelemetry's default exporter along with a dedicated agent known as Local Forwarder.
Note: Local forwarder is still under preview, but being deprecated. Application insights team recommends to use Opentelemetry collector (which is in alpha state) for the future so that we're working on moving from local forwarder to Opentelemetry collector.
How to configure distributed tracing with Application insights
The following steps will show you how to configure Dapr to send distributed tracing data to Application insights.
Setup Application insights
- First, you'll need an Azure account. Please see instructions here to apply for a free Azure account.
- Follow instructions here to create a new Application Insights resource.
- Get Application insights Intrumentation key from your application insights page
- Go to
Configure -> API Access
- Click
Create API Key
- Select all checkboxes under
Choose what this API key will allow apps to do:
- Read telemetry
- Write annotations
- Authenticate SDK control channel
- Generate Key and get API key
Setup the Local Forwarder
Local environment
- Run localfowarder
docker run -e APPINSIGHTS_INSTRUMENTATIONKEY=<Your Instrumentation Key> -e APPINSIGHTS_LIVEMETRICSSTREAMAUTHENTICATIONAPIKEY=<Your API Key> -d -p 55678:55678 daprio/dapr-localforwarder:0.1-beta1
Note: dapr-localforwarder is created by using 0.1-beta1 release. If you want to create your own image, please use this dockerfile.
- Copy tracing.yaml to a components folder under the same folder where you run you application.
- native.yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: native
spec:
type: exporters.native
metadata:
- name: enabled
value: "true"
- name: agentEndpoint
value: "localhost:55678"
- tracing.yaml
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: tracing
spec:
tracing:
enabled: true
expandParams: true
includeBody: true
- When running in the local mode, you need to launch Dapr with the
--config
parameter:
dapr run --app-id mynode --app-port 3000 --config ./tracing.yaml node app.js
Kubernetes environment
- Download dapr-localforwarder.yaml
- 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
- Deploy dapr-localfowarder.yaml
kubectl apply -f ./dapr-localforwarder.yaml
- Create the following YAML files
- native.yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: native
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
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: tracing
spec:
tracing:
enabled: true
expandParams: true
includeBody: true
- Use kubectl to apply the above CRD files:
kubectl apply -f tracing.yaml
kubectl apply -f native.yaml
- Deploy your app with tracing
When running in the Kubernetes model, you need to add a
dapr.io/config
annotation to your 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 in anyway. Dapr automatically handles distributed tracing for you.
NOTE: You can register multiple exporters at the same time, and tracing logs will be forwarded to all registered exporters.
Generate some workloads. And after a few minutes, you should see tracing logs appearing in your Application Insights resource. And you can also use Application map to examine the topology of your services, as shown below:
Tracing Configuration
The tracing
section under the Configuration
spec contains the following properties:
tracing:
enabled: true
expandParams: true
includeBody: true
The following table lists the different properties.
Property | Type | Description |
---|---|---|
enabled | bool | Set tracing to be enabled or disabled |
expandParams | bool | When true, expands parameters passed to HTTP endpoints |
includeBody | bool | When true, includes the request body in the tracing event |