Skip to content

Commit

Permalink
feat: Add utruncated user id to telemetry events (#5742)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
tdurnford and cwhitten authored Feb 10, 2021
1 parent 03d5717 commit 8cde5d7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Composer/packages/server/src/services/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (instrumentationKey) {
// do not collect the user's machine name
AppInsights.defaultClient.context.tags[AppInsights.defaultClient.context.keys.cloudRoleInstance] = '';
AppInsights.defaultClient.addTelemetryProcessor((envelope: AppInsights.Contracts.Envelope, context): boolean => {
const { sessionId, telemetry, composerVersion } = getTelemetryContext();
const { sessionId, telemetry, composerVersion, userId } = getTelemetryContext();

if (!telemetry?.allowDataCollection) {
return false;
Expand All @@ -49,6 +49,9 @@ if (instrumentationKey) {
// Add session id
envelope.tags[AppInsights.defaultClient.context.keys.sessionId] = sessionId;

// Add truncated user id
envelope.tags[AppInsights.defaultClient.context.keys.userId] = userId?.slice(0, Math.floor(userId.length * 0.8));

// Remove PII from url
if (envelope.data.baseType === 'RequestData' && data.baseData.url.match(/\/\d+.\d+/i)) {
if (typeof data.baseData.url === 'string') {
Expand Down

0 comments on commit 8cde5d7

Please sign in to comment.