2.1 KiB
2.1 KiB
description
| description |
|---|
| Create a new auto-instrumentation integration |
Create a new auto-instrumentation integration for the Datadog .NET tracer.
Follow these steps:
-
Gather requirements:
- Target library name and NuGet package
- Supported version range
- Methods to instrument (assembly, type, method signatures)
- Integration category (e.g., HTTP, Database, Messaging, etc.)
-
Create integration class:
- Location:
tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/<Area>/<Integration>.cs - Add
[InstrumentMethod]attribute with:AssemblyName: Target assemblyTypeName: Fully qualified type nameMethodName: Method to instrumentReturnTypeName: Method return typeParameterTypeNames: Array of parameter typesMinimumVersionandMaximumVersion: Version rangeIntegrationName: Unique integration identifier
- Implement
OnMethodBegin(for method entry) - Implement
OnMethodEndorOnAsyncMethodEnd(for method exit)
- Location:
-
Use duck typing for third-party types:
- Define interface with required properties/methods
- Use
where TTarget : IMyInterface, IDuckTypeconstraint - Or use
target.DuckCast<IMyInterface>()for runtime casting
-
Add integration tests:
- Location:
tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/<Area>/ - Create sample application:
tracer/test/test-applications/integrations/<Library>/ - Test multiple library versions (package_versions.props)
- Verify spans are created with correct tags
- Location:
-
Generate boilerplate:
- Run:
./tracer/build.ps1 RunInstrumentationGenerator
- Run:
-
Update documentation:
- Add integration to supported libraries list if needed
Reference files:
docs/development/AutomaticInstrumentation.md- Complete integration guidedocs/development/DuckTyping.md- Duck typing patternstracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/- Existing integrations
After creating:
- Run the instrumentation generator
- Build the tracer
- Run integration tests
- Verify spans in test output