Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit fca773d

Browse files
committed
Add SDK version telemetry header
1 parent 737ef12 commit fca773d

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
"console": "internalConsole",
1616
"stopAtEntry": false
1717
},
18+
{
19+
"name": "login",
20+
"type": "coreclr",
21+
"request": "launch",
22+
"preLaunchTask": "build",
23+
"program": "${workspaceFolder}/src/bin/Debug/net6.0/mgc.dll",
24+
"args": ["login", "--scopes", "User.ReadWrite Mail.ReadWrite"],
25+
"cwd": "${workspaceFolder}",
26+
"console": "internalConsole",
27+
"stopAtEntry": false
28+
},
1829
{
1930
"name": "me get",
2031
"type": "coreclr",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
namespace Microsoft.Graph.Cli.Authentication;
22

3+
/// <summary>
4+
/// The authentication strategy to use
5+
/// </summary>
36
public enum AuthenticationStrategy {
7+
/// <summary>
8+
/// Device code strategy
9+
/// </summary>
410
DeviceCode
511
}

src/Authentication/LoginServiceBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.IO;
23
using System.Threading.Tasks;
34
using Azure.Identity;
@@ -14,7 +15,9 @@ public async Task LoginAsync(string[] scopes) {
1415
protected abstract Task<AuthenticationRecord> DoLoginAsync(string[] scopes);
1516

1617
public async Task SaveSessionAsync(AuthenticationRecord record) {
17-
using var authRecordStream = new FileStream(Constants.AuthRecordPath, FileMode.OpenOrCreate, FileAccess.Write);
18+
var homeDir = Environment.GetEnvironmentVariable("HOME") ?? Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
19+
var recordPath = Path.Combine(homeDir, Constants.ApplicationDataDirectory, Constants.AuthRecordPath);
20+
using var authRecordStream = new FileStream(recordPath, FileMode.OpenOrCreate, FileAccess.Write);
1821
await record.SerializeAsync(authRecordStream);
1922
}
2023
}

src/Program.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,31 @@
66
using Microsoft.Kiota.Authentication.Azure;
77
using Microsoft.Kiota.Http.HttpClientLibrary;
88
using System.CommandLine;
9+
using System.Net.Http;
10+
using System.Reflection;
911
using System.Threading.Tasks;
1012

1113
namespace Microsoft.Graph.Cli
1214
{
1315
class Program {
16+
const string SdkVersionHeaderValueFormatString = "{0}-cli-{1}.{2}.{3}";
17+
1418
static async Task<int> Main(string[] args) {
1519
var authServiceFactory = new AuthenticationServiceFactory();
1620
var authStrategy = AuthenticationStrategy.DeviceCode;
1721

1822
var credential = await authServiceFactory.GetTokenCredentialAsync(authStrategy);
1923
var authProvider = new AzureIdentityAuthenticationProvider(credential);
20-
var core = new HttpClientRequestAdapter(authProvider);
24+
var httpClient = new HttpClient();
25+
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
26+
var sdkVersionHeaderValue = string.Format(
27+
SdkVersionHeaderValueFormatString,
28+
"graph",
29+
assemblyVersion.Major,
30+
assemblyVersion.Minor,
31+
assemblyVersion.Build);
32+
httpClient.DefaultRequestHeaders.Add("SdkVersion", sdkVersionHeaderValue);
33+
var core = new HttpClientRequestAdapter(authProvider, null, null, httpClient);
2134
var client = new GraphClient(core);
2235

2336
var rootCommand = client.BuildCommand();

src/msgraph-cli.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<SelfContained>false</SelfContained>
1111
<PublishReadyToRun>true</PublishReadyToRun>
1212
<AssemblyName>mgc</AssemblyName>
13+
<Version>0.1.0-preview1</Version>
1314
</PropertyGroup>
1415

1516
<ItemGroup>

src/utils/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace Microsoft.Graph.Cli.Utils
44
{
55
class Constants
66
{
7+
public const string ApplicationDataDirectory = ".mgc";
8+
79
public const string AuthRecordPath = "authRecord";
810

911
public const string TokenCacheName = "MicrosoftGraph";

0 commit comments

Comments
 (0)