Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 2156609

Browse files
authored
add telemetry of resource-kit versions usage (#704)
1 parent 67c8b20 commit 2156609

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

.azure-pipelines/main.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pool:
1010

1111
variables:
1212
configuration: 'Release'
13-
BASE_VERSION: '0.0.1'
13+
BASE_VERSION: '1.0.0'
1414
PREVIEW_LABEL: 'preview'
1515
BUILD_NUMBER: $[counter(format('{0}_{1}_{2}', variables['BASE_VERSION'], variables['PREVIEW_LABEL'], variables['Build.SourceBranch']), 1)]
1616
APP_VERSION: $[format('{0}-{1}.{2}', variables['BASE_VERSION'], variables['PREVIEW_LABEL'], variables['BUILD_NUMBER'])]
@@ -63,13 +63,17 @@ stages:
6363
publishTestResults: true
6464
projects: 'tests/**/*Tests/*.csproj'
6565

66-
- task: DotNetCoreCLI@2
66+
- pwsh: |
67+
$buildNumberVersion = $env:APP_VERSION.Split(".")[-1]
68+
$assemblyVersion = "$($env:BASE_VERSION).$($buildNumberVersion)"
69+
Write-Host "Assembly Version: $($assemblyVersion)"
70+
Write-Host "##vso[task.setvariable variable=ASSEMBLY_VERSION]$assemblyVersion"
71+
displayName: Generate AssemblyVersion for publishing binaries
72+
73+
- pwsh: |
74+
dotnet publish src/ArmTemplates/ArmTemplates.csproj --configuration $(configuration) --output $(Build.ArtifactStagingDirectory) /p:Version=$env:ASSEMBLY_VERSION
6775
displayName: 'Publish build artifacts'
68-
inputs:
69-
command: publish
70-
arguments: '--configuration $(configuration) --output $(Build.ArtifactStagingDirectory)'
71-
publishWebProjects: false
72-
76+
7377
- pwsh: |
7478
New-Item '$(Build.ArtifactStagingDirectory)/build' -Type Directory
7579
Get-ChildItem -Path 'src/ArmTemplates/bin/$(configuration)/net6.0' -File | %{

src/ArmTemplates/Application.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
using System.Reflection;
7+
8+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates
9+
{
10+
class Application
11+
{
12+
public const string Name = "azure-api-management-devops-resource-kit";
13+
14+
public static readonly string BuildVersion = Assembly.GetEntryAssembly().GetName().Version.ToString();
15+
}
16+
}

src/ArmTemplates/ArmTemplates.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<LangVersion>latest</LangVersion>
88
<PackAsTool>true</PackAsTool>
99
<ToolCommandName>apim-templates</ToolCommandName>
10-
<Version>1.0.0</Version>
10+
<Version>0.0.0.0</Version>
1111
<RootNamespace>$(SolutionName).$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
1212
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
1313
<DockerfileContext>..\..</DockerfileContext>

src/ArmTemplates/Common/API/Clients/Abstractions/ApiClientBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected async Task<string> CallApiManagementAsync(string azToken, string reque
4141

4242
var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
4343
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", azToken);
44+
request.Headers.UserAgent.TryParseAdd($"{Application.Name}/{Application.BuildVersion}");
4445

4546
HttpResponseMessage response = await this.httpClient.SendAsync(request);
4647
response.EnsureSuccessStatusCode();

src/ArmTemplates/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using CommandLine.Text;
1515
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
1616
using System.Linq;
17+
using System.Runtime.InteropServices;
1718

1819
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates
1920
{
@@ -24,14 +25,16 @@ public static async Task Main(string[] args)
2425
var applicationLogger = SetupApplicationLoggingToConsole();
2526
var serviceProvider = CreateServiceProvider(applicationLogger);
2627

28+
applicationLogger.Information("Booting up Azure-Api-Management-DevOps-Resource-Kit v{0} running .NET {1}", Application.BuildVersion, RuntimeInformation.FrameworkDescription);
29+
2730
var commandLineParser = new Parser(parserSettings =>
2831
{
2932
parserSettings.HelpWriter = Console.Out;
3033
parserSettings.CaseSensitive = true;
3134
});
3235

3336
var parserResult = commandLineParser.ParseArguments<ExtractorConsoleAppConfiguration, CreateConsoleAppConfiguration>(args);
34-
37+
3538
await parserResult.MapResult(
3639
async (ExtractorConsoleAppConfiguration consoleAppConfiguration) =>
3740
{

0 commit comments

Comments
 (0)