How to track DB Interactions on .NET Applications with the OpenTelemetry Agent


Overview

With .NET Applications and the OpenTelemetry Agent, an additional Environment Variable needs to be added to track the interactions with DB Servers beyond the default Environment Variables that vFunction uses. This Environment Variable should be added to any Services that interact with this DB Server. The Environment Variable will change based on the type of DB Server, whether Microsoft SQL Server or Oracle DB. See below for the environmentally-specific variable and examples in various startup workflows.

See the Installation Wizard for a full set of environmentally-specific variables.


Tracking Microsoft SQL Server DB Interactions

Add the following flag to any Services that interact with the Microsoft SQL Server to see the DB Tracking as a Resource in the vFunction Analysis:

OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT=true
Sample Linux .NET Arguments for Microsoft SQL Server DB Interactions
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions from the vFunction Server UI

export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=http://$VF_SERVER_ADDRESS/api/unauth/otlp
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=none
export OTEL_LOGS_EXPORTER=none
export OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT=true
export OTEL_EXPORTER_OTLP_HEADERS=$VF_APP_ID
export OTEL_SERVICE_NAME=$MY_SERVICE
. $HOME/.otel-dotnet-auto/instrument.sh
dotnet run
Sample Windows .NET Command Line Arguments for Microsoft SQL Server DB Interactions
### Find-and-Replace the SERVICE_DISPLAY_NAME with your Service
### Find-and-Replace $RUN_APP.EXE with the name and path to the Application to be profiled
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions in the vFunction Server UI

$env:OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf'
$env:OTEL_EXPORTER_OTLP_ENDPOINT='http://$VF_SERVER_ADDRESS/api/unauth/otlp'
$env:OTEL_TRACES_EXPORTER='otlp'
$env:OTEL_METRICS_EXPORTER=none
$env:OTEL_LOGS_EXPORTER=none
$env:OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT=true
$env:OTEL_EXPORTER_OTLP_HEADERS='X-VF-APP=$VF_APP_ID'
Register-OpenTelemetryForCurrentSession -OTelServiceName "SERVICE_DISPLAY_NAME"
.\$RUN_APP.EXE
Sample Windows .NET IIS Arguments for Microsoft SQL Server DB Interactions
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions in the vFunction Server UI
### Under the applicationPools node, find the relevant application pool and add the env vars. Note that the example below modifies the DefaultAppPool:

<add name="DefaultAppPool" autoStart="true">
 <environmentVariables>
  <add name="OTEL_EXPORTER_OTLP_PROTOCOL" value="http/protobuf" />
  <add name="OTEL_EXPORTER_OTLP_ENDPOINT" value="http://$VF_SERVER_ADDRESS/api/unauth/otlp" />
  <add name="OTEL_TRACES_EXPORTER" value="otlp" />
  <add name="OTEL_METRICS_EXPORTER" value="none" />
  <add name="OTEL_LOGS_EXPORTER" value="none" />
  <add name="OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT" value="true" />
  <add name="OTEL_EXPORTER_OTLP_HEADERS" value="X-VF-APP=$VF_APP_ID" />
 </environmentVariables>
</add>
Sample Windows .NET Windows Service Arguments for Microsoft SQL Server DB Interactions
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions in the vFunction Server UI

OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_ENDPOINT=http://$VF_SERVER_ADDRESS/api/unauth/otlp
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=none
OTEL_LOGS_EXPORTER=none
OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT=true
OTEL_EXPORTER_OTLP_HEADERS=X-VF-APP=$VF_APP_ID

Tracking Oracle DB Interactions

Add the following flag to any Services that interact with the Microsoft SQL Server to see the DB Tracking as a Resource in the vFunction Analysis:

OTEL_DOTNET_AUTO_ORACLEMDA_SET_DBSTATEMENT_FOR_TEXT=true
Sample Linux .NET Arguments for Microsoft SQL Server DB Interactions
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions from the vFunction Server UI

export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=http://$VF_SERVER_ADDRESS/api/unauth/otlp
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=none
export OTEL_LOGS_EXPORTER=none
export OTEL_DOTNET_AUTO_ORACLEMDA_SET_DBSTATEMENT_FOR_TEXT=true
export OTEL_EXPORTER_OTLP_HEADERS=$VF_APP_ID
export OTEL_SERVICE_NAME=$MY_SERVICE
. $HOME/.otel-dotnet-auto/instrument.sh
dotnet run
Sample Windows .NET Command Line Arguments for Microsoft SQL Server DB Interactions
### Find-and-Replace the SERVICE_DISPLAY_NAME with your Service
### Find-and-Replace $RUN_APP.EXE with the name and path to the Application to be profiled
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions in the vFunction Server UI

$env:OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf'
$env:OTEL_EXPORTER_OTLP_ENDPOINT='http://$VF_SERVER_ADDRESS/api/unauth/otlp'
$env:OTEL_TRACES_EXPORTER='otlp'
$env:OTEL_METRICS_EXPORTER=none
$env:OTEL_LOGS_EXPORTER=none
$env:OTEL_DOTNET_AUTO_ORACLEMDA_SET_DBSTATEMENT_FOR_TEXT=true
$env:OTEL_EXPORTER_OTLP_HEADERS='X-VF-APP=$VF_APP_ID'
Register-OpenTelemetryForCurrentSession -OTelServiceName "SERVICE_DISPLAY_NAME"
.\$RUN_APP.EXE
Sample Windows .NET IIS Arguments for Microsoft SQL Server DB Interactions
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions in the vFunction Server UI
### Under the applicationPools node, find the relevant application pool and add the env vars. Note that the example below modifies the DefaultAppPool:

<add name="DefaultAppPool" autoStart="true">
 <environmentVariables>
  <add name="OTEL_EXPORTER_OTLP_PROTOCOL" value="http/protobuf" />
  <add name="OTEL_EXPORTER_OTLP_ENDPOINT" value="http://$VF_SERVER_ADDRESS/api/unauth/otlp" />
  <add name="OTEL_TRACES_EXPORTER" value="otlp" />
  <add name="OTEL_METRICS_EXPORTER" value="none" />
  <add name="OTEL_LOGS_EXPORTER" value="none" />
  <add name="OTEL_DOTNET_AUTO_ORACLEMDA_SET_DBSTATEMENT_FOR_TEXT" value="true" />
  <add name="OTEL_EXPORTER_OTLP_HEADERS" value="X-VF-APP=$VF_APP_ID" />
 </environmentVariables>
</add>
Sample Windows .NET Windows Service Arguments for Microsoft SQL Server DB Interactions
### Find-and-replace $VF_SERVER_ADDRESS with the URL for your organization’s vFunction Server
### Find-and-replace $VF_APP_ID with the Application UUID created with the Installation Instructions in the vFunction Server UI

OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_ENDPOINT=http://$VF_SERVER_ADDRESS/api/unauth/otlp
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=none
OTEL_LOGS_EXPORTER=none
OTEL_DOTNET_AUTO_ORACLEMDA_SET_DBSTATEMENT_FOR_TEXT=true
OTEL_EXPORTER_OTLP_HEADERS=X-VF-APP=$VF_APP_ID