You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide default activity name value from [CallerMemberName] in ActivitySource.StartActivity #43483
The improvements up to part 2 have made things substantially more usable for the Activity API. This is a small proposed improvement to introduce a sensible default activity name.
We currently require an activity name to be provided as the only required argument in ActivitySource.StartActivity overloads. For scenarios where the caller wants to match the activity with the calling method name, providing that as a default value would make calling code less repetitive.
when the only thing the caller wants to customize is the ActivityKind, a new overload would also be useful
How often do you forsee this occuring? The only situation that came to mind is when creating a client or producer Activity around a new outbound communication protocol. That seemed fairly niche to me.
I don't think the easy-ness of writing an extension method should be of any concern WRT to thinking about potential additions as built-in API/overloads. (otherwise you could only justify the one method with the most parameters in every API, since it's easy to create the extension methods that call into that).
My main scenario is being able to track the flow of calls across components in a loosely coupled system where things go through pub/sub/command bus intermediaries (think CQRS/ES style). This makes it hard to reason about the logic flow in the app.
By simply starting activities at those boundaries (with just using var _ source.StartActivity()) means you can later on plot the flows. I don't think it's a corner case to want the activity name to default to the current method name. Neither that you'd want to just say source.StartActivity(ActivityKind.Client) for your outgoing calls.
I don't think the easy-ness of writing an extension method should be of any concern WRT to thinking about potential additions as built-in API/overloads. (otherwise you could only justify the one method with the most parameters in every API, since it's easy to create the extension methods that call into that).
We add overloads to the core when thought it is going to be used in main scenarios or it is hard to achieve the scenario without this overload. Otherwise we'll end up with tons of rarely used APIs in the core. This is why I suggested the extension method. So, the discussion here is about how popular you scenario is. I am not objecting the request but trying to understand the importance of your scenario. I can see how useful your scenario is but I cannot judge how this is not a corner case especially no-one requested such scenario before. @noahfalk do you have thoughts around this scenario?
@noahfalk do you have thoughts around this scenario?
Using the method name as the activity name seemed like a reasonable default that might get broad usage. Specifying ActivityKind.Client as the sole argument seemed likely to be a corner case, and if so I'd suggest not adding an overload for that part.
namespaceSystem.Diagnostics{publicstaticpartialclassActivitySource{// Existing API, just mark first parameter optional and add [CallerMemberName]publicActivity?StartActivity([CallerMemberName]stringname="",ActivityKindkind=ActivityKind.Internal);publicActivityStartActivity(ActivityKindkind,ActivityContext?parentContext=default,IEnumerable<KeyValuePair<string,object>>?tags=default,IEnumerable<ActivityLink>?links=default,DateTimeOffsetstartTime=default,[CallerMemberName]stringname="");}}
Activity
paulomorgado commentedon Jul 22, 2020
Why not just this one?
Not that I'm a fan on optional arguments...
I would prefer this:
tommcdon commentedon Oct 16, 2020
@noahfalk @tarekgh
noahfalk commentedon Oct 16, 2020
How often do you forsee this occuring? The only situation that came to mind is when creating a client or producer Activity around a new outbound communication protocol. That seemed fairly niche to me.
tarekgh commentedon Oct 16, 2020
I agree with @noahfalk that I am not seeing this is main stream scenario. Also, it is easy to write one line extension method to do so.
kzu commentedon Oct 20, 2020
I don't think the easy-ness of writing an extension method should be of any concern WRT to thinking about potential additions as built-in API/overloads. (otherwise you could only justify the one method with the most parameters in every API, since it's easy to create the extension methods that call into that).
My main scenario is being able to track the flow of calls across components in a loosely coupled system where things go through pub/sub/command bus intermediaries (think CQRS/ES style). This makes it hard to reason about the logic flow in the app.
By simply starting activities at those boundaries (with just
using var _ source.StartActivity()) means you can later on plot the flows. I don't think it's a corner case to want the activity name to default to the current method name. Neither that you'd want to just saysource.StartActivity(ActivityKind.Client)for your outgoing calls.tarekgh commentedon Oct 20, 2020
We add overloads to the core when thought it is going to be used in main scenarios or it is hard to achieve the scenario without this overload. Otherwise we'll end up with tons of rarely used APIs in the core. This is why I suggested the extension method. So, the discussion here is about how popular you scenario is. I am not objecting the request but trying to understand the importance of your scenario. I can see how useful your scenario is but I cannot judge how this is not a corner case especially no-one requested such scenario before. @noahfalk do you have thoughts around this scenario?
noahfalk commentedon Oct 20, 2020
Using the method name as the activity name seemed like a reasonable default that might get broad usage. Specifying ActivityKind.Client as the sole argument seemed likely to be a corner case, and if so I'd suggest not adding an overload for that part.
tarekgh commentedon Oct 20, 2020
Considering we are currently have the overloads:
I am suggesting to change the first one to
and then add the overload:
The reason for that, if anyone want to provide more parameters and still need to get the caller member names, this overload can do it.
what you think about that?
3 remaining items
tarekgh commentedon Oct 21, 2020
@noahfalk I marked this ready for design review.
noahfalk commentedon Oct 22, 2020
That looks fine to me 👍
terrajobst commentedon Oct 27, 2020
Video
kzu commentedon Oct 29, 2020
The video time is more at https://youtu.be/viYdlWGUiro?t=4757 :)