Correlate database 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 version 1.15.0 or higher.
    2. Follow the steps to instrument your .NET application.
    3. Add these environment variables to the OTLP exporter for the .NET application:
      • OTEL_EXPORTER_OTLP_INSECURE: "true"

      • OTEL_EXPORTER_OTLP_PROTOCOL: "grpc"

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

      • OTEL_EXPORTER_OTLP_ENDPOINT: "http://your-otel-collector-endpoint:port"

        Note: Use port 4317 for OTLP over gRPC and port 4318 for OTLP over HTTP/JSON.
      • OTEL_DOTNET_EXPERIMENTAL_SQLCLIENT_ENABLE_TRACE_CONTEXT_PROPAGATION: "true"

      Note: Trace context propagation (OTEL_DOTNET_EXPERIMENTAL_SQLCLIENT_ENABLE_TRACE_CONTEXT_PROPAGATION) to SQL Server requires .NET 8 or later. It is not supported on .NET Framework or earlier .NET versions.

      Example:

      YAML
      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):4317"
                        - name: OTEL_DOTNET_EXPERIMENTAL_SQLCLIENT_ENABLE_TRACE_CONTEXT_PROPAGATION
                          value: "true"
  2. In your .csproj file, use version 1.14.0 or higher of the Splunk OpenTelemetry.AutoInstrumentation library:
    CODE
    <PackageReference Include="Splunk.OpenTelemetry.AutoInstrumentation" Version="1.14.0" />
  3. Restart your application.