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

Cache information for OnAddCommonCustomDimensions telemetry subscriber #567

Merged
merged 8 commits into from
Feb 16, 2024
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 @@ -110,6 +110,10 @@
{
"from": 9029,
"to": 9029
},
{
"from": 9034,
"to": 9034
}
],
"internalsVisibleTo": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace System.Azure.Identity;
using System;
using System.Security.User;
using System.Environment;
using System.Telemetry;
using System.Globalization;
using System.Security.AccessControl;
using System.Environment.Configuration;

Expand Down Expand Up @@ -312,37 +310,6 @@ codeunit 9017 "Azure AD User Mgmt. Impl."
exit(AccessControl.Count() > TempAccessControlWithDefaultPermissions.Count());
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Telemetry Custom Dimensions", OnAddCommonCustomDimensions, '', true, true)]
local procedure OnAddCommonCustomDimensions(var Sender: Codeunit "Telemetry Custom Dimensions")
var
Language: Codeunit Language;
PlanIds: Codeunit "Plan Ids";
UserAccountHelper: DotNet NavUserAccountHelper;
IsAdmin: Boolean;
CountryCode: Text;
begin
if not UserAccountHelper.IsAzure() then
exit;

// Add IsAdmin
IsAdmin := AzureADGraphUser.IsUserDelegatedAdmin() or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetGlobalAdminPlanId()) or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetD365AdminPlanId()) or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetBCAdminPlanId());
Sender.AddCommonCustomDimension('IsAdmin', Language.ToDefaultLanguage(IsAdmin));

// Add CountryCode
if TryGetCountryCode(CountryCode) then
Sender.AddCommonCustomDimension('CountryCode', CountryCode);
end;

[TryFunction]
local procedure TryGetCountryCode(var CountryCode: Text)
var
TenantInfo: DotNet TenantInfo;
begin
AzureADGraph.GetTenantDetail(TenantInfo);
if not IsNull(TenantInfo) then
CountryCode := TenantInfo.CountryLetterCode();
end;

[InternalEvent(false)]
local procedure OnIsUserTenantAdmin(var IsUserTenantAdmin: Boolean; var Handled: Boolean)
begin
Expand Down
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.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Azure.Identity;

using System;
using System.Globalization;
using System.Telemetry;

codeunit 9034 "Azure AD User Subscribers"
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;
SingleInstance = true;

var
AzureADGraphUser: Codeunit "Azure AD Graph User";
AzureADGraph: Codeunit "Azure AD Graph";
AzureADPlan: Codeunit "Azure AD Plan";
Initialized, IsAzure, IsAdmin : Boolean;
CountryCode: Text;

local procedure GetInformation()
darjoo marked this conversation as resolved.
Show resolved Hide resolved
var
PlanIds: Codeunit "Plan Ids";
UserAccountHelper: DotNet NavUserAccountHelper;
begin
if Initialized then
exit;
Initialized := true;

IsAzure := UserAccountHelper.IsAzure();
if not IsAzure then
exit;

IsAdmin := AzureADGraphUser.IsUserDelegatedAdmin() or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetGlobalAdminPlanId()) or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetD365AdminPlanId());
if TryGetCountryCode() then;
end;

[TryFunction]
local procedure TryGetCountryCode()
var
TenantInfo: DotNet TenantInfo;
begin
AzureADGraph.GetTenantDetail(TenantInfo);
if not IsNull(TenantInfo) then
CountryCode := TenantInfo.CountryLetterCode();
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Telemetry Custom Dimensions", OnAddCommonCustomDimensions, '', true, true)]
local procedure OnAddCommonCustomDimensions(var Sender: Codeunit "Telemetry Custom Dimensions")
var
Language: Codeunit Language;
begin
GetInformation();

if not IsAzure then
exit;

// Add IsAdmin
Sender.AddCommonCustomDimension('IsAdmin', Language.ToDefaultLanguage(IsAdmin));

// Add CountryCode
if CountryCode <> '' then
Sender.AddCommonCustomDimension('CountryCode', CountryCode);
end;
}
Loading