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

Commit 0cf2da8

Browse files
committed
Update context trace span
1 parent 65cd18a commit 0cf2da8

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

apm/span-tags/add-context-trace-span.rst

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,15 @@ The following examples show how to create a custom tag for an existing span:
9999

100100
.. code-tab:: csharp .NET
101101

102-
// SignalFx Instrumentation for .NET
102+
// Splunk Distribution of OpenTelemetry .NET
103103

104-
using OpenTracing;
105-
using OpenTracing.Util;
104+
using var myActivity = MyActivitySource.StartActivity("SayHello");
106105

107-
// A scope for the span must already exist
106+
activity?.SetTag("operation.value", 1);
107+
activity?.SetTag("operation.name", "Saying hello!");
108+
activity?.SetTag("operation.other-stuff", new int[] { 1, 2, 3 });
108109

109-
var span = scope.Span;
110-
span.SetTag("some.tag", "some value");
111-
112-
// You can also set global tags using the SIGNALFX_GLOBAL_TAGS
110+
// You can also set global tags using the OTEL_RESOURCE_ATTRIBUTES
113111
// environment variable, which accepts a list of comma-separated key-value
114112
// pairs. For example, key1:val1,key2:val2.
115113

@@ -135,28 +133,19 @@ The following examples show how to create a custom tag for an existing span:
135133
// Other activities
136134
}
137135

138-
// You can also set global tags using the OTEL_RESOURCE_ATTRIBUTES
136+
// You can also set global tags using the OTEL_RESOURCE_ATTRIBUTES
139137
// environment variable, which accepts a list of comma-separated key-value
140-
// pairs. For example, key1:val1,key2:val2.
138+
// pairs. For example, key1:val1,key2:val2.
141139

142140
.. code-tab:: ruby Ruby
143141

144-
# SignalFx Ruby Tracing Library
142+
# OpenTelemetry Ruby
145143

146-
require "splunk/otel"
144+
require "opentelemetry/sdk"
147145

148-
module BasicExample
149-
def some_spans
150-
Splunk::Otel.configure
151-
tracer = OpenTelemetry.tracer_provider.tracer("mytracer")
152-
# Create a span with custom attributes or tags
153-
tracer.in_span("basic-example-span-1", attributes: { "hello" => "world", "some.number" => 1024 }) do |_span|
154-
tracer.in_span("basic-example-span-2") do |span|
155-
# Add span attributes after creation
156-
span.set_attribute("animals", ["splunk", "observability"])
157-
end
158-
end
159-
end
146+
current_span = OpenTelemetry::Trace.current_span
147+
148+
current_span.set_attribute("animals", ["elephant", "tiger"])
160149

161150
# You can also set global tags using the OTEL_RESOURCE_ATTRIBUTES
162151
# environment variable, which accepts a list of comma-separated key-value
@@ -166,17 +155,27 @@ The following examples show how to create a custom tag for an existing span:
166155

167156
<?php
168157

169-
// SignalFx PHP Tracing Library
158+
// OpenTelemetry PHP
170159

171160
use SignalFx\GlobalTracer;
172161

173-
$tracer = GlobalTracer::get(); // Will provide the tracer instance used by provided instrumentations
174-
$customizedSpan = $tracer->startActiveSpan('myApplicationLogic')->getSpan();
175-
$customizedSpan->setTag('some.tag', 'some value');
162+
private function rollOnce() {
163+
$parent = OpenTelemetry\API\Trace\Span::getCurrent();
164+
$scope = $parent->activate();
165+
try {
166+
$span = $this->tracer->spanBuilder("rollTheDice")->startSpan();
167+
$result = random_int(1, 6);
168+
$span->setAttribute('dicelib.rolled', $result);
169+
$span->end();
170+
} finally {
171+
$scope->detach();
172+
}
173+
return $result;
174+
}
176175

177176
// You can also set global tags using the SIGNALFX_TRACE_GLOBAL_TAGS
178177
// environment variable, which accepts a list of comma-separated key-value
179-
// pairs. For example: key1:val1,key2:val2.
178+
// pairs. For example: key1:val1,key2:val2.
180179
?>
181180

182181
.. _otel-span-tags:

0 commit comments

Comments
 (0)