Skip to content

Commit

Permalink
Clarify Activity parent in links example (readme) (#946)
Browse files Browse the repository at this point in the history
* Clarify parent id in links scenario

Server activity had parent equal to one of the links - this is confusing, changed to default context (new trace) as likely this activity has no parent.

* Update README.md

* review comments

* fix lint

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
  • Loading branch information
Liudmila Molkova and cijothomas authored Jul 30, 2020
1 parent 21d18e1 commit 70c4107
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/OpenTelemetry.Api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,22 @@ OpenTelemetry samplers chose not to sample this activity.
activityLinks.Add(new ActivityLink(linkedContext2));

var activity = activitySource.StartActivity(
"ActivityName",
"ActivityWithLinks",
ActivityKind.Server,
"00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
default(ActivityContext), // this creates Activity without parent
initialTags,
activityLinks);
```

In case activity has parent, pass parent's context:

```csharp
var parentContext = Activity.Current != null ? Activity.Current.Context : default(ActivityContext);

var activity = activitySource.StartActivity(
"ActivityWithLinks",
ActivityKind.Server,
parentContext,
initialTags,
activityLinks);
```
Expand Down

0 comments on commit 70c4107

Please sign in to comment.