Skip to content

Commit 9cd586c

Browse files
authored
Merge branch 'main' into sdk-metrics-exemplar-concurrency
2 parents 22fbc3b + b10f84a commit 9cd586c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/trace/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ or
9595
> [!NOTE]
9696
> Activities which are not yet finished/stopped will not be exported.
9797
98+
:stop_sign: You should avoid calling
99+
[Activity.AddEvent](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.addevent)
100+
in a loop. Activities are not designed to handle hundreds or thousands of
101+
events, a better model is to use [correlated
102+
logs](../logs/README.md#log-correlation) or
103+
[Activity.Links](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity.links).
104+
105+
> [!WARNING]
106+
> The following code is not modeling `Activity.Events` correctly, and is very
107+
likely to have usability and performance problems.
108+
109+
```csharp
110+
private static async Task Test()
111+
{
112+
Activity activity = Activity.Current;
113+
114+
while (true)
115+
{
116+
activity.AddEvent(new ActivityEvent("Processing background task."));
117+
await Task.Delay(1000);
118+
}
119+
}
120+
```
121+
98122
## TracerProvider Management
99123

100124
:stop_sign: You should avoid creating `TracerProvider` instances too frequently,

0 commit comments

Comments
 (0)