Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit c2f728d

Browse files
committed
add sampling optimizations
1 parent 764d801 commit c2f728d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ To create custom spans and traces, follow these steps:
3737
3838
using (var activity = RegisteredActivity.StartActivity("Custom Span Name"))
3939
{
40-
activity?.SetTag("foo", "bar1");
41-
// your logic for custom activity
40+
// Check if the activity is sampled and if full data collection is enabled.
41+
// This ensures that tags and other custom attributes are only set when the activity is being recorded.
42+
// Note: Ensure that skipping logic based on sampling does not interfere with essential business operations.
43+
if(activity?.IsAllDataRequested)
44+
{
45+
// your logic for custom activity
46+
activity.SetTag("foo", "bar1");
47+
}
4248
}
4349
4450
5. Register your ``ActivitySource`` by setting the ``OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES`` environmental variable. You can set the value to either ``Examples.ManualInstrumentations.Registered`` or to ``Examples.ManualInstrumentations.*``, which registers the entire prefix.

0 commit comments

Comments
 (0)