From baeec84a90883add2f943b8af49d98bde34199d0 Mon Sep 17 00:00:00 2001 From: Rasmus Kuusmann Date: Fri, 14 Mar 2025 15:02:40 +0200 Subject: [PATCH 1/4] update manual inst docs Signed-off-by: Rasmus Kuusmann --- .../instrumentation/manual-dotnet-instrumentation.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst index b5d0d4062..8bdbf2999 100644 --- a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst +++ b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst @@ -31,17 +31,19 @@ To create custom spans and traces, follow these steps: private static readonly ActivitySource RegisteredActivity = new ActivitySource("Examples.ManualInstrumentations.Registered"); -4. Create an ``Activity``. Optionally, set tags: +4. Create an ``Activity`` (Span). Optionally, set tags: .. code:: csharp - using (var activity = RegisteredActivity.StartActivity("Main")) + using (var activity = RegisteredActivity.StartActivity("Custom Span Name")) { activity?.SetTag("foo", "bar1"); - // your logic for Main activity + // your logic for your custom activity } -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. +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. + +6. Invoke the action that generates an ``Activity``, note the trade 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. See the :new-page:`OpenTelemetry official documentation ` for additional information and examples. From 6072565e5af3ad7199a062df0c2b6442ede1e23e Mon Sep 17 00:00:00 2001 From: Rasmus Kuusmann Date: Fri, 14 Mar 2025 15:05:16 +0200 Subject: [PATCH 2/4] remove a word Signed-off-by: Rasmus Kuusmann --- .../instrumentation/manual-dotnet-instrumentation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst index 8bdbf2999..137385347 100644 --- a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst +++ b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst @@ -38,7 +38,7 @@ To create custom spans and traces, follow these steps: using (var activity = RegisteredActivity.StartActivity("Custom Span Name")) { activity?.SetTag("foo", "bar1"); - // your logic for your custom activity + // your logic for custom activity } 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. From 764d80118afbe79c4c0aa7d751ef243d912aa82f Mon Sep 17 00:00:00 2001 From: Rasmus Kuusmann Date: Fri, 14 Mar 2025 15:44:13 +0200 Subject: [PATCH 3/4] fix typo Signed-off-by: Rasmus Kuusmann --- .../instrumentation/manual-dotnet-instrumentation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst index 137385347..584c629d2 100644 --- a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst +++ b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst @@ -43,7 +43,7 @@ To create custom spans and traces, follow these steps: 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. -6. Invoke the action that generates an ``Activity``, note the trade 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. +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. See the :new-page:`OpenTelemetry official documentation ` for additional information and examples. From c2f728db4456ea78d9eb642219ffb0cf72cc966f Mon Sep 17 00:00:00 2001 From: Rasmus Kuusmann Date: Mon, 17 Mar 2025 12:22:27 +0200 Subject: [PATCH 4/4] add sampling optimizations --- .../instrumentation/manual-dotnet-instrumentation.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst index 584c629d2..786918b26 100644 --- a/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst +++ b/gdi/get-data-in/application/otel-dotnet/instrumentation/manual-dotnet-instrumentation.rst @@ -37,8 +37,14 @@ To create custom spans and traces, follow these steps: using (var activity = RegisteredActivity.StartActivity("Custom Span Name")) { - activity?.SetTag("foo", "bar1"); - // your logic for custom activity + // Check if the activity is sampled and if full data collection is enabled. + // This ensures that tags and other custom attributes are only set when the activity is being recorded. + // Note: Ensure that skipping logic based on sampling does not interfere with essential business operations. + if(activity?.IsAllDataRequested) + { + // your logic for custom activity + activity.SetTag("foo", "bar1"); + } } 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.