This is an Instrumentation Library, which instruments Dataverse ServiceClient and collects traces about incoming Dataverse requests.
This component is based on the v1.24 of database semantic conventions. For details on the default set of attributes that are added, checkout Traces sections below.
Add a reference to
the RemyDuijkeren.OpenTelemetry.Instrumentation.DataverseServiceClient
package. Also, add any other instrumentation and exporters you will need.
dotnet add package RemyDuijkeren.OpenTelemetry.Instrumentation.DataverseServiceClientDataverse ServiceClient instrumentation must be enabled at application startup, when setting up the host for
OpenTelemetry. See the
package OpenTelemetry.Extensions.Hosting
for more info how to add OpenTelemetry to the
application.
The following example demonstrates adding Dataverse ServiceClient instrumentation within the extension method
WithTracing() on the OpenTelemetryBuilder. The extension method AddDataverseServiceClientInstrumentation()
registers the instrumentation to the TracerProvider and tries to replace any registered IOrganizationService,
IOrganizationServiceAsync or IOrganizationServiceAsync2 by wrapping the service into
OpenTelemetryServiceClientDecorator that will do the actual tracing.
This example also sets up the Console Exporter, which requires adding the
package OpenTelemetry.Exporter.Console
to the application.
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Trace;
public void ConfigureServices(IServiceCollection services)
{
services.AddOpenTelemetry()
.WithTracing(builder => builder
.AddDataverseServiceClientInstrumentation()
.AddConsoleExporter());
}Optional create the OpenTelemetryServiceClientDecorator manually by passing it a ServiceClient like:
using Microsoft.PowerPlatform.Dataverse.Client;
using OpenTelemetry.Instrumentation.DataverseServiceClient;
// Add 'OpenTelemetry.Instrumentation.DataverseServiceClient' as source
// Create ServiceClient and wrap it into OpenTelemetryServiceClientDecorator
var serviceClient = new ServiceClient(new ConnectionOptions { /* your config */ } );
IOrganizationServiceAsync2 decoratedServiceClient = new OpenTelemetryServiceClientDecorator(serviceClient);
// Use the decoratedServiceClient as you would use the serviceClient
var response = decoratedServiceClient.Execute(new WhoAmIRequest());The following list of attributes is added by default on activity. See db-spans for more details about each attribute:
db.operationdb.sql.tabledb.statementdb.systemdb.namedb.connection_stringdb.userdb.dataverse.organization_iddb.dataverse.organization_versiondb.dataverse.geoerror.typeserver.addressserver.port
Application Insights example:
When you have helper methods for Dataverse calls that you want to trace, you can create custom activities, using the
extension method StartDataverseActivity:
public class DataverseHelper
{
private readonly IOrganizationService _service;
public DataverseHelper(IOrganizationService service)
{
_service = service;
}
public void MyFirstHelperMethod()
{
using Activity? activity = _service.StartDataverseActivity();
// Add custom attributes (optional)
activity?.SetTag("custom.tag", "custom value");
// Use the service with your own logic
var response = _service.Execute(new WhoAmIRequest());
}
}There are overloads for StartDataverseActivity to pass in the Entity or EntityReference, statement and
operation. By default, the operation is the name of the method that called StartDataverseActivity, in this example
MyFirstHelperMethod.

