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

Commit dc213d0

Browse files
Merge pull request #1704 from RassK/dotnet-custom-span
Update dotnet manual instrumentation instructions
2 parents 0fd38fb + c2f728d commit dc213d0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ To create custom spans and traces, follow these steps:
3131
3232
private static readonly ActivitySource RegisteredActivity = new ActivitySource("Examples.ManualInstrumentations.Registered");
3333
34-
4. Create an ``Activity``. Optionally, set tags:
34+
4. Create an ``Activity`` (Span). Optionally, set tags:
3535

3636
.. code:: csharp
3737
38-
using (var activity = RegisteredActivity.StartActivity("Main"))
38+
using (var activity = RegisteredActivity.StartActivity("Custom Span Name"))
3939
{
40-
activity?.SetTag("foo", "bar1");
41-
// your logic for Main 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
44-
4. 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.
50+
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.
51+
52+
6. Invoke the action that generates an ``Activity``, note the trace ID of the ``Activity``, and locate the trace in Splunk APM. You should now see a span with the display name "Custom Span Name" in the trace tree.
4553

4654
See the :new-page:`OpenTelemetry official documentation <https://opentelemetry.io/docs/languages/net/instrumentation/#traces>` for additional information and examples.
4755

0 commit comments

Comments
 (0)