OpenTelemetry.Instrumentation.Kusto 0.1.0-alpha.3

Prefix Reserved
This is a prerelease version of OpenTelemetry.Instrumentation.Kusto.
dotnet add package OpenTelemetry.Instrumentation.Kusto --version 0.1.0-alpha.3
                    
NuGet\Install-Package OpenTelemetry.Instrumentation.Kusto -Version 0.1.0-alpha.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenTelemetry.Instrumentation.Kusto" Version="0.1.0-alpha.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenTelemetry.Instrumentation.Kusto" Version="0.1.0-alpha.3" />
                    
Directory.Packages.props
<PackageReference Include="OpenTelemetry.Instrumentation.Kusto" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenTelemetry.Instrumentation.Kusto --version 0.1.0-alpha.3
                    
#r "nuget: OpenTelemetry.Instrumentation.Kusto, 0.1.0-alpha.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenTelemetry.Instrumentation.Kusto@0.1.0-alpha.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenTelemetry.Instrumentation.Kusto&version=0.1.0-alpha.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=OpenTelemetry.Instrumentation.Kusto&version=0.1.0-alpha.3&prerelease
                    
Install as a Cake Tool

Kusto Instrumentation for OpenTelemetry

Status
Stability Alpha
Code Owners @MattKotsenas

NuGet version badge NuGet download count badge codecov.io

This is an Instrumentation Library, which instruments Azure Data Explorer (Kusto) client libraries and collects telemetry about Kusto operations.

Steps to enable OpenTelemetry.Instrumentation.Kusto

Step 1: Install Package

Add a reference to the OpenTelemetry.Instrumentation.Kusto package. Also, add any other instrumentations & exporters you will need.

dotnet add package OpenTelemetry.Instrumentation.Kusto --prerelease

Step 2: Enable Kusto Instrumentation at application startup

Kusto instrumentation must be enabled at application startup.

Traces

The following example demonstrates adding Kusto traces instrumentation to a console application. This example also sets up the OpenTelemetry Console exporter, which requires adding the package OpenTelemetry.Exporter.Console to the application.

using OpenTelemetry.Trace;

public class Program
{
    public static void Main(string[] args)
    {
        using var tracerProvider = Sdk.CreateTracerProviderBuilder()
            .AddKustoInstrumentation()
            .AddConsoleExporter()
            .Build();
    }
}
Metrics

The following example demonstrates adding Kusto metrics instrumentation to a console application. This example also sets up the OpenTelemetry Console exporter, which requires adding the package OpenTelemetry.Exporter.Console to the application.

using OpenTelemetry.Metrics;

public class Program
{
    public static void Main(string[] args)
    {
        using var meterProvider = Sdk.CreateMeterProviderBuilder()
            .AddKustoInstrumentation()
            .AddConsoleExporter()
            .Build();
    }
}
List of metrics produced

The instrumentation is implemented based on metrics semantic conventions. Currently, the instrumentation supports the following metric:

Name Instrument Type Unit Description Attributes
db.client.operation.duration Histogram s Duration of database client operations. db.system.name, db.operation.name, db.namespace, db.query.summary[^1], db.query.text[^2], server.address, server.port, error.type[^3]

[^1]: db.query.summary is only included when RecordQuerySummary is enabled [^2]: db.query.text is only included when RecordQueryText is enabled [^3]: error.type is only included when an error occurs

Advanced configuration

This instrumentation can be configured to change the default behavior by using KustoInstrumentationOptions.

Multiple providers

The Kusto instrumentation uses a single, process-wide trace listener, so all TracerProviders and MeterProviders in a process share one set of options. When more than one provider configures the instrumentation, the most recent AddKustoInstrumentation call wins, so configure the options consistently across providers.

Capturing query text

RecordQueryText and RecordQuerySummary rely on the Kusto client emitting the query text in its trace output, which it only does when the KUSTO_DATA_TRACE_REQUEST_BODY environment variable is set to 1. The client reads this variable once, so it must be set before any Kusto client is created. The instrumentation deliberately does not set it, because doing so would enable query-body tracing process-wide as a side effect; that is left to the host as a deliberate choice. If either option is enabled without the variable set, no query text or summary is recorded and a warning is written to the OpenTelemetry-Instrumentation-Kusto event source. The Kusto client's tracing system is described in Controlling and suppressing Kusto SDK client-side tracing.

For example, set the variable during application startup:

Environment.SetEnvironmentVariable("KUSTO_DATA_TRACE_REQUEST_BODY", "1");

RecordQueryText

This option can be set to instruct the instrumentation to record the sanitized query text as an attribute on the activity. Query text is sanitized to remove literal values and replace them with a placeholder character.

The default value is false and can be changed by the code like below.

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddKustoInstrumentation(
        options => options.RecordQueryText = true)
    .AddConsoleExporter()
    .Build();

RecordQuerySummary

This option can be set to instruct the instrumentation to record a query summary as an attribute on the activity. The query summary is automatically generated from the query text and contains the operation type and relevant object names.

The default value is true and can be changed by the code like below.

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddKustoInstrumentation(
        options => options.RecordQuerySummary = false)
    .AddConsoleExporter()
    .Build();

Enrich

This option can be used to enrich the activity with additional information from the raw TraceRecord object. The Enrich action is called only when activity.IsAllDataRequested is true. It contains the activity itself (which can be enriched) and the actual TraceRecord from the Kusto client library.

The following code snippet shows how to add additional tags using Enrich.

using OpenTelemetry.Instrumentation.Kusto.Implementation;

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddKustoInstrumentation(opt => opt.Enrich = (activity, record) =>
    {
        // Add custom tags based on the TraceRecord
        activity.SetTag("azure.kusto.activity_id", record.Activity.ActivityId);
        activity.SetTag("azure.kusto.activity_type", record.Activity.ActivityType);
    })
    .Build();

Processor, is the general extensibility point to add additional properties to any activity. The Enrich option is specific to this instrumentation, and is provided to get access to the TraceRecord object.

Custom Query Summarization

The Enrich callback can be used to implement custom query summarization logic. For example, you can extract summary information from query comments:

using OpenTelemetry.Instrumentation.Kusto.Implementation;

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddKustoInstrumentation(opt =>
    {
        // Disable automatic summarization
        opt.RecordQuerySummary = false;

        // Extract custom summary from query comments
        opt.Enrich = (activity, record) =>
        {
            const string key = "// otel-custom-summary=";
            var message = record.Message.AsSpan();
            var begin = message.IndexOf(key, StringComparison.Ordinal);

            if (begin < 0)
            {
                return;
            }

            var summary = message.Slice(begin + key.Length);
            var end = summary.IndexOfAny('/r', '/n');
            if (end < 0)
            {
                end = summary.Length;
            }

            summary = summary.Slice(0, end).Trim();
            var summaryString = summary.ToString();

            activity.SetTag("db.query.summary", summaryString);
            activity.DisplayName = summaryString;
        };
    })
    .Build();

With this configuration, a query like:

// otel-custom-summary=Get active users
Users
| where IsActive == true
| take 100

Would result in an activity with the summary and display name set to "Get active users".

References

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha.3 44 7/17/2026
0.1.0-alpha.2 62 7/3/2026
0.1.0-alpha.1 57 7/2/2026