@@ -332,11 +332,13 @@ chose not to sample this activity.
332332
3333334. Activity Links
334334
335- Apart from the parent-child relation, activities can be linked using
336- ` ActivityLinks` which represent the OpenTelemetry
337- [Links](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/overview.md#links-between-spans).
338- The linked activities must be provided during the creation time, as shown
339- below.
335+ In addition to parent-child relationships, activities can also be linked
336+ using ` ActivityLinks` , which represent
337+ [Links](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/overview.md#links-between-spans)
338+ in OpenTelemetry. Providing activity links during creation is recommended, as
339+ this allows samplers to consider them when deciding whether to sample an
340+ activity. However, starting with ` System.Diagnostics.DiagnosticSource` 9.0.0,
341+ links can also be added after an activity is created.
340342
341343 ` ` ` csharp
342344 var activityLinks = new List<ActivityLink> ();
@@ -359,12 +361,19 @@ chose not to sample this activity.
359361 ActivityKind.Server,
360362 default(ActivityContext),
361363 initialTags,
362- activityLinks);
364+ activityLinks); // links provided at creation time.
365+
366+ // One may add links after activity is created too.
367+ var linkedContext3 = new ActivityContext(
368+ ActivityTraceId.CreateFromString(" 01260a70a81e1fa3ad5a8acfeaa0f711" ),
369+ ActivitySpanId.CreateFromString(" 34739aa9e2239da1" ),
370+ ActivityTraceFlags.None);
371+ activity? .AddLink(linkedContext3);
363372 ` ` `
364373
365- Note that ` Activity` above is created with ` default(ActivityContext)`
366- parent, which makes it child of implicit ` Activity.Current` or orphan if
367- there is no ` Current` .
374+ Note that ` Activity` above is created with ` default(ActivityContext)`
375+ parent, which makes it child of implicit ` Activity.Current` or orphan if
376+ there is no ` Current` .
368377
369378# ## Adding Events
370379
0 commit comments