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

[WIP] In-process propagation with a simple ITracer.ActiveSpan property #36

Closed
wants to merge 1 commit into from

Conversation

cwe1ss
Copy link
Member

@cwe1ss cwe1ss commented Apr 27, 2017

Related to #35. This PR shows a very simple contract for in-process propagation in C#.

It has the following properties:

  • ITracer.ActiveSpan holds the currently active span.
  • Every new span will automatically get the active span as a parent.
  • Opting out of this inheritance behavior is possible through ISpanBuilder.IgnoreActiveSpan().
  • There is no separate IActiveSpan because C# doesn't need the "Continuation" feature from the Java PR.
  • This is a breaking change because the current usage would automatically activate spans. I don't think this is a problem though because I'm not even sure if anyone is using this library already 😄

Since this library currently only holds contracts, these rules must be met by tracer implementations. We should discuss separately if there are any building blocks that should go into this library or a contrib project.

Things that are not possible with this right now:

Questions:

  • Does a user need an API to access a span's parent? (e.g. ISpan.Parent or ISpanContext.Parent)

Usage:

// Accessing the currently active span.
ISpan activeSpan = tracer.ActiveSpan;

// Starting a new span will automatically inherit an existing active span
// with a "child_of" reference and will "activate" itself.
ISpan span = tracer.BuildSpan("someWork").Start();
try
{
    HttpResponseMessage response = await httpClient.SendAsync(request);

    // C# automatically restores local variables in an async execution,
    // so this line doesn't even need to access `tracer.ActiveSpan`.
    span.SetTag(Tags.HttpStatusCode, response.StatusCode);
}
finally
{
    // Finish will revert "tracer.ActiveSpan" to its parent.
    span.Finish();
}

// The same can be achieved by using the IDisposable feature of ISpan and a "using" statement:
using (ISpan activeSpan = tracer.BuildSpan("someWork").Start())
{
    // (record data to `span`, call async methods, ...)
}

// If an `ActiveSpan` should NOT act as a parent for a newly started span
// a user can invoke `ISpanBuilder.IgnoreActiveSpan()` at `BuildSpan()` time, like so:
ISpan activeSpan = tracer.BuildSpan("someWork")
    .IgnoreActiveSpan()
    .Start();

@cwe1ss cwe1ss added this to the 0.10.0 milestone Apr 27, 2017
@cwe1ss cwe1ss self-assigned this Apr 27, 2017
@cwe1ss cwe1ss requested review from bhs and yurishkuro April 27, 2017 16:49
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

@cwe1ss I am not familiar with .Net's new async stuff or how the context is propagated across threads, so I cannot offer any opinion on this. Would you be able to poll other .Net developers, maybe whoever participated in earlier PRs/

@tedsuo
Copy link
Member

tedsuo commented Apr 28, 2017

@carlosalberto any thoughts?

@carlosalberto
Copy link
Contributor

Definitely sounds all fine to me, specially the part about not needing a few things since async/await help us here (together with AsyncLocal).

For the HttpClient and similar components, it looks like there's not much of an option, other than be explicit about it with the users.

@bhs bhs mentioned this pull request May 28, 2017
@bhs
Copy link

bhs commented May 28, 2017

cc += @TerribleDev

@TerribleDev
Copy link

TerribleDev commented May 30, 2017

What is the plan for getting the span into the HttpClient request? Have you thought at all about making extension methods of HttpClient that will add the ISpan to the request? httpClient.SentAsync(request, span).

Personally, I'd think some extension methods would be pretty nice, because then they would be easy to add to someones code, without having to make sweeping changes across their apps.

@bmermet
Copy link

bmermet commented Nov 23, 2017

@cwe1ss Any progress on this? The Java propagation API seems stabilized and will soon be released, I can help porting it to c# if it's the right thing to do.

@cwe1ss
Copy link
Member Author

cwe1ss commented Nov 23, 2017

See #52 as well.

(.NET‘s Activity has built in support for propagation via Activity.Current)

@carlosalberto
Copy link
Contributor

An interesting take would be to prototype out an API/wrapper for Activity to work under the OpenTracing API. Wondering if that would be useful (for a start), though. Ideas?

@cwe1ss
Copy link
Member Author

cwe1ss commented Feb 1, 2018

Out of date. I'll create a new PR with the new scope stuff from Java.

EDIT: I'll just look at #50 since it already has that code.

@cwe1ss cwe1ss closed this Feb 1, 2018
@cwe1ss cwe1ss deleted the inproc-prop branch February 1, 2018 15:59
@cwe1ss cwe1ss removed this from the 1.0.0 milestone Feb 1, 2018
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.

7 participants