You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+98-4Lines changed: 98 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,10 @@ Datadog APM traces the path of each request through your application stack, reco
7
7
This repository contains what you need to trace C# applications. Some quick notes up front:
8
8
9
9
-**Datadog C# APM is currently in Alpha**
10
-
- It supports .Net Framework version above 4.5 and .Net Core 2.0
11
-
- It does not support out of process propagation
12
-
- It does not provide automatic framework instrumentation, all instrumentation is [manual](#manual-instrumentation)
13
-
- Multiple AppDomains are not supported (but it could work).
10
+
- It supports .Net Framework version above 4.5 and .Net Core 2.0.
11
+
- It does not support out of process propagation.
12
+
- It does not provide automatic framework instrumentation, all instrumentation is [manual](#manual-instrumentation).
13
+
- Multiple AppDomains are not supported.
14
14
- Our tracer is based on the current OpenTracing standard, however we do not yet support the following features: `FollowsFrom` references, `Baggage` or `Log`.
15
15
16
16
## The Components
@@ -26,10 +26,104 @@ Before instrumenting your code, [install the Datadog Agent](https://app.datadogh
26
26
27
27
### Manual Instrumentation
28
28
29
+
#### Introduction
30
+
31
+
Before instrumenting your application, have a look at the [Datadog APM Terminology](https://docs.datadoghq.com/tracing/terminology/) to get familiar with the core concepts of Datadog APM.
32
+
29
33
#### Setup
30
34
35
+
In order to instrument you code you need to add the `Datadog.Trace` NuGet package to your project.
36
+
37
+
Your tracing adventure starts with the `ITracer` object, you should typically instantiate only one `ITracer` for the lifetime of your app and use it in all places of your code where you want to add tracing. Instantiating the `ITracer` is done with the `TracerFactory.GetTracer` method.
38
+
39
+
To get a tracer with default parameters (i.e. the agent endpoint set to `http://localhost:8126`, and the default service name set to the name of the AppDomain):
40
+
41
+
```csharp
42
+
ITracertracer=TracerFactory.GetTracer();
43
+
```
44
+
45
+
Customize your tracer object by adding optional parameters to the `TracerFactory.GetTracer` call:
46
+
47
+
By default the service name is set to the name of the AppDomain, choose a custom name with the defaultServiceName parameter:
Use the shared `ITracer` object you created to create spans, instrument any section of your code, and get detailed metrics on it.
62
+
63
+
Set the ServiceName to recognize which service this trace belongs to; if you don't, the parent span's service name or in case of a root span the defaultServiceName stated above is used.
64
+
65
+
Set the ResourceName to scope this trace to a specific endpoint or SQL Query; For instance:
66
+
- "GET /users/:id"
67
+
- "SELECT * FROM ..."
68
+
if you don't the OperationName will be used.
69
+
70
+
A minimal examples is:
71
+
72
+
```csharp
73
+
using (ISpanspan=tracer.BuildSpan("OperationName").WithTag(DDTags.ServiceName, "ServiceName").Start())
74
+
{
75
+
span.SetTag(DDTags.ResourceName, "ResourceName");
76
+
77
+
// Instrumented code
78
+
Thread.Sleep(1000);
79
+
}
80
+
```
81
+
82
+
You may also choose, not to use the `using` construct and close the `ISpan` object explictly:
// Finish sets the span duration and sends it to the agent (if you don't call finish the data will never be sent to Datadog)
93
+
span.Finish();
94
+
```
95
+
96
+
You may add custom tags by calling `ISpan.SetTag`:
97
+
98
+
```csharp
99
+
ISpanspan=tracer.BuildSpan("SqlQuery").Start();
100
+
span.SetTag("db.rows", 10);
101
+
```
102
+
103
+
You should not have to explicitly declare parent/children relationship between your spans, but to override the default behavior - a new span is considered a child of the innermost open span in its logical context- use:
-[OpenTracing's documentation](https://github.com/opentracing/opentracing-csharp); feel free to use the Trace C# API to customize your instrumentation.
0 commit comments