Skip to content

Commit

Permalink
Adding telemetry shared items project to package manager client proje…
Browse files Browse the repository at this point in the history
…ct (#4)

* Adding Telemetry shared project to the PackageManager client project

* Adding Privacy Statement and updating telemetry statement in readme.
  • Loading branch information
mapill-msft authored Dec 9, 2019
1 parent 8ec6687 commit 67800b0
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ provided by the bot. You will only need to do this once across all repos using o
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.


Data/Telemetry

This project collects usage data and sends it to Microsoft to help improve our products and services. See the privacy statement for more details.

3 changes: 3 additions & 0 deletions privacy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Data Collection

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.
1 change: 1 addition & 0 deletions src/AppInstallerCLI/AppInstallerCLI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
<Import Project="..\Telemetry\Telemetry.vcxitems" Label="Shared" />
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
Expand Down
4 changes: 4 additions & 0 deletions src/AppInstallerCLI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace AppInstaller::CLI;
int wmain(int argc, wchar_t const** argv) try
{
init_apartment();
RegisterTraceLogging();

RootCommand root;
Invocation invocation{ argc, argv };
Expand All @@ -32,6 +33,7 @@ int wmain(int argc, wchar_t const** argv) try
catch (const CommandException& ce)
{
commandToExecute->OutputHelp(std::wcout, &ce);
UnRegisterTraceLogging();
return 1;
}

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

}

UnRegisterTraceLogging();
}
// End of the line exceptions that are not ever expected
catch (const winrt::hresult_error&)
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCLI/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

#include <iostream>
#include <memory>
#include <windows.h>
#include "TraceLogging.h"
11 changes: 11 additions & 0 deletions src/AppInstallerClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "AppInstallerClientPackage",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppInstallerCLI", "AppInstallerCLI\AppInstallerCLI.vcxproj", "{5B6F90DF-FD19-4BAE-83D9-24DAD128E777}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{60618CAC-2995-4DF9-9914-45C6FC02C995}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Telemetry", "Telemetry\Telemetry.vcxitems", "{4B988559-DDBD-4456-9300-0C3AAD12C466}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Telemetry\Telemetry.vcxitems*{4b988559-ddbd-4456-9300-0c3aad12c466}*SharedItemsImports = 9
Telemetry\Telemetry.vcxitems*{5b6f90df-fd19-4bae-83d9-24dad128e777}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Expand Down Expand Up @@ -73,6 +81,9 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4B988559-DDBD-4456-9300-0C3AAD12C466} = {60618CAC-2995-4DF9-9914-45C6FC02C995}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6FDB70C-A751-422C-ACD1-E35419495857}
EndGlobalSection
Expand Down
87 changes: 87 additions & 0 deletions src/Telemetry/MicrosoftTelemetry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* ++
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See LICENSE in the project root for license information.
Module Name:
MicrosoftTelemetry.h
Abstract:
Macro definitions used by this project's TraceLogging ETW providers:
- Configuration macros that select the ETW Provider Groups to be used by
this project.
- Constants for tags that are commonly used in Microsoft's
TraceLogging-based ETW.
Different versions of this file use different definitions for the
TraceLoggingOption configuration macros. The definitions in this file are
empty. As a result, providers using this configuration file will not join
any ETW Provider Groups and will not be given any special treatment by
group-sensitive ETW listeners.
Environment:
User mode or kernel mode.
--*/

#pragma once

// Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition
// in this file configures the provider as a normal (non-telemetry) provider.
#define TraceLoggingOptionMicrosoftTelemetry() \
// Empty definition for TraceLoggingOptionMicrosoftTelemetry

// Configuration macro for use in TRACELOGGING_DEFINE_PROVIDER. The definition
// in this file configures the provider as a normal (non-telemetry) provider.
#define TraceLoggingOptionWindowsCoreTelemetry() \
// Empty definition for TraceLoggingOptionWindowsCoreTelemetry

// Event privacy tags. Use the PDT macro values for the tag parameter, e.g.:
// TraceLoggingWrite(...,
// TelemetryPrivacyDataTag(PDT_BrowsingHistory | PDT_ProductAndServiceUsage),
// ...);
#define TelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "PartA_PrivTags")
#define PDT_BrowsingHistory 0x0000000000000002u
#define PDT_DeviceConnectivityAndConfiguration 0x0000000000000800u
#define PDT_InkingTypingAndSpeechUtterance 0x0000000000020000u
#define PDT_ProductAndServicePerformance 0x0000000001000000u
#define PDT_ProductAndServiceUsage 0x0000000002000000u
#define PDT_SoftwareSetupAndInventory 0x0000000080000000u

// Event categories specified via keywords, e.g.:
// TraceLoggingWrite(...,
// TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
// ...);
#define MICROSOFT_KEYWORD_CRITICAL_DATA 0x0000800000000000 // Bit 47
#define MICROSOFT_KEYWORD_MEASURES 0x0000400000000000 // Bit 46
#define MICROSOFT_KEYWORD_TELEMETRY 0x0000200000000000 // Bit 45
#define MICROSOFT_KEYWORD_RESERVED_44 0x0000100000000000 // Bit 44 (reserved for future assignment)

