Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Add EntityFramework diagnostics source #297

Closed
wants to merge 5 commits into from
Closed

Add EntityFramework diagnostics source #297

wants to merge 5 commits into from

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Dec 12, 2016

Also reference individual packages instead AspNetCore.Hosting as per comment in my previous PR.

@dnduffy

@msftclas
Copy link

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

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

@SergeyKanzhelev
Copy link
Contributor

Last we discussed this should go to Dependency collector nugget. What changed?

@pakrym
Copy link
Contributor Author

pakrym commented Dec 13, 2016

@SergeyKanzhelev we were discussing SqlClient tracing, this diagnostic source can be used with any database client that has entity framework adapter.

using Microsoft.Extensions.DiagnosticAdapter;

/// <summary>
/// <see cref="IApplicationInsightDiagnosticListener"/> implementation that listens for evens specific to EntiryFrameworkCore
Copy link
Member

@dnduffy dnduffy Dec 13, 2016

Choose a reason for hiding this comment

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

evens = events
nitpick: period on sentence.

private readonly TelemetryClient client;
private readonly ContextData<long> beginDependencyTimestamp = new ContextData<long>();

public string ListenerName { get; } = "Microsoft.EntityFrameworkCore";
Copy link
Member

@dnduffy dnduffy Dec 13, 2016

Choose a reason for hiding this comment

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

nitpick: doc comment "/// Gets the listener name."
And doc comments elsewhere.

telemetry.Name = command.Connection.Database;
telemetry.Data = command.CommandText;
telemetry.Duration = new TimeSpan(end - start);
telemetry.Timestamp = DateTimeOffset.Now - telemetry.Duration;
Copy link
Member

Choose a reason for hiding this comment

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

We had a discussion the other day that we should probably go through our code and replace all instances of DateTimeOffset.Now with DateTimeOffset.UtcNow because there happens to be a perf difference between them so maybe this one should be updated now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You want me to update all occurrences?

Copy link
Member

Choose a reason for hiding this comment

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

I was just thinking of this one that is new, or you could leave it and I'll get it with all the others, probably safe to leave it. Sorry, I just commented on it when I saw it but probably I should do it with the others all at once so don't worry about it.

@@ -3,6 +3,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System.Reflection;
Copy link
Member

Choose a reason for hiding this comment

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

Can this using go inside the namespace for consistency? I don't think it is needed for anything outside the namespace.

@@ -1,4 +1,6 @@
namespace Microsoft.Extensions.DependencyInjection
using Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners.Implementation;
Copy link
Member

Choose a reason for hiding this comment

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

Please place inside the namespace sorted with the other usings.

task.Wait(TestTimeoutMs);
}
}
var telemetries = server.BackChannel.Buffer.OfType<DependencyTelemetry>()
Copy link
Member

Choose a reason for hiding this comment

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

What is the type here? I'm guessing it might be "DependencyTelemetry[]" but I'm not sure, please replace var with the known type.

Assert.Equal(new TimeSpan(100000), sentTelemetry.Duration);
}

public class MockDbCommand : System.Data.IDbCommand
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 know it's test code but I would love doc comments anyway please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want doc comment for members too?

Copy link
Member

@dnduffy dnduffy left a comment

Choose a reason for hiding this comment

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

I would like some minor tweaks, mostly doc comments, and then I'll merge it. Thank-you. :)

@AlexBulankou AlexBulankou added this to the 2.0.0-Beta2 milestone Dec 13, 2016
@SergeyKanzhelev
Copy link
Contributor

@pakrym - In Application Insights we split telemetry collection logic by types. Typically dependencies will be collected by DependencyCollector package.

I do not understand why we need to collect EntityFramework collection right in AspNet package?

var start = beginDependencyTimestamp.Value;
var end = timestamp;

var telemetry = new DependencyTelemetry();
Copy link
Contributor

Choose a reason for hiding this comment

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

How does it work with SQL dependencies collected by DependencyCollector module? Will we have double counting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only for SqlClient on full framework.

Copy link
Member

Choose a reason for hiding this comment

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

That would be a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Options? Only enable this feature for .NET Core? Double counting is not good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is useful for non SqlClient connection on full framework too. We can try and filter out SqlCommands by type.

var end = timestamp;

var telemetry = new DependencyTelemetry();
telemetry.Name = command.Connection.Database;
Copy link
Contributor

Choose a reason for hiding this comment

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

Name should be a name of stored procedure or friendly name of SQL command. Not the database name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Framework only sets command text as a name for stored procedures. We have quite strange logic for full framework: https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/DependencyCollector/Shared/Implementation/ProfilerSqlProcessing.cs#L144

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it's, Server | Database | StoredProcedure for stored procedures and Server | Database for everything else. But DataSource unfortunately is SqlClient specific.

telemetry.Data = command.CommandText;
telemetry.Duration = new TimeSpan(end - start);
telemetry.Timestamp = DateTimeOffset.Now - telemetry.Duration;
telemetry.Target = command.Connection.Database;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have Server name? Please include it into target

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because this is provider agnostic there is no common way to get a server name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make our best attempt? Like parse connection string or something. We want to light up scenario in UI when we open database information from the application map's SQL node

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can send entire connection string but it might contain secrets. We can parse connection string syntax but we don't know what to search for.

var start = beginDependencyTimestamp.Value;
var end = timestamp;

var telemetry = new DependencyTelemetry();
Copy link
Contributor

Choose a reason for hiding this comment

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

Options? Only enable this feature for .NET Core? Double counting is not good

var end = timestamp;

var telemetry = new DependencyTelemetry();
telemetry.Name = command.Connection.Database;
Copy link
Contributor

Choose a reason for hiding this comment

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

Framework only sets command text as a name for stored procedures. We have quite strange logic for full framework: https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/DependencyCollector/Shared/Implementation/ProfilerSqlProcessing.cs#L144

telemetry.Data = command.CommandText;
telemetry.Duration = new TimeSpan(end - start);
telemetry.Timestamp = DateTimeOffset.Now - telemetry.Duration;
telemetry.Target = command.Connection.Database;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make our best attempt? Like parse connection string or something. We want to light up scenario in UI when we open database information from the application map's SQL node

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants