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

Overload StartOperation to specify operation Id and parent Id #430

Merged
merged 5 commits into from
Feb 15, 2017

Conversation

pharring
Copy link
Member

Fixes #163

@msftclas
Copy link

Hi @pharring, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Paul Harrington). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

Copy link
Contributor

@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.

Thanks!

@SergeyKanzhelev
Copy link
Contributor

Would you mind to make another overload that takes an entire RequestTelemetry?

@pharring
Copy link
Member Author

@SergeyKanzhelev

Would you mind to make another overload that takes an entire RequestTelemetry?

Certainly. Done.

{
var op = this.telemetryClient.StartOperation<RequestTelemetry>("request");
var id1 = Thread.CurrentThread.ManagedThreadId;
int id2 = 0;
this.telemetryClient.TrackTrace("trace1");

HttpWebRequest request = WebRequest.Create(new Uri("http://bing.com")) as HttpWebRequest;
var result = request.BeginGetResponse(
var result = Task.Delay(millisecondsDelay: 50).AsAsyncResult(
Copy link
Member Author

@pharring pharring Feb 11, 2017

Choose a reason for hiding this comment

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

FYI, this test failed for me because I was working in a place with no WiFi. Hence the change to Task.Delay.

Copy link
Member

Choose a reason for hiding this comment

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

There is an additional Thread.Sleep(100); call in this method that seems questionable.

I also wonder if the test method itself should be attributed for timeout so that the while (!result.IsCompleted) loop doesn't ever accidentally become an infinite loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

}

var operation = new AsyncLocalBasedOperationHolder<T>(telemetryClient, operationTelemetry);
operationTelemetry.Start();
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if these two lines (82,83) should be switched (I kept them like this to preserve existing behavior, but I don't think it matters)

  1. To get the timestamp as close as possible to the top of the method.
  2. To put the setting of operation.ParentContext next to the constructor.
    What do you think, @SergeyKanzhelev ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree - ordering is not logical. If calculating what's inside - Start should be the very last operation. If measuring total - it should be first. Not a big deal, thanks for noticing. You can switch the order

Copy link
Member Author

Choose a reason for hiding this comment

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

Done (commit 13ebde7)

Copy link
Contributor

@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.

approve again

/// <param name="operationId">Operation ID to set in the new operation.</param>
/// <param name="parentOperationId">Optional parent operation ID to set in the new operation.</param>
/// <returns>Operation item object with a new telemetry item having current start time and timestamp.</returns>
public static IOperationHolder<T> StartOperation<T>(this TelemetryClient telemetryClient, string operationName, string operationId, string parentOperationId = null) where T : OperationTelemetry, new()
Copy link
Contributor

Choose a reason for hiding this comment

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

One of the problem with our Sampling + Correlation is that we calculate hash on Context.User.Id (if set), than Context.Operaiton.Id (if set), than toss a coin. The idea was to either include or exclude telemetry for the user.

Passing parent and root solves the problem in case Context.User.Id is not set. However if it was set for the request - "childrens" wouldn't get it.

So we may need to have override with the userId as well. Let me chat with PMs. This sampling by userId not quite working with the correlation story we are implementing today...

Copy link
Member Author

Choose a reason for hiding this comment

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

Presumably, if an app wants to flow Context.User.Id from parent to child, then it would need to install an initializer like UserTelemetryInitializer from the ASP.NET repo. That seems reasonable to me.

@SergeyKanzhelev
Copy link
Contributor

I'll merge later today. Giving chance @dnduffy and @cijothomas to review.

}

/// <summary>
/// Ensure that context being propagated via async/await.
/// </summary>
[TestMethod]
public void ContextPropogatesThruAsyncAwait()
public void ContextPropagatesThruAsyncAwait()
Copy link
Member

@dnduffy dnduffy Feb 14, 2017

Choose a reason for hiding this comment

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

nitpick: There is an additional (pre-existing) spelling mistake, "Thru" should be "Through".

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

{
using (var operation1 = this.telemetryClient.StartOperation<RequestTelemetry>("OuterRequest"))
{
using (var operation2 = this.telemetryClient.StartOperation<DependencyTelemetry>("DependentCall"))
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I have a strong personal dislike of using var instead of known types but in these usings in particular it really isn't clear what the type returned by StartOperation is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed (although I did not replace var in tests that were already in place before this change)

@SergeyKanzhelev SergeyKanzhelev merged commit 35465cd into microsoft:develop Feb 15, 2017
@pharring pharring deleted the StartOperationOverload branch March 24, 2023 19:09
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

4 participants