Clarify Activity parent in links example (readme) (#946)

* 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>
This commit is contained in:
Liudmila Molkova 2020-07-30 09:50:47 -07:00 committed by GitHub
parent 21d18e1662
commit 70c410771a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -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);
```