Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Activity API usability and OpenTelemetry integration (Part 2) #39087

Merged
merged 6 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public string? Id
get { throw null; }
}

public bool IsAllDataRequested { get { throw null; } set { throw null; }}
public bool IsAllDataRequested { get { throw null; } set { throw null; } }
public System.Diagnostics.ActivityIdFormat IdFormat { get { throw null; } }
public System.Diagnostics.ActivityKind Kind { get { throw null; } }
public string OperationName { get { throw null; } }
Expand All @@ -47,13 +47,16 @@ public string? Id
public System.Diagnostics.ActivitySpanId SpanId { get { throw null; } }
public System.DateTime StartTimeUtc { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string?>> Tags { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> TagObjects { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityEvent> Events { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink> Links { get { throw null; } }
public System.Diagnostics.ActivityTraceId TraceId { get { throw null; } }
public string? TraceStateString { get { throw null; } set { } }
public System.Diagnostics.Activity AddBaggage(string key, string? value) { throw null; }
public System.Diagnostics.Activity AddEvent(System.Diagnostics.ActivityEvent e) { throw null; }
public System.Diagnostics.Activity AddTag(string key, string? value) { throw null; }
public System.Diagnostics.Activity AddTag(string key, object value) { throw null; }
public System.Diagnostics.Activity SetTag(string key, object value) { throw null; }
public string? GetBaggageItem(string key) { throw null; }
public System.Diagnostics.Activity SetEndTime(System.DateTime endTimeUtc) { throw null; }
public System.Diagnostics.Activity SetIdFormat(System.Diagnostics.ActivityIdFormat format) { throw null; }
Expand All @@ -68,6 +71,27 @@ public string? Id
public object? GetCustomProperty(string propertyName) { throw null; }
public ActivityContext Context { get { throw null; } }
}
public class ActivityTagsCollection : System.Collections.Generic.IDictionary<string, object>
{
public ActivityTagsCollection() { throw null; }
public ActivityTagsCollection(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> list) { throw null; }
public object? this[string key] { get { throw null; } set { } }
public System.Collections.Generic.ICollection<string> Keys { get { throw null; } }
public System.Collections.Generic.ICollection<object> Values { get { throw null; } }
public int Count { get { throw null; } }
public bool IsReadOnly { get { throw null; } }
public void Add(string key, object value) { throw null; }
public void Add(System.Collections.Generic.KeyValuePair<string, object> item) { throw null; }
public void Clear() { throw null; }
public bool Contains(System.Collections.Generic.KeyValuePair<string, object> item) { throw null; }
public bool ContainsKey(string key) { throw null; }
public void CopyTo(System.Collections.Generic.KeyValuePair<string, object>[] array, int arrayIndex) { throw null; }
public System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object>> GetEnumerator() { throw null; }
public bool Remove(string key) { throw null; }
public bool Remove(System.Collections.Generic.KeyValuePair<string, object> item) { throw null; }
public bool TryGetValue(string key, out object value) { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
}
public enum ActivityIdFormat
{
Unknown = 0,
Expand Down Expand Up @@ -101,8 +125,8 @@ public sealed class ActivitySource : IDisposable
public string? Version { get { throw null; } }
public bool HasListeners() { throw null; }
public System.Diagnostics.Activity? StartActivity(string name, System.Diagnostics.ActivityKind kind = ActivityKind.Internal) { throw null; }
public System.Diagnostics.Activity? StartActivity(string name, System.Diagnostics.ActivityKind kind, System.Diagnostics.ActivityContext parentContext, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string?>>? tags = null, System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink>? links = null, System.DateTimeOffset startTime = default) { throw null; }
public System.Diagnostics.Activity? StartActivity(string name, System.Diagnostics.ActivityKind kind, string parentId, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string?>>? tags = null, System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink>? links = null, System.DateTimeOffset startTime = default) { throw null; }
public System.Diagnostics.Activity? StartActivity(string name, System.Diagnostics.ActivityKind kind, System.Diagnostics.ActivityContext parentContext, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>>? tags = null, System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink>? links = null, System.DateTimeOffset startTime = default) { throw null; }
public System.Diagnostics.Activity? StartActivity(string name, System.Diagnostics.ActivityKind kind, string parentId, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>>? tags = null, System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink>? links = null, System.DateTimeOffset startTime = default) { throw null; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarekgh Hey I just noticed working on some code in OTel that you can't specify events in the StartActivity call. You can specify pretty much everything else. Should we add events too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there is no AddLink method. Links you have to specify at creation?

Copy link
Member Author

@tarekgh tarekgh Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed working on some code in OTel that you can't specify events in the StartActivity call. You can specify pretty much everything else. Should we add events too?

StartActivity arguments mainly the things needed for sampling decision to decide if want to create the activity or just avoid that and sample it out. If you look at the OT sampling specs, you'll find events are not needed there https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling. But anyway, you can add events after creating the activity.

Also there is no AddLink method. Links you have to specify at creation?

This was proposed before and then got removed because there was a claim that shouldn't allow adding links after creating and starting the activity. OT specs saying During the Span creation user MUST have the ability to record links to other Spans. Linked Spans can be from the same or a different trace.. so, the spec is explicit mentioning the links should be provided during the Span creation. But anyway, later if we find any scenario need to add links after starting the activity, we can consider it.

CC @cijothomas @reyang

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Tarek said is my understanding as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That all makes sense. What I'm doing right now is working on a unit test. It needs the Activity created very specifically. So it's not a normal use case. I think I can make it work with reflection. The links are a bit of a challenge. I'll mention you guys on the change once I have it working so you can see what I'm up against, and then we can decide if any changes are warranted.

public static void AddActivityListener(System.Diagnostics.ActivityListener listener) { throw null; }
public void Dispose() { throw null; }
}
Expand Down Expand Up @@ -163,20 +187,19 @@ public enum ActivityKind
public readonly struct ActivityEvent
{
public ActivityEvent(string name) {throw null; }
public ActivityEvent(string name, System.DateTimeOffset timestamp) { throw null; }
public ActivityEvent(string name, System.DateTimeOffset timestamp, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { throw null; }
public ActivityEvent(string name, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { throw null; }
public ActivityEvent(string name, System.DateTimeOffset timestamp = default, System.Diagnostics.ActivityTagsCollection? tags = null) { throw null; }
public string Name { get { throw null; } }
public System.DateTimeOffset Timestamp { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> Attributes { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> Tags { get { throw null; } }
}
public readonly struct ActivityContext : System.IEquatable<System.Diagnostics.ActivityContext>
{
public ActivityContext(System.Diagnostics.ActivityTraceId traceId, System.Diagnostics.ActivitySpanId spanId, System.Diagnostics.ActivityTraceFlags traceOptions, string? traceState = null) { throw null; }
public ActivityContext(System.Diagnostics.ActivityTraceId traceId, System.Diagnostics.ActivitySpanId spanId, System.Diagnostics.ActivityTraceFlags traceOptions, string? traceState = null, bool isRemote = false) { throw null; }
public System.Diagnostics.ActivityTraceId TraceId { get { throw null; } }
public System.Diagnostics.ActivitySpanId SpanId { get { throw null; } }
public System.Diagnostics.ActivityTraceFlags TraceFlags { get { throw null; } }
public string? TraceState { get { throw null; } }
public bool IsRemote { get { throw null; } }
public static bool operator ==(System.Diagnostics.ActivityContext left, System.Diagnostics.ActivityContext right) { throw null; }
public static bool operator !=(System.Diagnostics.ActivityContext left, System.Diagnostics.ActivityContext right) { throw null; }
public bool Equals(System.Diagnostics.ActivityContext value) { throw null; }
Expand All @@ -185,11 +208,9 @@ public readonly struct ActivityEvent
}
public readonly struct ActivityLink : IEquatable<ActivityLink>
{
public ActivityLink(System.Diagnostics.ActivityContext context) { throw null; }
public ActivityLink(System.Diagnostics.ActivityContext context, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { throw null; }
public ActivityLink(System.Diagnostics.ActivityContext context, System.Diagnostics.ActivityTagsCollection? tags = null) { throw null; }
public System.Diagnostics.ActivityContext Context { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? Attributes { get { throw null; } }

public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? Tags { get { throw null; } }
public override bool Equals(object? obj) { throw null; }
public bool Equals(System.Diagnostics.ActivityLink value) { throw null; }
public static bool operator ==(System.Diagnostics.ActivityLink left, System.Diagnostics.ActivityLink right) { throw null; }
Expand All @@ -202,18 +223,19 @@ public readonly struct ActivityCreationOptions<T>
public string Name { get { throw null; } }
public System.Diagnostics.ActivityKind Kind { get { throw null; } }
public T Parent { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string?>> Tags { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>> Tags { get { throw null; } }
public System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink> Links { get { throw null; } }
}
public delegate System.Diagnostics.ActivityDataRequest GetRequestedData<T>(ref System.Diagnostics.ActivityCreationOptions<T> options);
public sealed class ActivityListener : IDisposable
{
public ActivityListener() { throw null; }
public System.Action<System.Diagnostics.Activity>? ActivityStarted { get { throw null; } set { } }
public System.Action<System.Diagnostics.Activity>? ActivityStopped { get { throw null; } set { } }
public System.Func<System.Diagnostics.ActivitySource, bool>? ShouldListenTo { get { throw null; } set { } }
public System.Diagnostics.GetRequestedData<string>? GetRequestedDataUsingParentId { get { throw null; } set { } }
public System.Diagnostics.GetRequestedData<ActivityContext>? GetRequestedDataUsingContext { get { throw null; } set { } }
public System.Action<System.Diagnostics.Activity>? ActivityStarted { get { throw null; } set { throw null; } }
public System.Action<System.Diagnostics.Activity>? ActivityStopped { get { throw null; } set { throw null; } }
public System.Func<System.Diagnostics.ActivitySource, bool>? ShouldListenTo { get { throw null; } set { throw null; } }
public System.Diagnostics.GetRequestedData<string>? GetRequestedDataUsingParentId { get { throw null; } set { throw null; } }
public System.Diagnostics.GetRequestedData<ActivityContext>? GetRequestedDataUsingContext { get { throw null; } set { throw null; } }
public bool AutoGenerateRootContextTraceId { get { throw null; } set { throw null; } }
public void Dispose() { throw null; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,7 @@
<data name="StartTimeNotUtc" xml:space="preserve">
<value>"StartTime is not UTC"</value>
</data>
<data name="KeyAlreadyExist" xml:space="preserve">
<value>"The collection already contains item with same key '{0}''"</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Compile Include="$(CommonPath)System\HexConverter.cs"
Link="Common\System\HexConverter.cs" />
<Compile Include="System\Diagnostics\Activity.cs" />
<Compile Include="System\Diagnostics\ActivityTagsCollection.cs" />
<Compile Include="System\Diagnostics\ActivityContext.cs" />
<Compile Include="System\Diagnostics\ActivityCreationOptions.cs" />
<Compile Include="System\Diagnostics\ActivityDataRequest.cs" />
Expand Down
Loading