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

Fix couple 2.0-beta issues #317

Merged
merged 7 commits into from
Jan 13, 2017
Merged

Fix couple 2.0-beta issues #317

merged 7 commits into from
Jan 13, 2017

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Jan 11, 2017

Add AspNetCore environment initializer. Fixes: #312
Authenticated user tracking script support. Fixes: #311
Do not output client javascript if telemetry is disabled. Fixes: #313
Prevent debug logging if instrumentation key exists. Fixes: #314
Disable debug logger if other loggers are being added to ILoggerFactory. Fixes: #315

@SergeyKanzhelev @dnduffy

…ebug logging if instrumentation key exists, Disable debug logger if other loggers are being added to ILoggerFactory
@pakrym
Copy link
Contributor Author

pakrym commented Jan 12, 2017

Also fixes null reference exception while determining application version if ran from unit tests: #310

@gardnerjr
Copy link

gardnerjr commented Jan 12, 2017

@pakrym pakrym @DamianEdwards for #314 does this mean that if you have an ikey you don't get any output in the console when debugging? this would mean that all of the VS tooling for local search/etc would stop working once you've set an ikey. or am i interpreting this wrong and that output would still go out? or does this only turn off debug Traces when configured, normal debug output still occurs?

{
this.telemetryConfiguration = telemetryConfiguration;
this.httpContextAccessor = httpContextAccessor;
this.enableAuthSnippet = serviceOptions.Value.EnableAuthenticationTrackingJavaScript;
Copy link
Member

Choose a reason for hiding this comment

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

Can "Value" ever be null?

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, I don't think so.

Copy link
Member

Choose a reason for hiding this comment

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

The IOptions infrastructure will ensure a value is created.

@@ -16,7 +16,8 @@ public ApplicationInsightsServiceOptions()
this.EnableQuickPulseMetricStream = true;
this.EnableAdaptiveSampling = true;
this.EnableDebugLogger = true;
this.ApplicationVersion = Assembly.GetEntryAssembly().GetName().Version.ToString();
this.EnableAuthenticationTrackingJavaScript = false;
this.ApplicationVersion = Assembly.GetEntryAssembly()?.GetName().Version.ToString();
Copy link
Member

Choose a reason for hiding this comment

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

Just curious but when can GetEntryAssembly return null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When running in xunit test.

@@ -55,5 +56,11 @@ public ApplicationInsightsServiceOptions()
/// Gets or sets a value indicating whether a logger would be registered automatically in debug mode.
/// </summary>
public bool EnableDebugLogger { get; set; }

/// <summary>
/// Gets or sets a value indicating whether a JavaScript to track current authenticated user would be printed along with main
Copy link
Member

Choose a reason for hiding this comment

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

nitpick grammar: "Gets or sets a value indicating whether a JavaScript snippet to track the current authenticated user should be printed along with the main ApplicationInsights tracking script."

@pakrym
Copy link
Contributor Author

pakrym commented Jan 12, 2017

@gardnerjr we would only disable automatic debug time logger in that case so you don't accidentally write tons of traces directly to Azure. All other integration features would work as expected.

}

/// <summary>
/// Adds an ApplicationInsights logger that is enabled for <see cref="LogLevel"/>s of minLevel or higher.
/// </summary>
/// <param name="factory"></param>
/// <param name="client">The instance of <see cref="TelemetryClient"/> to use for logging.</param>
/// <param name="serviceProvider">The instance of <see cref="IServiceProvider"/> to use for logging.</param>
Copy link
Member

Choose a reason for hiding this comment

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

The param comment here and below should be updated to reflect the new type being passed since the service provider isn't being used for logging.

var debugLoggerControl = serviceProvider.GetService<DebugLoggerControl>();
if (debugLoggerControl != null)
{
debugLoggerControl.EnableDebugLogger = false;
Copy link
Member

Choose a reason for hiding this comment

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

Just curious so I understand this, when DebugLoggerControl is created the flag is defaulted to true but then here when adding App Insights it is set to false, can you explain the flow for enabling and disabling the debug logger?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idea here is to enable debug time logger only when there is no other logger added explicitly. So when adding debug logger we include debugLoggerControl.EnableDebugLogger into it's filter statement https://github.com/Microsoft/ApplicationInsights-aspnetcore/pull/317/files#diff-ba05ccca641cf8f4dbb9accc9dc93780R37 and when you call loggetFactory.AddApplicationInsights EnableDebugLogger get's set to false and debug logger disabled.

Copy link
Member

Choose a reason for hiding this comment

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

Thank-you.

_environment = environment;
}

public void Initialize(ITelemetry telemetry)
Copy link
Member

Choose a reason for hiding this comment

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

Please add doc comments.

/// </summary>
public AspNetCoreEnvironmentTelemetryInitializer(IHostingEnvironment environment)
{
_environment = environment;
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: prefer StyleCop compliance "this.environment" vs. "_environment".

};
}

private class IdentityStub : IIdentity
Copy link
Member

Choose a reason for hiding this comment

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

Please put doc comments on new code.

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.

Please add some doc comments to all new code so we have less to add later.

@pakrym
Copy link
Contributor Author

pakrym commented Jan 13, 2017

Done

@dnduffy dnduffy merged commit 4792e3c into microsoft:develop Jan 13, 2017
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.

5 participants