// Event categories specified via event tags, e.g.:
// TraceLoggingWrite(...,
// TraceLoggingEventTag(MICROSOFT_EVENTTAG_REALTIME_LATENCY),
// ...);
#define MICROSOFT_EVENTTAG_DROP_USER_IDS 0x00008000
#define MICROSOFT_EVENTTAG_AGGREGATE 0x00010000
#define MICROSOFT_EVENTTAG_DROP_PII_EXCEPT_IP 0x00020000
#define MICROSOFT_EVENTTAG_COSTDEFERRED_LATENCY 0x00040000
#define MICROSOFT_EVENTTAG_CORE_DATA 0x00080000
#define MICROSOFT_EVENTTAG_INJECT_XTOKEN 0x00100000
#define MICROSOFT_EVENTTAG_REALTIME_LATENCY 0x00200000
#define MICROSOFT_EVENTTAG_NORMAL_LATENCY 0x00400000
#define MICROSOFT_EVENTTAG_CRITICAL_PERSISTENCE 0x00800000
#define MICROSOFT_EVENTTAG_NORMAL_PERSISTENCE 0x01000000
#define MICROSOFT_EVENTTAG_DROP_PII 0x02000000
#define MICROSOFT_EVENTTAG_HASH_PII 0x04000000
#define MICROSOFT_EVENTTAG_MARK_PII 0x08000000

// Field categories specified via field tags, e.g.:
// TraceLoggingWrite(...,
// TraceLoggingString(szUser, "UserName", "User's name", MICROSOFT_FIELDTAG_HASH_PII),
// ...);
#define MICROSOFT_FIELDTAG_DROP_PII 0x04000000
#define MICROSOFT_FIELDTAG_HASH_PII 0x08000000
24 changes: 24 additions & 0 deletions src/Telemetry/Telemetry.vcxitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<ItemsProjectGuid>{4b988559-ddbd-4456-9300-0c3aad12c466}</ItemsProjectGuid>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)TraceLogging.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)MicrosoftTelemetry.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TraceLogging.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)WinEventLogLevels.h" />
</ItemGroup>
</Project>
57 changes: 57 additions & 0 deletions src/Telemetry/TraceLogging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
#include "TraceLogging.h"

// GUID for Microsoft.PackageManager.Client : {c0cf606f-569b-5c20-27d9-88a745fa2175}
TRACELOGGING_DEFINE_PROVIDER(
g_hTelemetryProvider,
"Microsoft.PackageManager.Client",
(0xc0cf606f, 0x569b, 0x5c20, 0x27, 0xd9, 0x88, 0xa7, 0x45, 0xfa, 0x21, 0x75),
TraceLoggingOptionMicrosoftTelemetry());

bool g_IsTelemetryProviderEnabled{};
UCHAR g_TelemetryProviderLevel{};
ULONGLONG g_TelemetryProviderMatchAnyKeyword{};
GUID g_TelemetryProviderActivityId{};

void WINAPI TelemetryProviderEnabledCallback(
_In_ LPCGUID /*sourceId*/,
_In_ ULONG isEnabled,
_In_ UCHAR level,
_In_ ULONGLONG matchAnyKeyword,
_In_ ULONGLONG /*matchAllKeywords*/,
_In_opt_ PEVENT_FILTER_DESCRIPTOR /*filterData*/,
_In_opt_ PVOID /*callbackContext*/)
{
g_IsTelemetryProviderEnabled = !!isEnabled;
g_TelemetryProviderLevel = level;
g_TelemetryProviderMatchAnyKeyword = matchAnyKeyword;
}

void RegisterTraceLogging()
{
HRESULT hr = S_OK;

TraceLoggingRegisterEx(g_hTelemetryProvider, TelemetryProviderEnabledCallback, nullptr);
//Generate the ActivityId used to track the session
hr = CoCreateGuid(&g_TelemetryProviderActivityId);
if (FAILED(hr))
{
TraceLoggingWriteActivity(
g_hTelemetryProvider,
"CreateGuidError",
nullptr,
nullptr,
TraceLoggingHResult(hr),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES));

g_TelemetryProviderActivityId = GUID_NULL;
};
}

void UnRegisterTraceLogging()
{
TraceLoggingUnregister(g_hTelemetryProvider);
}
70 changes: 70 additions & 0 deletions src/Telemetry/TraceLogging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once

#include "WinEventLogLevels.h"
#include <TraceLoggingProvider.h>

#include "MicrosoftTelemetry.h"

// Keywords
#define KEYWORD_REPEATER 0x0000000000000001
#define KEYWORD_SCROLLER 0x0000000000000002
#define KEYWORD_PTR 0x0000000000000004
#define KEYWORD_SCROLLVIEWER 0x0000000000000008
#define KEYWORD_SWIPECONTROL 0x0000000000000010
#define KEYWORD_COMMANDBARFLYOUT 0x0000000000000020

