Skip to content

Support OpenTelemetry concepts on Activity #31373

Closed

Description

@tarekgh

This issue tracking the work as the part of the issue https://github.com/dotnet/corefx/issues/42305

Please look at dotnet/designs#98 for the detailed design.

Activity

  1. transferred this issue fromdotnet/corefxon Feb 1, 2020
  2. added this to the Future milestone on Feb 1, 2020
  3. added
    untriaged
    on Feb 23, 2020
  4. assigned and unassigned on Mar 3, 2020
  5. noahfalk commented on Mar 3, 2020

    @noahfalk
    Member

    @tarekgh is the primary dev owner, I am actively assisting. So far design feedback has been occurring in #32660

  6. added
    api-needs-work
    and removed
    enhancement
    untriaged
    on Mar 11, 2020
  7. modified the milestones: Future, 5.0 on Mar 11, 2020
  8. reyang commented on Mar 12, 2020

    @reyang
    Contributor

    Looks great! Thanks @tarekgh and @noahfalk!

    One question related to

    using (Activity foo = new Activity(...))
    {
        throw new FoobarException(...);
    }

    If it is possible to capture the exception and associate it with the Activity?

    In OpenTelemetry Python there is such feature (although I think it is more like a question to the language/runtime rather than API) where we know if there is exception and derive status code.

  9. tarekgh commented on Mar 12, 2020

    @tarekgh
    MemberAuthor

    Thanks @reyang for your review.

    I don't think we can automatically capture the exception inside using block without try-catch. The user can write the code like:

    using (Activity foo = Activity.StartNew(...))
    {
        try
        {
            throw new FoobarException(...);
        }
        catch (Exception e)
        {
            foo?.SetCustomProperty("Exception", e);
        }
    }

    and if there is any listener, will get the notification in stopping the activity and then can check if the exception is set there using GetCustomProperty. I'll think if we'll have a better way to handle it.

  10. reyang commented on Mar 12, 2020

    @reyang
    Contributor

    If developers perform exception handling in a central place (e.g. the evil global exception handler, or catching exception from top level code), is there a way for them to know what's the enclosing activity? (I guess no?)

    try {
        using (var foo = new Activity("foo"))
        {
            using (var baz = new Activity("baz")
            {
                DoSomething();
            }
            DoSomething();
        }
        using (var bar = new Activity("bar"))
        {
            DoSomething();
        }
    } catch (FoobarException ex) {
        log(
            ex,
            MagicalFunctionWhichReturnsTheEnclosingActivity(ex).Name, // this is hard since activity is disposed already
            MagicalFunctionWhichReturnsTheVeryContext(ex).SpanId,
        );
    }
  11. 34 remaining items

  12. SergeyKanzhelev commented on Mar 18, 2020

    @SergeyKanzhelev

    I don't know how to comment on this thread. I'll try. Pretty-please, can we switch to google doc?

    1. UpdateName is absolutely needed. Asp.Net Core listener wouldn't work without it: https://github.com/open-telemetry/opentelemetry-dotnet/blob/633dda37bdb171f337596ba4b53021b5d35f117c/src/OpenTelemetry.Collector.AspNetCore/Implementation/HttpInListener.cs#L148
    2. IsRecording vs. no activity allocation. I commented before that not creating activity breaks propagation of the context. Which will break user scenarios. So we need Activity to be created or at least context propagated. Thus it needs some indication on whether recording enabled or not.
    3. Having specific callback for sampling instead of having the sampling decision made in creation callback is not aligned with OpenTelemetry spec. Some features like attributes returned by Sampler to be associated with the Span will simply not work.
  13. noahfalk commented on Mar 19, 2020

    @noahfalk
    Member

    Pretty-please, can we switch to google doc?

    I agree a single inline thread is hard to follow - I am already trying to move discussion to the PR which does allow for inline annotations and replies to different threads of conversation. I think this is similar to properties we'd get from a google doc. I don't really want to move yet again to google doc because (a) it is different than the convention every other .NET design issue uses, (b) every time we move the discussion forum it breaks the flow and makes it that much harder to understand the history or accumulate issues in one place.

    It is very tempting (I am guilty too) to keep replying back to this issue. To try and break that pattern I copied each of the issues you raised to comments in relevant portions of the PR and responded there instead.

  14. SergeyKanzhelev commented on Mar 19, 2020

    @SergeyKanzhelev

    @noahfalk yes, PR in designs repo is OK.

  15. tarekgh commented on Mar 29, 2020

    @tarekgh
    MemberAuthor

    Just FYI, I have updated the design proposal dotnet/designs#98 to reflect the latest discussions and decisions.

  16. added and removed
    api-needs-work
    on Apr 2, 2020
  17. chandramouleswaran commented on Apr 3, 2020

    @chandramouleswaran
    Contributor

    @chandramouleswaran thanks for the feedback too, I'll try to get back to you soon.

    Any updates here?

  18. tarekgh commented on Apr 3, 2020

    @tarekgh
    MemberAuthor

    @chandramouleswaran, sorry for the late reply I have missed this one unintentionally. thanks for the reminder.

    ActivitySource.StartActivity overload APIs provide multiple options to specify the parent context.

            /// Creates a new Activity object if there is any listener to the Activity, returns null otherwise.
            public Activity? StartActivity(string name, ActivityKind kind = ActivityKind.Internal);
    
            /// Creates a new <see cref="Activity"/> object if there is any listener to the Activity events, returns null otherwise.
            public Activity? StartActivity(
                                string name,
                                ActivityKind kind,
                                ActivityContext parentContext, IEnumerable<KeyValuePair<string, string?>>? tags = null,
                                IEnumerable<ActivityLink>? links = null,
                                DateTimeOffset startTime = default);
    
            /// Creates a new <see cref="Activity"/> object if there is any listener to the Activity events, returns null otherwise.
            public Activity? StartActivity(
                                string name,
                                ActivityKind kind,
                                string parentId,
                                IEnumerable<KeyValuePair<string, string?>>? tags = null,
                                IEnumerable<ActivityLink>? links = null,
                                DateTimeOffset startTime = default);

    Here are the options:

    • If you use the first overload which not providing ActivityContext nor parent Id, we'll create the Activity and have the parent pointing at the existing Activity.Current. This should address the async scenario as Activity.Current is defined as AsyncLocal which transfers with the context of the async call.
    • If you use the second overload, you can provide the parent ActivityContext (which includes the parent trace Id, span Id, flags and state). You have the control to set the parent context to the newly created Activity.
    • If you use the third overload, you can create the Activity object using the parent Id only.

    Please let me know if you have more questions or anything unclear here.

  19. tarekgh commented on Apr 14, 2020

    @tarekgh
    MemberAuthor
  20. added
    api-approved
    and removed on Apr 17, 2020
  21. terrajobst commented on Apr 17, 2020

    @terrajobst
    Contributor

    (marked as approved because that's what we decided in the notes but I didn't update the item during the review)

  22. tarekgh commented on May 18, 2020

    @tarekgh
    MemberAuthor

    Use new Activity to Replace OT Span: open-telemetry/opentelemetry-dotnet#660

  23. ghost locked as resolved and limited conversation to collaborators on Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-System.Diagnostics

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions