Skip to content
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
2 changes: 2 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,8 @@ const CONST = {
TAG_ACTIVE_POLICY: 'active_policy_id',
TAG_POLICIES_COUNT: 'policies_count',
TAG_REPORTS_COUNT: 'reports_count',
TAG_PERSONAL_DETAILS_COUNT: 'personal_details_count',
TAG_USER_ROLE: 'user_role',
TAG_NUDGE_MIGRATION_COHORT: 'nudge_migration_cohort',
TAG_AUTHENTICATION_FUNCTION: 'authentication_function',
TAG_AUTHENTICATION_ERROR_TYPE: 'authentication_error_type',
Expand Down
28 changes: 28 additions & 0 deletions src/libs/telemetry/TelemetrySynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ Onyx.connectWithoutView({
},
});

Onyx.connectWithoutView({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (!value) {
return;
}
sendPersonalDetailsCountTag(Object.keys(value).length);
},
});

Onyx.connectWithoutView({
key: ONYXKEYS.NVP_TRY_NEW_DOT,
callback: (value) => {
Expand Down Expand Up @@ -131,9 +141,22 @@ function sendPoliciesContext() {
return;
}
const activePolicies = getActivePolicies(policies, session.email).map((policy) => policy.id);

let userRole: string = CONST.POLICY.ROLE.USER;
for (const policy of Object.values(policies)) {
if (policy?.role === CONST.POLICY.ROLE.ADMIN) {
userRole = CONST.POLICY.ROLE.ADMIN;
break;
}
if (policy?.role === CONST.POLICY.ROLE.AUDITOR) {
userRole = CONST.POLICY.ROLE.AUDITOR;
}
}

const policiesCountBucket = bucketPolicyCount(activePolicies.length);
Sentry.setTag(CONST.TELEMETRY.TAG_ACTIVE_POLICY, activePolicyID);
Sentry.setTag(CONST.TELEMETRY.TAG_POLICIES_COUNT, policiesCountBucket);
Sentry.setTag(CONST.TELEMETRY.TAG_USER_ROLE, userRole);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate new telemetry tags to child spans

Adding Sentry.setTag for user_role/personal_details_count here does not make those tags searchable on spans, because copyTagsToChildSpans only forwards a fixed whitelist and rewrites child span tags. In practice, transactions may carry the new tags but child spans will not, so filtering span data by these new segmentation tags will fail until the span-tag propagation list is updated.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed change

Sentry.setContext(CONST.TELEMETRY.CONTEXT_POLICIES, {activePolicyID, activePolicies});
}

Expand All @@ -150,4 +173,9 @@ function sendReportsCountTag(reportsCount: number) {
Sentry.setTag(CONST.TELEMETRY.TAG_REPORTS_COUNT, reportsCountBucket);
}

function sendPersonalDetailsCountTag(personalDetailsCount: number) {
const personalDetailsCountBucket = bucketReportCount(personalDetailsCount);
Sentry.setTag(CONST.TELEMETRY.TAG_PERSONAL_DETAILS_COUNT, personalDetailsCountBucket);
}

export {initializeMemoryTracking as initializeMemoryTrackingTelemetry, cleanupMemoryTracking as cleanupMemoryTrackingTelemetry};
9 changes: 8 additions & 1 deletion src/libs/telemetry/middlewares/copyTagsToChildSpans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import type {TelemetryBeforeSend} from './index';
/**
* List of tags that should be copied from the transaction to all child spans
*/
const TAGS_TO_COPY = [CONST.TELEMETRY.TAG_POLICIES_COUNT, CONST.TELEMETRY.TAG_REPORTS_COUNT, CONST.TELEMETRY.TAG_ACTIVE_POLICY, CONST.TELEMETRY.TAG_NUDGE_MIGRATION_COHORT] as const;
const TAGS_TO_COPY = [
CONST.TELEMETRY.TAG_POLICIES_COUNT,
CONST.TELEMETRY.TAG_REPORTS_COUNT,
CONST.TELEMETRY.TAG_ACTIVE_POLICY,
CONST.TELEMETRY.TAG_NUDGE_MIGRATION_COHORT,
CONST.TELEMETRY.TAG_USER_ROLE,
CONST.TELEMETRY.TAG_PERSONAL_DETAILS_COUNT,
] as const;

/**
* Middleware that copies specific tags from the transaction event to all child spans.
Expand Down
Loading