.NET
Digma works well with zero code instrumentation and the more traditional manual instrumentation configuration. You can choose the method that works best for you. Make sure to add the required environment variables described in the Instrumenting your code for tracing page.
Automatic Code Instrumentation with .NET
Digma provides an optional capability to add instrumentation to your .NET methods and classes without changing your code. This is done by injecting OpenTelemetry attributes dynamically at runtime when the classes are first loaded. To control the scope of the automatic instrumentation, you can specify a list of relevant namespaces as well as other optional parameters to control how the code is instrumented.
Add the NuGet package
dotnet add package OpenTel.AutoInstrumentation.Digma
Add the following environment variables to load the Digma OTEL plugin
OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES=*
OTEL_DOTNET_AUTO_PLUGINS=OpenTelemetry.AutoInstrumentation.Digma.Plugin, OpenTelemetry.AutoInstrumentation.Digma, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Specify which namespaces to instrument automatically
Create a JSON file autoinstrumentation.rules.json
and save it in the same directly as your .NET application DLLs.
In this file, you can specify rules for the inclusion/exclusion of specific namespaces, classes, and methods. If you wish to name the file differently or place it in a custom location, you can use the following environment variable
DIGMA_AUTOINST_RULES_FILE=\my\custom\path\test.json
The JSON rules file uses a simple syntax to define a set of rules that are used to determine which code should be dynamically instrumented for tracing. You can reference your own namespace's classes and methods. It is recommended to be concise and avoid including low-level infrastructure code that may inflate the tracing data, making it less readable.
{
"include":[
{
"namespaces": "Acme.Core.*" // namespaces field is the minimum
},
{
"namespaces": "Acme.Repositories.*",
"classes": "Repo*",
"methods": "Get*",
"syncModifier": "Async", // Async or Sync, default is null
"accessModifier": "Public", // Private or Public, default is null
"nestedOnly": true // default is false
},
{
"namespaces": "/^Acme\\.V\\d+/", // Regex
"classes": "/^Repo\\w+/", // Regex
"methods": "/^Get\\w+/", // Regex
}
],
"exclude":[
{
"namespaces": "Acme.Tools.*"
}
]
}
Check the Digma autoinstrumentation repo for a more comprehensive documentation of the JSON syntax.
Optional Context for Better Error Processing
For better parsing of .NET errors and to differentiate between external code and your application, it is recommended to add the code.namespace.root
attribute. The easiest way to add that attribute is via the OTEL_RESOURCE_ATTRIBUTES
environment variable.
export OTEL_RESOURCE_ATTRIBUTES=[...existing values],code.namespace.root=YOUR_APP_NAMESPACE
Sample project
Last updated