Correlate Microsoft SQL Server queries with .NET traces

Skip step 1 if you've already instrumented your .NET application.

  1. If your .NET application is uninstrumented, instrument it first:
    1. If you plan to use the OpenTelemetry.AutoInstrumentation NuGet package (otel-dotnet-autoinstrumentation), make sure that you use its latest version, which is currently 1.12.0.
    2. Follow the steps to instrument your .NET application.
    3. Add these environment variables to the OTLP exporter for the .NET application:
      1. OTEL_EXPORTER_OTLP_INSECURE: "true"

      2. OTEL_EXPORTER_OTLP_PROTOCOL: "grpc"

      3. OTEL_RESOURCE_ATTRIBUTES: prepend service.name=your-app-name to your current values. For example, "service.name=your-app-name, deployment.environment=environment-name"

      4. OTEL_EXPORTER_OTLP_ENDPOINT: "http://your-otel-collector-endpoint:4317"

        Note: Port 4317 is for OTLP over gRPC whereas port 4318 is for OTLP over HTTP/JSON.
      5. OTEL_DOTNET_EXPERIMENTAL_SQLCLIENT_ENABLE_TRACE_CONTEXT_PROPAGATION: "true"

      apiVersion: apps/v1
      kind: Deployment
      spec:
         selector:
            matchLabels:
               app: your-application
         template:
            spec:
               containers:
                  - name: myapp
                    env:
                        - name: SPLUNK_OTEL_AGENT
                          valueFrom:
                            fieldRef:
                              fieldPath: status.hostIP
                        - name: OTEL_EXPORTER_OTLP_INSECURE
                          value: "true"
                        - name: OTEL_EXPORTER_OTLP_PROTOCOL
                          value: "grpc"
                        - name: OTEL_RESOURCE_ATTRIBUTES
                          value: "service.name=your-app-name, deployment.environment=environment-name"
                        - name: OTEL_SERVICE_NAME
                          value: "service-name"                   
                        - name: OTEL_EXPORTER_OTLP_ENDPOINT
                          value: "http://$(SPLUNK_OTEL_AGENT):4318"
                        - name: OTEL_DOTNET_EXPERIMENTAL_SQLCLIENT_ENABLE_TRACE_CONTEXT_PROPAGATION
                          value: "true"
      
  2. In your .csproj file, use the latest version (1.11.0) of the Splunk OpenTelemetry.AutoInstrumentation library:
    <PackageReference Include="Splunk.OpenTelemetry.AutoInstrumentation" Version="1.11.0" /> 
  3. Restart your application.

You can now view database query correlation with APM traces from the APM trace view or the Query details pane in the Database Monitoring Overview.