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

Commit for #29 - Read version information from project.json #144

Merged
merged 9 commits into from
Mar 25, 2016

Conversation

gzepeda
Copy link
Contributor

@gzepeda gzepeda commented Mar 21, 2016

Here are the changes for issue #29

There is a small change to the project.json file, I needed a dependency for Microsoft.Extensions.Configuration.Json and also change the version of Microsoft.ApplicationInsights so the project would compile.

@msftclas
Copy link

Hi @gzepeda, 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;

@msftclas
Copy link

@gzepeda, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, MSBOT;

@kartang
Copy link
Contributor

kartang commented Mar 21, 2016

Looks good to me!

{
private const string versionConfigurationOption = "dependencies:Microsoft.ApplicationInsights.AspNet";

public ComponentVersionTelemetryInitializer(IHttpContextAccessor httpContextAccessor):base(httpContextAccessor)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you get IConfiguration object using dependency injection here and than try to do:

config[versionConfigurationOption].ToString();

instead of guessing which file contains configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I will try that approach.

@gzepeda
Copy link
Contributor Author

gzepeda commented Mar 21, 2016

I have made the change, but before creating a new Pull request. I wanted to ask if the approach was correct.

I added this to the AddApplicationInsightsTelemetry method:

var projectJsonConfiguration = new ConfigurationBuilder().AddJsonFile("project.json").Build();
services.AddInstance<IConfiguration>(projectJsonConfiguration);

And Injecting the IConfiguration dependency on the constructor for the created class.

It does not conflict with the TelemetryConfiguration but I don't feel it is the right place to have that service declared.

… version as requested in the previous pull request.
@@ -48,6 +49,9 @@ public static void AddApplicationInsightsTelemetry(this IServiceCollection servi
services.AddSingleton<ITelemetryInitializer, WebSessionTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, WebUserTelemetryInitializer>();

var projectJsonConfiguration = new ConfigurationBuilder().AddJsonFile("project.json").Build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Configuration is already passed as an argument. You can pass it into initializer constructor

@gzepeda
Copy link
Contributor Author

gzepeda commented Mar 21, 2016

Done.

One more thing: I am not sure how to reuse the service on the unit tests without declaring a new instance and sending it to the initializer.

@@ -48,6 +49,8 @@ public static void AddApplicationInsightsTelemetry(this IServiceCollection servi
services.AddSingleton<ITelemetryInitializer, WebSessionTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, WebUserTelemetryInitializer>();

services.AddInstance<IConfiguration>(config);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just pass this configuration to ComponentVersionTelemetryInitializer constructor on the line 44

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I do something like this:

            services.AddSingleton<ITelemetryInitializer>(ComponentVersionTelemetryInitializer =>
            {
                return new ComponentVersionTelemetryInitializer(null, config);
            });

The problem I see is not having the httpContextAccessor

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, 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.

A bunch of Unit Tests produce exceptions if I send the first parameter (httpContextAccessor as null). Even if I don't need it on the initializer, as long as the class implements Interface TelemetryInitializerBase it is kind of mandatory to send it not null.

\test\Microsoft.ApplicationInsights.AspNet.Tests\Extensions\Appli
cationInsightsExtensionsTests.cs(52,0): at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensionsTests.AddApplicationI
nsightsTelemetry.RegistersExpectedServices(Type serviceType, Type implementationType, ServiceLifetime lifecycle)
      System.ArgumentNullException : Value cannot be null.
      Parameter name: httpContextAccessor
\test\Microsoft.ApplicationInsights.AspNet.Tests\Extensions\Appli
cationInsightsExtensionsTests.cs(275,0): at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensionsTests.AddApplication
InsightsSettings.RegistersTelemetryConfigurationFactoryMethodThatReadsInstrumentationKeyFromSettings()
      System.ArgumentNullException : Value cannot be null.
      Parameter name: httpContextAccessor

Copy link
Contributor

Choose a reason for hiding this comment

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

Just inherit it from ITelemetryInitializer, not TelemetryInitializerBase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Let me know if the latest commits work.

Copy link
Member

Choose a reason for hiding this comment

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

Unit tests all pass.

gzepeda added 3 commits March 23, 2016 16:33
…lizer.

- Removed not needed Unit tests.
- Initialize dependency calling the constructor explicitly.
@@ -14,7 +14,7 @@
"delaySign": true
},
"dependencies": {
"Microsoft.ApplicationInsights": "2.0.0-*",
"Microsoft.ApplicationInsights": "2.0.0-beta4",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we specifically referring to beta4 here?

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 for all of your changes, unless there is a problem with 2.0.0-* please go ahead and change it and then we will complete the pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@dnduffy dnduffy merged commit ddfc159 into microsoft:develop Mar 25, 2016
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