File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
opentelemetry-sdk/src/trace Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 5
5
- Update ` tonic ` dependency version to 0.13
6
6
- Re-export ` tonic ` types under ` tonic_types `
7
7
[ 2898] ( https://github.com/open-telemetry/opentelemetry-rust/pull/2898 )
8
+ - It is now possible to add links to a ` Span ` via the ` SpanRef ` that you get from
9
+ a ` Context ` . [ 2959] ( https://github.com/open-telemetry/opentelemetry-rust/pull/2959 )
8
10
9
11
## 0.29.0
10
12
Original file line number Diff line number Diff line change @@ -234,6 +234,16 @@ mod tests {
234
234
span. update_name ( "span_name_updated" ) ;
235
235
span. set_attribute ( KeyValue :: new ( "attribute1" , "value1" ) ) ;
236
236
span. add_event ( "test-event" . to_string ( ) , vec ! [ ] ) ;
237
+ span. add_link (
238
+ SpanContext :: new (
239
+ TraceId :: from ( 47 ) ,
240
+ SpanId :: from ( 11 ) ,
241
+ TraceFlags :: default ( ) ,
242
+ false ,
243
+ Default :: default ( ) ,
244
+ ) ,
245
+ vec ! [ ] ,
246
+ ) ;
237
247
} ) ;
238
248
239
249
// Assert
@@ -247,6 +257,9 @@ mod tests {
247
257
assert_eq ! ( span. attributes. len( ) , 1 ) ;
248
258
assert_eq ! ( span. events. len( ) , 1 ) ;
249
259
assert_eq ! ( span. events[ 0 ] . name, "test-event" ) ;
260
+ assert_eq ! ( span. links. len( ) , 1 ) ;
261
+ assert_eq ! ( span. links[ 0 ] . span_context. trace_id( ) , TraceId :: from( 47 ) ) ;
262
+ assert_eq ! ( span. links[ 0 ] . span_context. span_id( ) , SpanId :: from( 11 ) ) ;
250
263
assert_eq ! ( span. span_context. trace_flags( ) , TraceFlags :: SAMPLED ) ;
251
264
assert ! ( !span. span_context. is_remote( ) ) ;
252
265
assert_eq ! ( span. status, Status :: Unset ) ;
Original file line number Diff line number Diff line change @@ -185,6 +185,30 @@ impl SpanRef<'_> {
185
185
self . with_inner_mut ( move |inner| inner. update_name ( new_name) )
186
186
}
187
187
188
+ /// Adds a [`Link`] to another [`SpanContext`].
189
+ ///
190
+ /// This method allows linking the current span to another span, identified by
191
+ /// its `SpanContext`. Links can be used to connect spans from different traces
192
+ /// or within the same trace. Attributes can be attached to the link to provide
193
+ /// additional context or metadata.
194
+ ///
195
+ /// # Arguments
196
+ ///
197
+ /// * `span_context` - The `SpanContext` of the span to link to. This represents
198
+ /// the target span's unique identifiers and trace information.
199
+ /// * `attributes` - A vector of `KeyValue` pairs that describe additional
200
+ /// attributes of the link. These attributes can include any contextual
201
+ /// information relevant to the link between the spans.
202
+ ///
203
+ /// Note - Any [`Link`] added via this mechanism is not accessible to a `Sampler`.
204
+ /// It is recommended to add Links at [`Span`] creation time, rather than adding
205
+ /// them afterwards.
206
+ ///
207
+ /// [`Link`]: crate::trace::Link
208
+ pub fn add_link ( & self , span_context : SpanContext , attributes : Vec < KeyValue > ) {
209
+ self . with_inner_mut ( move |inner| inner. add_link ( span_context, attributes) ) ;
210
+ }
211
+
188
212
/// Signals that the operation described by this span has now ended.
189
213
pub fn end ( & self ) {
190
214
self . end_with_timestamp ( crate :: time:: now ( ) ) ;
You can’t perform that action at this time.
0 commit comments