Skip to content

Commit 0902cc5

Browse files
feat(telemetry): report CloudUserId on telemetry events from the auth token (#497)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b300fb8 commit 0902cc5

17 files changed

Lines changed: 310 additions & 19 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
"test:coverage": "vitest --coverage"
227227
},
228228
"dependencies": {
229-
"@uipath/core-telemetry": "^1.0.0-beta.2",
229+
"@uipath/core-telemetry": "^1.0.0-beta.3",
230230
"socket.io-client": "^4.8.1"
231231
},
232232
"peerDependencies": {

packages/coded-action-app/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/coded-action-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uipath/coded-action-app",
3-
"version": "1.0.0-beta.1",
3+
"version": "1.0.0-beta.2",
44
"description": "UiPath package to be used for viewing coded action apps in Action Center",
55
"license": "MIT",
66
"type": "module",
@@ -32,7 +32,7 @@
3232
"lint": "oxlint"
3333
},
3434
"dependencies": {
35-
"@uipath/core-telemetry": "^1.0.0-beta.2"
35+
"@uipath/core-telemetry": "^1.0.0-beta.3"
3636
},
3737
"devDependencies": {
3838
"@rollup/plugin-commonjs": "^25.0.0",

packages/coded-action-app/src/coded-action-app-service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import {
44
TaskCompleteResponse,
55
} from './types';
66
import { CodedActionAppServiceModel } from './coded-action-app.models';
7-
import { ActionCenterEventNames, ActionCenterEventResponsePayload } from './types.internal';
7+
import {
8+
ActionCenterEventNames,
9+
ActionCenterEventResponsePayload,
10+
TaskWithCloudUserId,
11+
} from './types.internal';
812
import { telemetryClient, track } from './telemetry';
913
import { loadFromMetaTags } from './telemetry/runtime';
1014

@@ -18,7 +22,12 @@ export class CodedActionAppService implements CodedActionAppServiceModel {
1822
private isCompletingTask = false;
1923

2024
constructor() {
21-
telemetryClient.initialize(loadFromMetaTags() ?? undefined);
25+
const metaConfig = loadFromMetaTags();
26+
telemetryClient.initialize(
27+
metaConfig
28+
? { ...metaConfig, orgId: metaConfig.orgName, tenantId: metaConfig.tenantName }
29+
: undefined,
30+
);
2231
}
2332

2433
/**
@@ -111,7 +120,10 @@ export class CodedActionAppService implements CodedActionAppServiceModel {
111120
clearTimeout(timer);
112121

113122
this.cleanup(messageListener);
114-
resolve(event.data?.content as Task);
123+
124+
const task = event.data?.content as TaskWithCloudUserId;
125+
telemetryClient.setUserId(task?.cloudUserId ?? '');
126+
resolve(task);
115127
};
116128

117129
const timer = setTimeout(() => {

packages/coded-action-app/src/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export const SDK_SERVICE_NAME = 'UiPath.CodedActionApp.Sdk';
1111
export const CLOUD_ROLE_NAME = 'uipath-coded-action-app-sdk';
1212
export const SDK_LOGGER_NAME = 'uipath-coded-action-app-telemetry';
1313
export const SDK_RUN_EVENT = 'CodedActionApp.Sdk.Run';
14+
export const TS_SDK_CLOUD_ROLE_NAME = 'uipath-ts-sdk';

packages/coded-action-app/src/telemetry/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
SDK_RUN_EVENT,
2121
SDK_SERVICE_NAME,
2222
SDK_VERSION,
23+
TS_SDK_CLOUD_ROLE_NAME,
2324
} from './constants';
2425

2526
/** Keyed by `CLOUD_ROLE_NAME` so all CodedActionApp SDK module loads share a single `TelemetryClient`. Each SDK uses
@@ -41,4 +42,13 @@ export const telemetryClient = {
4142
context,
4243
});
4344
},
45+
46+
/**
47+
* Sets the authenticated user's id so completeTask event and all ts-sdk api calls
48+
* carry it as `CloudUserId`.
49+
*/
50+
setUserId(userId: string): void {
51+
codedActionAppTelemetryClient.setUserId(userId);
52+
getOrCreateClient(TS_SDK_CLOUD_ROLE_NAME).setUserId(userId);
53+
},
4454
};

packages/coded-action-app/src/types.internal.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ export enum ActionCenterEventNames {
1010
COMPLETERESPONSE = 'AC.completeResponse',
1111
}
1212

13+
/**
14+
* Task content as delivered by Action Center on the `LOADAPP` event. Carries
15+
* the hidden `cloudUserId` that is reported as `CloudUserId` on telemetry
16+
* events but is intentionally absent from the public {@link Task} contract.
17+
*/
18+
export type TaskWithCloudUserId = Task & { cloudUserId?: string };
19+
1320
export type ActionCenterEventResponsePayload = {
1421
eventType: ActionCenterEventNames;
15-
content: Task | TaskCompleteResponse;
22+
content: TaskWithCloudUserId | TaskCompleteResponse;
1623
};

src/core/auth/token-manager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { AuthenticationError, HttpStatus } from '../errors';
88
import { ActionCenterTokenManager } from './action-center-token-manager';
99
import { EmbeddedTokenManager } from './embedded-token-manager';
1010
import { isValidHostOrigin } from './host-token-request';
11+
import { telemetryClient } from '../telemetry';
12+
import { extractUserIdFromToken } from '../../utils/encoding';
1113

1214
/**
1315
* TokenManager is responsible for managing authentication tokens.
@@ -269,6 +271,7 @@ export class TokenManager {
269271
*/
270272
private _updateExecutionContext(tokenInfo: TokenInfo): void {
271273
this.executionContext.set('tokenInfo', tokenInfo);
274+
telemetryClient.setUserId(extractUserIdFromToken(tokenInfo.token));
272275
}
273276

274277
/**

src/core/telemetry/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ export const telemetryClient = {
4242
context,
4343
});
4444
},
45+
46+
/**
47+
* Sets the authenticated user's id so every subsequently emitted event
48+
* carries it as `CloudUserId`.
49+
*/
50+
setUserId(userId: string): void {
51+
sdkClient.setUserId(userId);
52+
},
4553
};

0 commit comments

Comments
 (0)