Skip to content

Commit 67800b0

Browse files
authored
Adding telemetry shared items project to package manager client project (#4)
* Adding Telemetry shared project to the PackageManager client project * Adding Privacy Statement and updating telemetry statement in readme.
1 parent 8ec6687 commit 67800b0

File tree

11 files changed

+276
-0
lines changed

11 files changed

+276
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ provided by the bot. You will only need to do this once across all repos using o
1212
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
1313
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
1414
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
15+
16+
17+
Data/Telemetry
18+
19+
This project collects usage data and sends it to Microsoft to help improve our products and services. See the privacy statement for more details.
20+

privacy.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Data Collection
2+
3+
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.

src/AppInstallerCLI/AppInstallerCLI.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<ImportGroup Label="ExtensionSettings">
7070
</ImportGroup>
7171
<ImportGroup Label="Shared">
72+
<Import Project="..\Telemetry\Telemetry.vcxitems" Label="Shared" />
7273
</ImportGroup>
7374
<ImportGroup Label="PropertySheets">
7475
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />

src/AppInstallerCLI/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using namespace AppInstaller::CLI;
1010
int wmain(int argc, wchar_t const** argv) try
1111
{
1212
init_apartment();
13+
RegisterTraceLogging();
1314

1415
RootCommand root;
1516
Invocation invocation{ argc, argv };
@@ -32,6 +33,7 @@ int wmain(int argc, wchar_t const** argv) try
3233
catch (const CommandException& ce)
3334
{
3435
commandToExecute->OutputHelp(std::wcout, &ce);
36+
UnRegisterTraceLogging();
3537
return 1;
3638
}
3739

@@ -48,6 +50,8 @@ int wmain(int argc, wchar_t const** argv) try
4850
{
4951

5052
}
53+
54+
UnRegisterTraceLogging();
5155
}
5256
// End of the line exceptions that are not ever expected
5357
catch (const winrt::hresult_error&)

src/AppInstallerCLI/pch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66

77
#include <iostream>
88
#include <memory>
9+
#include <windows.h>
10+
#include "TraceLogging.h"

src/AppInstallerClient.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "AppInstallerClientPackage",
77
EndProject
88
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppInstallerCLI", "AppInstallerCLI\AppInstallerCLI.vcxproj", "{5B6F90DF-FD19-4BAE-83D9-24DAD128E777}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{60618CAC-2995-4DF9-9914-45C6FC02C995}"
11+
EndProject
12+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Telemetry", "Telemetry\Telemetry.vcxitems", "{4B988559-DDBD-4456-9300-0C3AAD12C466}"
13+
EndProject
1014
Global
15+
GlobalSection(SharedMSBuildProjectFiles) = preSolution
16+
Telemetry\Telemetry.vcxitems*{4b988559-ddbd-4456-9300-0c3aad12c466}*SharedItemsImports = 9
17+
Telemetry\Telemetry.vcxitems*{5b6f90df-fd19-4bae-83d9-24dad128e777}*SharedItemsImports = 4
18+
EndGlobalSection
1119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1220
Debug|Any CPU = Debug|Any CPU
1321
Debug|ARM = Debug|ARM
@@ -73,6 +81,9 @@ Global
7381
GlobalSection(SolutionProperties) = preSolution
7482
HideSolutionNode = FALSE
7583
EndGlobalSection
84+
GlobalSection(NestedProjects) = preSolution
85+
{4B988559-DDBD-4456-9300-0C3AAD12C466} = {60618CAC-2995-4DF9-9914-45C6FC02C995}
86+
EndGlobalSection
7687
GlobalSection(ExtensibilityGlobals) = postSolution
7788
SolutionGuid = {B6FDB70C-A751-422C-ACD1-E35419495857}
7889
EndGlobalSection

src/Telemetry/MicrosoftTelemetry.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* ++
2+
3+
Copyright (c) Microsoft Corporation. All rights reserved.
4+
Licensed under the MIT License. See LICENSE in the project root for license information.
5+
6+
Module Name:
7+
8+
MicrosoftTelemetry.h
9+
10+
Abstract:
11+
12+
Macro definitions used by this project's TraceLogging ETW providers:
13+
14+
- Configuration macros that select the ETW Provider Groups to be used by
15+
this project.
16+
- Constants for tags that are commonly used in Microsoft's
17+
TraceLogging-based ETW.
18+
19+
Different versions of this file use different definitions for the
20+
TraceLoggingOption configuration macros. The definitions in this file are
21+
empty. As a result, providers using this configuration file will not join
22+
any ETW Provider Groups and will not be given any special treatment by
23+
group-sensitive ETW listeners.
24+
25+
Environment:
26+
27+
User mode or kernel mode.
28+
29+
--*/
30+
31+
#pragma once
32+
33+
// Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition
34+
// in this file configures the provider as a normal (non-telemetry) provider.
35+
#define TraceLoggingOptionMicrosoftTelemetry() \
36+
// Empty definition for TraceLoggingOptionMicrosoftTelemetry
37+
38+
// Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition
39+
// in this file configures the provider as a normal (non-telemetry) provider.
40+
#define TraceLoggingOptionWindowsCoreTelemetry() \
41+
// Empty definition for TraceLoggingOptionWindowsCoreTelemetry
42+
43+
// Event privacy tags. Use the PDT macro values for the tag parameter, e.g.:
44+
// TraceLoggingWrite(...,
45+
// TelemetryPrivacyDataTag(PDT_BrowsingHistory | PDT_ProductAndServiceUsage),
46+
// ...);
47+
#define TelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "PartA_PrivTags")
48+
#define PDT_BrowsingHistory 0x0000000000000002u
49+
#define PDT_DeviceConnectivityAndConfiguration 0x0000000000000800u
50+
#define PDT_InkingTypingAndSpeechUtterance 0x0000000000020000u
51+
#define PDT_ProductAndServicePerformance 0x0000000001000000u
52+
#define PDT_ProductAndServiceUsage 0x0000000002000000u
53+
#define PDT_SoftwareSetupAndInventory 0x0000000080000000u
54+
55+
// Event categories specified via keywords, e.g.:
56+
// TraceLoggingWrite(...,
57+
// TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
58+
// ...);
59+
#define MICROSOFT_KEYWORD_CRITICAL_DATA 0x0000800000000000 // Bit 47
60+
#define MICROSOFT_KEYWORD_MEASURES 0x0000400000000000 // Bit 46
61+
#define MICROSOFT_KEYWORD_TELEMETRY 0x0000200000000000 // Bit 45
62+
#define MICROSOFT_KEYWORD_RESERVED_44 0x0000100000000000 // Bit 44 (reserved for future assignment)
63+
64+
// Event categories specified via event tags, e.g.:
65+
// TraceLoggingWrite(...,
66+
// TraceLoggingEventTag(MICROSOFT_EVENTTAG_REALTIME_LATENCY),
67+
// ...);
68+
#define MICROSOFT_EVENTTAG_DROP_USER_IDS 0x00008000
69+
#define MICROSOFT_EVENTTAG_AGGREGATE 0x00010000
70+
#define MICROSOFT_EVENTTAG_DROP_PII_EXCEPT_IP 0x00020000
71+
#define MICROSOFT_EVENTTAG_COSTDEFERRED_LATENCY 0x00040000
72+
#define MICROSOFT_EVENTTAG_CORE_DATA 0x00080000
73+
#define MICROSOFT_EVENTTAG_INJECT_XTOKEN 0x00100000
74+
#define MICROSOFT_EVENTTAG_REALTIME_LATENCY 0x00200000
75+
#define MICROSOFT_EVENTTAG_NORMAL_LATENCY 0x00400000
76+
#define MICROSOFT_EVENTTAG_CRITICAL_PERSISTENCE 0x00800000
77+
#define MICROSOFT_EVENTTAG_NORMAL_PERSISTENCE 0x01000000
78+
#define MICROSOFT_EVENTTAG_DROP_PII 0x02000000
79+
#define MICROSOFT_EVENTTAG_HASH_PII 0x04000000
80+
#define MICROSOFT_EVENTTAG_MARK_PII 0x08000000
81+
82+
// Field categories specified via field tags, e.g.:
83+
// TraceLoggingWrite(...,
84+
// TraceLoggingString(szUser, "UserName", "User's name", MICROSOFT_FIELDTAG_HASH_PII),
85+
// ...);
86+
#define MICROSOFT_FIELDTAG_DROP_PII 0x04000000
87+
#define MICROSOFT_FIELDTAG_HASH_PII 0x08000000

src/Telemetry/Telemetry.vcxitems

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
<HasSharedItems>true</HasSharedItems>
6+
<ItemsProjectGuid>{4b988559-ddbd-4456-9300-0c3aad12c466}</ItemsProjectGuid>
7+
</PropertyGroup>
8+
<ItemDefinitionGroup>
9+
<ClCompile>
10+
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
11+
</ClCompile>
12+
</ItemDefinitionGroup>
13+
<ItemGroup>
14+
<ProjectCapability Include="SourceItemsFromImports" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<ClCompile Include="$(MSBuildThisFileDirectory)TraceLogging.cpp" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<ClInclude Include="$(MSBuildThisFileDirectory)MicrosoftTelemetry.h" />
21+
<ClInclude Include="$(MSBuildThisFileDirectory)TraceLogging.h" />
22+
<ClInclude Include="$(MSBuildThisFileDirectory)WinEventLogLevels.h" />
23+
</ItemGroup>
24+
</Project>

src/Telemetry/TraceLogging.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
#include "pch.h"
5+
#include "TraceLogging.h"
6+
7+
// GUID for Microsoft.PackageManager.Client : {c0cf606f-569b-5c20-27d9-88a745fa2175}
8+
TRACELOGGING_DEFINE_PROVIDER(
9+
g_hTelemetryProvider,
10+
"Microsoft.PackageManager.Client",
11+
(0xc0cf606f, 0x569b, 0x5c20, 0x27, 0xd9, 0x88, 0xa7, 0x45, 0xfa, 0x21, 0x75),
12+
TraceLoggingOptionMicrosoftTelemetry());
13+
14+
bool g_IsTelemetryProviderEnabled{};
15+
UCHAR g_TelemetryProviderLevel{};
16+
ULONGLONG g_TelemetryProviderMatchAnyKeyword{};
17+
GUID g_TelemetryProviderActivityId{};
18+
19+
void WINAPI TelemetryProviderEnabledCallback(
20+
_In_ LPCGUID /*sourceId*/,
21+
_In_ ULONG isEnabled,
22+
_In_ UCHAR level,
23+
_In_ ULONGLONG matchAnyKeyword,
24+
_In_ ULONGLONG /*matchAllKeywords*/,
25+
_In_opt_ PEVENT_FILTER_DESCRIPTOR /*filterData*/,
26+
_In_opt_ PVOID /*callbackContext*/)
27+
{
28+
g_IsTelemetryProviderEnabled = !!isEnabled;
29+
g_TelemetryProviderLevel = level;
30+
g_TelemetryProviderMatchAnyKeyword = matchAnyKeyword;
31+
}
32+
33+
void RegisterTraceLogging()
34+
{
35+
HRESULT hr = S_OK;
36+
37+
TraceLoggingRegisterEx(g_hTelemetryProvider, TelemetryProviderEnabledCallback, nullptr);
38+
//Generate the ActivityId used to track the session
39+
hr = CoCreateGuid(&g_TelemetryProviderActivityId);
40+
if (FAILED(hr))
41+
{
42+
TraceLoggingWriteActivity(
43+
g_hTelemetryProvider,
44+
"CreateGuidError",
45+
nullptr,
46+
nullptr,
47+
TraceLoggingHResult(hr),
48+
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES));
49+
50+
g_TelemetryProviderActivityId = GUID_NULL;
51+
};
52+
}
53+
54+
void UnRegisterTraceLogging()
55+
{
56+
TraceLoggingUnregister(g_hTelemetryProvider);
57+
}

