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

Support .NET Activities #140

Merged
merged 19 commits into from
Jul 13, 2019
Merged

Support .NET Activities #140

merged 19 commits into from
Jul 13, 2019

Conversation

lmolkova
Copy link

@lmolkova lmolkova commented Jul 9, 2019

Fixes #60, see explanation in #128

This change

  • adds SpanBuilder methods to set parent activity, or create span FOR current Activity (not a child, it's for auto-collectors that create Activity)

  • adds SpanBuilder/Link methods to create Link from Activity

  • By default, creates Span out of Activity.Current (and span attached to it)

  • Changes scopes to work with Activity - i.e. Activity is the propagation mechanism and Span is weakly coupled with it

  • All scoping happens in WithSpan call - this is where Activity.Current is changes and span is assigned to it.

  • Does a bunch of optimization in tracestate: Activity does not support tracestate object (it only allows strings) and more conversions of traceparent to string and back are expected in some cases. Optimizations are built around new .NET Span API (like an array pointer, not OT span)

Scenarios

Auto-collectors

  • ASP.NET Core starts activity,
  • auto-collector starts scoped span out of this activity
  • user makes http call- it gets parent ASP.NET Core activity
  • auto-collector creates span for the outgoing call
  • user in the app start a new span - it becomes a child of this Activity/Span attached to it
  • if user does not call WithSpan, Activity.Current is untouched and Current Span is parent one

Manual spans

  • users can create spans as usual
  • they can use scopes or propagate spans explicitly in the code.

What is NOT covered and comes next

  • auto-collectors changes based on this. BTW I believe auto-collectors should all eventually create SpanData - no need to create spans
  • make Spans leverage Activity start time/stop time. TimeStampConverter should go away
  • some improvement (enforcing W3C easier) that are coming with next DiagnosticSource/Activity release.

depends on #136 - this block merge

there are some new TODO dependent on next DignosticSource preview 7 (coming in the next days) - but it shouldn't block merge

/// Any parent that was set previously will be discarded.
/// </summary>
/// <returns>This span builder for chaining.</returns>
ISpanBuilder FromCurrentActivity();
Copy link
Member

Choose a reason for hiding this comment

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

this method ties SpanBuilder to the context. Which is very misaligned with API. Would it be better to have FromActivity method and user of API will pass Activity.Current explicitly?

Copy link
Author

Choose a reason for hiding this comment

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

To be fair, SpanBuilder is tied to context already by using the current span unless any other parent was provided. Why do you think it is misaligned with the API?

I do not see a good scenario for FromActivity(activity) except when it is current. Moreover, I want to strictly prohibit this usage because it internally complicates things even more.

Copy link
Member

Choose a reason for hiding this comment

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

you are right. It is tight to the current span in StartSpan method. What I don't like in this API is that it is not like any other builder methods which simply add properties. Maybe it will be more logical to create the entire SpanBuilder from the current Activity from a Tracer rather than have this method on SpanBuilder.

Copy link
Author

Choose a reason for hiding this comment

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

Wait, we have spanbuilder to build spans, tracer does not do it and let's not abuse it.

This API simply adds property at the end of the day. It looks different than other APIs, this is right.

How about we change it to something like SetAutocollected (true) - I'll try to come up with more descriptive name, but basically this is a bool flag, that in absence of parent, creates span from current activity.

Copy link
Author

@lmolkova lmolkova Jul 12, 2019

Choose a reason for hiding this comment

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

Spent great deal of time thinking about naming and I still believe FromCurrentActivity is the most accurate one.
Still, this is naming - internally this API is no different than others - tells what context to use to create Span. I can come up with different names AssociateWithCurrentActivity / AssignToCurrentActivity()

If you have strong objections here is the alternative

  • SetCreateChild(true/false). It will not be compatible with any SetParent methods (as parent assumes there will be a child) and will only apply to the case when there is implicit context.
    • true: will create span which is child of current activity. this is default and equivalent to not calling method at all
    • false: will continue current Activity without creating child

So I'll implement SetCreateChild. Let me know what you think @SergeyKanzhelev.

@lmolkova lmolkova changed the base branch from SwitchToActivityTraceIdSpanId to master July 11, 2019 19:12
/// <param name="createChild">If true, a new span will become a child of the existing implicit context.
/// If false, new span will continue this context.</param>
/// <returns>This span builder for chaining.</returns>
ISpanBuilder SetCreateChild(bool createChild);
Copy link
Member

Choose a reason for hiding this comment

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

this name is quite confusing. Why not move this part of deciding on whether to create one out of Activity.Current or a new one into the Tracer? This decision is only actual when you creating a SpanBuilder initially, right?

Copy link
Member

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

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

Let's discuss the method name/placement in a separate issue.

@lmolkova
Copy link
Author

Let's discuss the method name/placement in a separate issue.

Created #145 to track it.

@lmolkova lmolkova merged commit c5f33e1 into open-telemetry:master Jul 13, 2019
@lmolkova lmolkova deleted the Activities branch December 19, 2019 05:35
Yun-Ting pushed a commit to Yun-Ting/opentelemetry-dotnet that referenced this pull request Oct 13, 2022
* Update changelog for ESClient and MT release

* fix date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: Use Activity as a context propagation mechanism
2 participants