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 telemetry data points for .NET Core 2.0 #1459

Merged
merged 1 commit into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Copyright (c) .NET Foundation. All rights reserved.
FormatArguments="$([MSBuild]::Escape('$(TargetFramework)'))" />
</Target>

<Target Name="_CollectTargetFrameworkForTelemetry" AfterTargets="_CheckForUnsupportedTargetFramework">
<Telemetry EventName="TargetFramework" EventData="version=$([MSBuild]::Escape('$(TargetFrameworkMoniker)'))" />
</Target>

<!--
Don't leave TargetFrameworkVersion empty if it still hasn't been determined. We will trigger the error above,
but we need this to be a valid version so that our error message does not get pre-empted by failure to interpret
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using FluentAssertions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using System;
using System.IO;
using Xunit;
using Xunit.Abstractions;
using System.Reflection;

namespace Microsoft.NET.Build.Tests
{
public class GivenThatWeWantToBuildANetCoreAppAndPassingALogger : SdkTest
{
public GivenThatWeWantToBuildANetCoreAppAndPassingALogger(ITestOutputHelper log) : base(log)
{
}

[CoreMSBuildOnlyFact]
public void It_collects_TargetFramework_version()
{
string targetFramework = "netcoreapp1.0";
var testProject = new TestProject()
{
Name = "FrameworkTargetTelemetryTest",
TargetFrameworks = targetFramework,
IsSdkProject = true,
};
Type loggerType = typeof(LogTelemetryToStdOutForTest);
var TelemetryTestLogger = new[]
{
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
};
var testAsset = _testAssetsManager.CreateTestProject(testProject)
.Restore(Log, testProject.Name, TelemetryTestLogger);

var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));

buildCommand
.Execute(TelemetryTestLogger)
.StdOut.Should()
.Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETCoreApp,Version=v1.0\"}");
}

[CoreMSBuildOnlyFact]
public void It_collects_multi_TargetFramework_version()
{
string targetFramework = "net46;netcoreapp1.1";

var testProject = new TestProject()
{
Name = "MultitargetTelemetry",
TargetFrameworks = targetFramework,
IsSdkProject = true,
};
Type loggerType = typeof(LogTelemetryToStdOutForTest);
var TelemetryTestLogger = new[]
{
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
};
var testAsset = _testAssetsManager.CreateTestProject(testProject)
.Restore(Log, testProject.Name, TelemetryTestLogger);

var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));

buildCommand
.Execute(TelemetryTestLogger)
.StdOut.Should()
.Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETFramework,Version=v4.6\"}")
.And
.Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETCoreApp,Version=v1.1\"}");
}
}
}
31 changes: 31 additions & 0 deletions test/Microsoft.NET.Build.Tests/LogTelemetryToStdOutForTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Protocol;

namespace Microsoft.NET.Build.Tests
{
public sealed class LogTelemetryToStdOutForTest : Logger
{

public LogTelemetryToStdOutForTest()
{
}

public override void Initialize(IEventSource eventSource)
{
if (eventSource is IEventSource2 eventSource2)
{
eventSource2.TelemetryLogged += OnTelemetryLogged;
}
}

private void OnTelemetryLogged(object sender, TelemetryEventArgs args)
{
Console.WriteLine(args.ToJson());
}
}
}