src/Telemetry/TraceLogging.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
#pragma once
5+
6+
#include "WinEventLogLevels.h"
7+
#include <TraceLoggingProvider.h>
8+
9+
#include "MicrosoftTelemetry.h"
10+
11+
// Keywords
12+
#define KEYWORD_REPEATER 0x0000000000000001
13+
#define KEYWORD_SCROLLER 0x0000000000000002
14+
#define KEYWORD_PTR 0x0000000000000004
15+
#define KEYWORD_SCROLLVIEWER 0x0000000000000008
16+
#define KEYWORD_SWIPECONTROL 0x0000000000000010
17+
#define KEYWORD_COMMANDBARFLYOUT 0x0000000000000020
18+
19+
// Common output formats
20+
#define TRACE_MSG_METH L"%s[0x%p]()\n"
21+
#define TRACE_MSG_METH_DBL L"%s[0x%p](%lf)\n"
22+
#define TRACE_MSG_METH_DBL_DBL L"%s[0x%p](%lf, %lf)\n"
23+
#define TRACE_MSG_METH_DBL_INT L"%s[0x%p](%lf, %d)\n"
24+
#define TRACE_MSG_METH_DBL_DBL_INT L"%s[0x%p](%lf, %lf, %d)\n"
25+
#define TRACE_MSG_METH_DBL_DBL_FLT L"%s[0x%p](%lf, %lf, %f)\n"
26+
#define TRACE_MSG_METH_DBL_DBL_STR L"%s[0x%p](%lf, %lf, %s)\n"
27+
#define TRACE_MSG_METH_FLT L"%s[0x%p](%f)\n"
28+
#define TRACE_MSG_METH_FLT_FLT L"%s[0x%p](%f, %f)\n"
29+
#define TRACE_MSG_METH_FLT_FLT_FLT L"%s[0x%p](%f, %f, %f)\n"
30+
#define TRACE_MSG_METH_FLT_FLT_FLT_FLT L"%s[0x%p](%f, %f, %f, %f)\n"
31+
#define TRACE_MSG_METH_FLT_FLT_STR_INT L"%s[0x%p](%f, %f, %s, %d)\n"
32+
#define TRACE_MSG_METH_INT L"%s[0x%p](%d)\n"
33+
#define TRACE_MSG_METH_INT_INT L"%s[0x%p](%d, %d)\n"
34+
#define TRACE_MSG_METH_PTR L"%s[0x%p](0x%p)\n"
35+
#define TRACE_MSG_METH_PTR_PTR L"%s[0x%p](0x%p, 0x%p)\n"
36+
#define TRACE_MSG_METH_PTR_DBL L"%s[0x%p](0x%p, %lf)\n"
37+
#define TRACE_MSG_METH_PTR_INT L"%s[0x%p](0x%p, %d)\n"
38+
#define TRACE_MSG_METH_PTR_STR L"%s[0x%p](0x%p, %s)\n"
39+
#define TRACE_MSG_METH_STR L"%s[0x%p](%s)\n"
40+
#define TRACE_MSG_METH_STR_STR L"%s[0x%p](%s, %s)\n"
41+
#define TRACE_MSG_METH_STR_DBL L"%s[0x%p](%s, %lf)\n"
42+
#define TRACE_MSG_METH_STR_FLT L"%s[0x%p](%s, %f)\n"
43+
#define TRACE_MSG_METH_STR_INT L"%s[0x%p](%s, %d)\n"
44+
#define TRACE_MSG_METH_STR_STR_STR L"%s[0x%p](%s, %s, %s)\n"
45+
#define TRACE_MSG_METH_STR_INT_INT L"%s[0x%p](%s, %d, %d)\n"
46+
#define TRACE_MSG_METH_STR_FLT_FLT L"%s[0x%p](%s, %f, %f)\n"
47+
#define TRACE_MSG_METH_STR_STR_FLT L"%s[0x%p](%s, %s, %f)\n"
48+
#define TRACE_MSG_METH_STR_STR_INT_INT L"%s[0x%p](%s, %s, %d, %d)\n"
49+
50+
#define TRACE_MSG_METH_METH L"%s[0x%p] - calls %s()\n"
51+
#define TRACE_MSG_METH_METH_INT L"%s[0x%p] - calls %s(%d)\n"
52+
#define TRACE_MSG_METH_METH_STR L"%s[0x%p] - calls %s(%s)\n"
53+
#define TRACE_MSG_METH_METH_STR_STR L"%s[0x%p] - calls %s(%s, %s)\n"
54+
#define TRACE_MSG_METH_METH_FLT_STR L"%s[0x%p] - calls %s(%f, %s)\n"
55+
#define TRACE_MSG_METH_METH_FLT_FLT_FLT L"%s[0x%p] - calls %s(%f, %f, %f)\n"
56+
57+
// Current method name
58+
#define METH_NAME StringUtil::Utf8ToUtf16(__FUNCTION__).c_str()
59+
60+
// TraceLogging provider name for telemetry.
61+
#define TELEMETRY_PROVIDER_NAME "Microsoft.PackageManager.Client"
62+
63+
TRACELOGGING_DECLARE_PROVIDER(g_hTelemetryProvider);
64+
extern bool g_IsTelemetryProviderEnabled;
65+
extern UCHAR g_TelemetryProviderLevel;
66+
extern ULONGLONG g_TelemetryProviderMatchAnyKeyword;
67+
extern GUID g_TelemetryProviderActivityId;
68+
69+
extern void RegisterTraceLogging();
70+
extern void UnRegisterTraceLogging();

0 commit comments

Comments
 (0)