// Common output formats
#define TRACE_MSG_METH L"%s[0x%p]()\n"
#define TRACE_MSG_METH_DBL L"%s[0x%p](%lf)\n"
#define TRACE_MSG_METH_DBL_DBL L"%s[0x%p](%lf, %lf)\n"
#define TRACE_MSG_METH_DBL_INT L"%s[0x%p](%lf, %d)\n"
#define TRACE_MSG_METH_DBL_DBL_INT L"%s[0x%p](%lf, %lf, %d)\n"
#define TRACE_MSG_METH_DBL_DBL_FLT L"%s[0x%p](%lf, %lf, %f)\n"
#define TRACE_MSG_METH_DBL_DBL_STR L"%s[0x%p](%lf, %lf, %s)\n"
#define TRACE_MSG_METH_FLT L"%s[0x%p](%f)\n"
#define TRACE_MSG_METH_FLT_FLT L"%s[0x%p](%f, %f)\n"
#define TRACE_MSG_METH_FLT_FLT_FLT L"%s[0x%p](%f, %f, %f)\n"
#define TRACE_MSG_METH_FLT_FLT_FLT_FLT L"%s[0x%p](%f, %f, %f, %f)\n"
#define TRACE_MSG_METH_FLT_FLT_STR_INT L"%s[0x%p](%f, %f, %s, %d)\n"
#define TRACE_MSG_METH_INT L"%s[0x%p](%d)\n"
#define TRACE_MSG_METH_INT_INT L"%s[0x%p](%d, %d)\n"
#define TRACE_MSG_METH_PTR L"%s[0x%p](0x%p)\n"
#define TRACE_MSG_METH_PTR_PTR L"%s[0x%p](0x%p, 0x%p)\n"
#define TRACE_MSG_METH_PTR_DBL L"%s[0x%p](0x%p, %lf)\n"
#define TRACE_MSG_METH_PTR_INT L"%s[0x%p](0x%p, %d)\n"
#define TRACE_MSG_METH_PTR_STR L"%s[0x%p](0x%p, %s)\n"
#define TRACE_MSG_METH_STR L"%s[0x%p](%s)\n"
#define TRACE_MSG_METH_STR_STR L"%s[0x%p](%s, %s)\n"
#define TRACE_MSG_METH_STR_DBL L"%s[0x%p](%s, %lf)\n"
#define TRACE_MSG_METH_STR_FLT L"%s[0x%p](%s, %f)\n"
#define TRACE_MSG_METH_STR_INT L"%s[0x%p](%s, %d)\n"
#define TRACE_MSG_METH_STR_STR_STR L"%s[0x%p](%s, %s, %s)\n"
#define TRACE_MSG_METH_STR_INT_INT L"%s[0x%p](%s, %d, %d)\n"
#define TRACE_MSG_METH_STR_FLT_FLT L"%s[0x%p](%s, %f, %f)\n"
#define TRACE_MSG_METH_STR_STR_FLT L"%s[0x%p](%s, %s, %f)\n"
#define TRACE_MSG_METH_STR_STR_INT_INT L"%s[0x%p](%s, %s, %d, %d)\n"

#define TRACE_MSG_METH_METH L"%s[0x%p] - calls %s()\n"
#define TRACE_MSG_METH_METH_INT L"%s[0x%p] - calls %s(%d)\n"
#define TRACE_MSG_METH_METH_STR L"%s[0x%p] - calls %s(%s)\n"
#define TRACE_MSG_METH_METH_STR_STR L"%s[0x%p] - calls %s(%s, %s)\n"
#define TRACE_MSG_METH_METH_FLT_STR L"%s[0x%p] - calls %s(%f, %s)\n"
#define TRACE_MSG_METH_METH_FLT_FLT_FLT L"%s[0x%p] - calls %s(%f, %f, %f)\n"

// Current method name
#define METH_NAME StringUtil::Utf8ToUtf16(__FUNCTION__).c_str()

// TraceLogging provider name for telemetry.
#define TELEMETRY_PROVIDER_NAME "Microsoft.PackageManager.Client"

TRACELOGGING_DECLARE_PROVIDER(g_hTelemetryProvider);
extern bool g_IsTelemetryProviderEnabled;
extern UCHAR g_TelemetryProviderLevel;
extern ULONGLONG g_TelemetryProviderMatchAnyKeyword;
extern GUID g_TelemetryProviderActivityId;

extern void RegisterTraceLogging();
extern void UnRegisterTraceLogging();
11 changes: 11 additions & 0 deletions src/Telemetry/WinEventLogLevels.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// From winmeta.h

#define WINEVENT_LEVEL_LOG_ALWAYS 0x0
#define WINEVENT_LEVEL_CRITICAL 0x1
#define WINEVENT_LEVEL_ERROR 0x2
#define WINEVENT_LEVEL_WARNING 0x3
#define WINEVENT_LEVEL_INFO 0x4
#define WINEVENT_LEVEL_VERBOSE 0x5

0 comments on commit 67800b0

Please sign in to comment.