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

Add ActivityContextFormat and propagation #724

Merged
merged 45 commits into from
Jun 16, 2020
Merged

Add ActivityContextFormat and propagation #724

merged 45 commits into from
Jun 16, 2020

Conversation

cijothomas
Copy link
Member

Following up on #701, this PR adds ITextFormatActivity and TraceContextFormatActivity which can extract/inject ActivityContext (similar to SpanContext).

TODO: as another follow up:
When instrumentation adapter creates new activity(), this results in a duplicate telemetry collection. This will be fixed as a follow up, along with fixing the custom Filter. (the new instrumentationadapters dont support Filters)

Changes

Introduce ITextFormatActivity and TraceContextFormatActivity
Modify instrumentation adapter to extract context using above - the activity which did not use the above(i.e Asp.Net, Asp.Net Core), will be ignored and a new one is started.

Checklist

  • I ran Unit Tests locally.

For significant contributions please make sure you have completed the following items:

  • Design discussion issue #
  • Changes in public API reviewed

The PR will automatically request reviews from code owners and trigger CI build and tests.

Make Asp.Net instrumentation work with Activity API
…it tests and this is not planned to be in this repo as well.
using OpenTelemetry.Context.Propagation;
using Xunit;

namespace OpenTelemetry.Impl.Trace.Propagation
Copy link
Member

Choose a reason for hiding this comment

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

nit: Rename "Impl" -> "Implementation" in namespace. I think "Impl" was used a lot before but we're been slowly cleaning it up?

activity.Kind,
activity.Tags,
activity.Links);
activity.Context,
Copy link
Member

Choose a reason for hiding this comment

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

nit: Extra tab thing going on here? Also at the end of the method (line 121) spacing looks off. Sorry for even mentioning it just happened to catch my eye.

@@ -59,12 +59,14 @@ public void Dispose()
// [InlineData("http://localhost/api/value", 0, null, "/api/value")] // Request will be filtered
// [InlineData("http://localhost/api/value", 0, null, "{ThrowException}")] // Filter user code will throw an exception
[InlineData("http://localhost/api/value/2", 0, null, "CustomContext", "/api/value")] // Request will not be filtered
[InlineData("http://localhost/api/value/2", 0, null, "CustomContext", "/api/value", true)] // Request will not be filtered
Copy link
Member

Choose a reason for hiding this comment

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

This tests for both cases now? Awesome!

// then we need to retrieve the one created by HttpInListener
// and stop it.
var activityByHttpInListener = (Activity)activity.GetCustomProperty("ActivityByHttpInListener");
activityByHttpInListener.Stop();
Copy link
Member

Choose a reason for hiding this comment

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

One last thing :) When we stop "newOne" here do we need to restore Activity.Current back to libraryActivity (since the Stop will call Activity.SetCurrent(Parent))? Something like:

                else if (activity.OperationName.Equals("Microsoft.AspNet.HttpReqIn.Start"))
                {
                    // This block is hit if Asp.Net did restore Current to its own activity,
                    // then we need to retrieve the one created by HttpInListener
                    // and stop it.
                    var activityByHttpInListener = (Activity)activity.GetCustomProperty("ActivityByHttpInListener");
                    activityByHttpInListener.Stop();
                    Activity.Current = activity; // Put back libraryActivity
                }

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. Added tests too for this.

@cijothomas
Copy link
Member Author

Merging this now to make another PR on top of this.
If there are more review comments, please let me know.

@cijothomas cijothomas merged commit 575ddd5 into open-telemetry:master Jun 16, 2020
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.

None yet

2 participants