@uipath/common 1.201.0 → 1.202.0-preview.136

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/catch-error.d.ts +14 -0
  2. package/dist/catch-error.js +259 -10
  3. package/dist/classified-failure.d.ts +28 -0
  4. package/dist/entity-name-rules.d.ts +18 -0
  5. package/dist/entity-name-rules.js +241 -0
  6. package/dist/error-handler.d.ts +13 -0
  7. package/dist/exit-code.d.ts +42 -0
  8. package/dist/formatter.d.ts +34 -5
  9. package/dist/index.browser.d.ts +3 -0
  10. package/dist/index.browser.js +11328 -10486
  11. package/dist/index.d.ts +10 -1
  12. package/dist/index.js +12320 -11208
  13. package/dist/logger.d.ts +15 -0
  14. package/dist/package-metadata-options.js +3 -3
  15. package/dist/polling/poll-failure-mapping.d.ts +15 -1
  16. package/dist/sdk-user-agent.js +6 -6
  17. package/dist/telemetry/command-name.d.ts +60 -0
  18. package/dist/telemetry/console-telemetry-provider.d.ts +5 -6
  19. package/dist/telemetry/debug-telemetry-provider.d.ts +5 -6
  20. package/dist/telemetry/index.d.ts +3 -3
  21. package/dist/telemetry/index.js +18581 -105
  22. package/dist/telemetry/invocation-request.d.ts +38 -0
  23. package/dist/telemetry/logger-telemetry-provider.d.ts +5 -6
  24. package/dist/telemetry/node-appinsights-telemetry-provider.d.ts +17 -29
  25. package/dist/telemetry/node.d.ts +2 -2
  26. package/dist/telemetry/packaged-name.d.ts +22 -0
  27. package/dist/telemetry/pii-redactor.d.ts +110 -13
  28. package/dist/telemetry/pseudonymize.d.ts +57 -0
  29. package/dist/telemetry/span-clock.d.ts +27 -0
  30. package/dist/telemetry/supplied-values.d.ts +59 -0
  31. package/dist/telemetry/telemetry-init.d.ts +27 -0
  32. package/dist/telemetry/telemetry-provider.d.ts +84 -16
  33. package/dist/telemetry/telemetry-service.d.ts +71 -41
  34. package/dist/telemetry/telemetry-spool.d.ts +17 -0
  35. package/dist/timings.d.ts +99 -0
  36. package/dist/trackedAction.d.ts +25 -2
  37. package/package.json +6 -2
@@ -6,39 +6,6 @@ import type { ITelemetryProvider } from "./telemetry-provider.js";
6
6
  export interface TelemetryProperties {
7
7
  [key: string]: string | number | boolean | undefined;
8
8
  }
9
- /**
10
- * Internal property key that carries an active trace context's operation id
11
- * (mirrors {@link TelemetryContext.operationId}). The AppInsights provider reads
12
- * it to set the native `operation_Id` tag, falling back to the per-invocation id
13
- * when no context is present — i.e. for events emitted outside a `trackRequest`
14
- * scope. The provider consumes and strips it, so it never ships as a dimension.
15
- *
16
- * The key lives in the `uip.trace.*` namespace (not the plain `operationId`)
17
- * so it can never be shadowed by a command argument of the same name.
18
- * `extractCommandParams` in `trackedAction.ts` now namespaces args under
19
- * `uip.cmd.arg.*`, but the dedicated trace namespace keeps this control key
20
- * unambiguous and consistent with the rest of the owner-namespaced schema. The
21
- * provider consumes and strips it, so the dotted key never ships as a dimension.
22
- */
23
- export declare const TELEMETRY_OPERATION_ID_PROPERTY = "uip.trace.operation_id";
24
- /**
25
- * Internal routing key carrying an active trace context's parent id (mirrors
26
- * {@link TelemetryContext.parentId}). The AppInsights provider reads it to set
27
- * the native `ai.operation.parentId` tag on request/dependency items, so the
28
- * parent/child tree links in the App Insights UI. Present only inside a nested
29
- * scope (a top-level `trackRequest` has no parent). Consumed and stripped by
30
- * the provider — never ships as a dimension.
31
- */
32
- export declare const TELEMETRY_PARENT_ID_PROPERTY = "uip.trace.parent_id";
33
- /**
34
- * Internal routing key carrying an active trace context's own id (mirrors
35
- * {@link TelemetryContext.id}). The AppInsights provider uses it as the request/
36
- * dependency envelope's native item `id`, so child items whose parent id equals
37
- * it link up; for leaf items (events/exceptions) the provider maps it onto
38
- * `ai.operation.parentId` so the leaf nests under the current operation.
39
- * Consumed and stripped by the provider — never ships as a dimension.
40
- */
41
- export declare const TELEMETRY_SPAN_ID_PROPERTY = "uip.trace.span_id";
42
9
  /**
43
10
  * Telemetry correlation context for tracking parent-child relationships
44
11
  */
@@ -55,6 +22,25 @@ export interface TelemetryContext {
55
22
  * Current operation ID - identifier for this specific operation
56
23
  */
57
24
  id: string;
25
+ /**
26
+ * Wall-clock moment the span began, stamped when the context is created.
27
+ *
28
+ * App Insights reads a request's/dependency's timestamp as the span START
29
+ * and draws the bar forward by `duration`, so this is what decides where a
30
+ * bar lands. Recorded rather than derived at emit time: a span is tracked
31
+ * once its work has finished, and anything between the clock stopping and
32
+ * the emit — `trackedAction` builds and redacts its property bag there —
33
+ * would otherwise be charged to the front of the bar and push it past
34
+ * children that started early.
35
+ *
36
+ * Every context this service builds opens a {@link startSpanClock} at the
37
+ * instant the work does, so the start here and the duration reported
38
+ * alongside it are two views of one clock reading.
39
+ *
40
+ * Optional: a context assembled by hand carries no start, and the provider
41
+ * falls back to deriving one.
42
+ */
43
+ startedAt?: Date;
58
44
  }
59
45
  /**
60
46
  * Interface for tracking telemetry events.
@@ -111,10 +97,15 @@ export interface ITelemetryService {
111
97
  * @param error - The error to track
112
98
  * @param properties - Optional properties to attach to the exception
113
99
  *
100
+ * @param context - The span to hang the exception under. Defaults to
101
+ * whatever scope is active; pass one explicitly from a caller that runs
102
+ * after its scope has closed, or the row groups by type but links to no
103
+ * request.
104
+ *
114
105
  * @remarks
115
106
  * If called within a trackRequest block, automatically includes operationId for correlation.
116
107
  */
117
- trackException(error: Error, properties?: TelemetryProperties): void;
108
+ trackException(error: Error, properties?: TelemetryProperties, context?: TelemetryContext): void;
118
109
  /**
119
110
  * Track a request operation (top-level operation in the dependency tree).
120
111
  * Use this for main entry point.
@@ -163,6 +154,16 @@ export interface ITelemetryService {
163
154
  * it. Returns the function's result.
164
155
  */
165
156
  runWithContext<T>(context: TelemetryContext, fn: () => Promise<T>): Promise<T>;
157
+ /**
158
+ * The context active in the async storage right now, or `undefined` outside
159
+ * any scope.
160
+ *
161
+ * The async storage is the only per-invocation place a context can live, so
162
+ * a caller that has to tell "this invocation's scope" from "some other
163
+ * invocation's" asks here rather than reading a process-wide slot — see
164
+ * `invocation-request.ts`.
165
+ */
166
+ getActiveContext(): TelemetryContext | undefined;
166
167
  /**
167
168
  * Build a dependency context (child of the currently active context) without
168
169
  * emitting anything, or `undefined` when there is no active request scope.
@@ -225,7 +226,7 @@ export declare class TelemetryService implements ITelemetryService {
225
226
  setProvider(provider: ITelemetryProvider): void;
226
227
  setDefaultProperties(properties?: TelemetryProperties): void;
227
228
  trackEvent(name: string, properties?: TelemetryProperties): void;
228
- trackException(error: Error, properties?: TelemetryProperties): void;
229
+ trackException(error: Error, properties?: TelemetryProperties, context?: TelemetryContext): void;
229
230
  trackRequest<T>(name: string, fn: () => Promise<T>, properties?: TelemetryProperties): Promise<T>;
230
231
  trackRequestResult(name: string, durationMs: number, success: boolean, properties?: TelemetryProperties, context?: TelemetryContext): void;
231
232
  createRequestContext(): TelemetryContext;
@@ -247,20 +248,49 @@ export declare class TelemetryService implements ITelemetryService {
247
248
  * Gets the current telemetry context from the context storage.
248
249
  * Returns undefined if no context is available (not within a trackRequest block).
249
250
  */
250
- private getCurrentContext;
251
+ getActiveContext(): TelemetryContext | undefined;
252
+ /**
253
+ * Where a leaf item (event, exception) sits in the trace.
254
+ *
255
+ * A leaf marks an instant, so it has no span id of its own and nothing
256
+ * points at it: it hangs under whichever span was open when it was emitted,
257
+ * which is why `parentId` is that span's OWN id rather than the span's
258
+ * parent. Outside any scope there is no parent, and `operationId` falls
259
+ * back to the per-invocation id so the item still groups with the rest of
260
+ * the run.
261
+ *
262
+ * A caller that emits after its scope has closed — `trackedAction` ships its
263
+ * internal-error exception once the invocation scope is gone — passes the
264
+ * span explicitly, or the item lands with no `parentId` and shows up in
265
+ * Transaction Search attached to nothing.
266
+ */
267
+ private leafCorrelation;
268
+ /**
269
+ * Assemble a finished span for a provider.
270
+ *
271
+ * Correlation comes off the context as fields on the span, never as keys
272
+ * inside `properties` — same rule {@link leafCorrelation} follows for
273
+ * events and exceptions. No tracked item ships a correlation id as a
274
+ * custom dimension.
275
+ */
276
+ private spanFor;
251
277
  /**
252
- * Enriches properties with the shared base properties, this service's
253
- * default properties, and context information (operationId, parentId, id).
278
+ * Merge the shared base properties, this service's defaults, and the
279
+ * per-call bag into the custom dimensions an item ships.
254
280
  *
255
281
  * The global base properties (app version, detected agent, authenticated
256
282
  * user/tenant/org) are merged here — at the service level — rather than
257
- * inside a specific provider, so EVERY event carries them regardless of
283
+ * inside a specific provider, so EVERY item carries them regardless of
258
284
  * which provider is active (AppInsights, logger fallback, or a tool
259
285
  * bundle's early local instance). Precedence, lowest to highest: detected
260
286
  * execution context → global base props → per-service defaults →
261
- * per-call props → correlation context.
287
+ * per-call props → the session source.
288
+ *
289
+ * Correlation is deliberately absent: it travels on the tracked item
290
+ * itself ({@link spanFor}, {@link leafCorrelation}), so no id can leak
291
+ * into a dimension and no provider has to strip one back out.
262
292
  */
263
- private enrichPropertiesWithContext;
293
+ private enrichProperties;
264
294
  /**
265
295
  * Generate a span id for telemetry correlation.
266
296
  *
@@ -33,6 +33,23 @@ export declare function getTelemetrySpoolDir(): string;
33
33
  * Persist pending envelopes for the sidecar. Writes to a `.tmp` name first
34
34
  * and renames into place so a concurrently-running sender never claims a
35
35
  * half-written file. Returns the spool file path.
36
+ *
37
+ * A spool file is written at the default umask, so on a multi-account machine
38
+ * every other account can read it: 0644 in an 0755 directory, holding whole
39
+ * telemetry envelopes — session id, install id, the command's arguments, error
40
+ * messages — for up to {@link MAX_SPOOL_AGE_MS}.
41
+ *
42
+ * Narrowing it needs a way to set POSIX bits, and `IFileSystem` deliberately has
43
+ * none: it is the bottom layer under every package, and permission semantics for
44
+ * one caller do not belong in its contract. Passing a `mode` through
45
+ * `mkdir`/`writeFile` would not have been enough on its own either — those apply
46
+ * it only when the call CREATES the target, and every machine that has ever run
47
+ * the CLI already has this directory.
48
+ *
49
+ * So the exposure is accepted rather than half-closed. Note it is READ only:
50
+ * 0755 is `rwxr-xr-x`, so another account can read the spool but not write to
51
+ * it, and planting a file to steer the sender needs write access — see
52
+ * `isPostableEndpoint` in the drain, which does not rely on these bits.
36
53
  */
37
54
  export declare function writeTelemetrySpoolFile(payload: TelemetrySpoolPayload): Promise<string>;
38
55
  /**
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Opt-in per-invocation timing report, switched on with `UIP_TIMINGS=1`.
3
+ *
4
+ * [timing] 'uip or assets list' exit=0 total=1250ms startup=380ms command=863ms http=691ms httpCalls=3 flush=7ms
5
+ *
6
+ * Nothing new is measured — the CLI already read every one of these clocks for
7
+ * telemetry. `startup` (up to the handler), `command` (the handler) and `flush`
8
+ * (telemetry teardown after it) tile `total` exactly. `http`/`httpCalls` are a
9
+ * sum inside `command`, not a fourth slice, so parallel calls can push `http`
10
+ * past `command`.
11
+ *
12
+ * State is reached through `Symbol.for()` slots (each tool bundles its own copy
13
+ * of this package) and bound to the invocation's async context, so the MCP
14
+ * bridge's concurrent in-process commands can't overwrite each other's numbers.
15
+ * Where there is no async context to bind to (the browser bundle shims
16
+ * `node:async_hooks` away), the invocation pins the shared slot instead — that
17
+ * host runs one command at a time.
18
+ */
19
+ /** Environment variable that turns the report on (`1` or `true`). */
20
+ export declare const TIMINGS_ENV_VAR = "UIP_TIMINGS";
21
+ /** Prefix every report line carries, so a pipeline can grep them out. */
22
+ export declare const TIMINGS_LINE_PREFIX = "[timing]";
23
+ /**
24
+ * Declare that this process outlives the invocations it runs, so no invocation
25
+ * is counted from process start.
26
+ *
27
+ * Called by the browser entry point, which runs a command per page action. A
28
+ * one-shot `uip` says nothing and keeps charging its first (only) invocation
29
+ * for startup, which is the part the user waited through.
30
+ */
31
+ export declare function markLongLivedHost(): void;
32
+ /**
33
+ * Run one CLI invocation with its own timing state and report on the way out.
34
+ *
35
+ * Wraps the whole invocation, so paths that give up before a command resolves
36
+ * (rejected `--output-filter`, `--output`/`--json` conflict) still report.
37
+ * Callers name the command via {@link setTimingCommand} once parsing resolves
38
+ * it, and {@link suppressTimingReport} on a path that re-execs elsewhere.
39
+ * No-op when `UIP_TIMINGS` is unset.
40
+ */
41
+ export declare function runWithTimings<T>(fallbackCommand: string, fn: () => Promise<T>): Promise<T>;
42
+ /** Only `1` and `true` count, matching how the logger reads `DEBUG`. */
43
+ export declare function timingsEnabled(): boolean;
44
+ /** Name the command being timed, once the parser has resolved it. */
45
+ export declare function setTimingCommand(command: string): void;
46
+ /**
47
+ * Record this invocation's exit code. Read from here rather than
48
+ * `process.exitCode`, which a long-lived host shares between commands and
49
+ * whose own `exit` may throw instead of setting it.
50
+ */
51
+ export declare function recordExitCode(exitCode: number): void;
52
+ /** Skip this invocation's report — a re-exec child reports the run instead. */
53
+ export declare function suppressTimingReport(): void;
54
+ /**
55
+ * Wall-clock moment this invocation began — the CLI entry point, before argv is
56
+ * parsed, tools are resolved and loaded, or a handler is reached.
57
+ *
58
+ * The command's telemetry request span is the whole invocation, so this is
59
+ * where its bar starts. `trackedAction` cannot supply it: by the time a
60
+ * Commander action runs, startup has already happened and is exactly the part
61
+ * that used to go unmeasured.
62
+ *
63
+ * `baseline` is in `performance.now()` units and `performance.timeOrigin` is
64
+ * the wall clock at process start, so the two add up to the real start — 0 for
65
+ * a one-shot CLI, and the invocation's own offset in a long-lived host (the MCP
66
+ * bridge), where process start is not command start.
67
+ */
68
+ export declare function invocationStartedAt(): Date;
69
+ /**
70
+ * How long this invocation has been running, for the request span's duration.
71
+ * Read at emit time — see {@link invocationStartedAt}.
72
+ */
73
+ export declare function invocationElapsedMs(): number;
74
+ /** Called by `trackedAction` when the command handler starts. */
75
+ export declare function markCommandStart(): void;
76
+ /** Called by `trackedAction` with the handler's duration. */
77
+ export declare function recordCommandDuration(durationMs: number): void;
78
+ /** Called by the tracked fetch for each outbound call. */
79
+ export declare function recordHttpCall(durationMs: number): void;
80
+ /** Drop everything recorded so far. Intended for tests. */
81
+ export declare function resetTimings(): void;
82
+ /**
83
+ * Build the report line — every value under a `name=` label, so nothing has to
84
+ * be read by position. Exported for tests; callers use {@link runWithTimings}.
85
+ *
86
+ * The whole split, `http` included, is dropped when no handler ran (`--help`,
87
+ * `--version`, unknown command, rejected option): there is nothing to
88
+ * attribute the time to, and a lone `http` from a startup call would imply
89
+ * otherwise. `exit` and `total` are always present.
90
+ */
91
+ export declare function formatTimingReport(args: {
92
+ command: string;
93
+ exitCode: number;
94
+ totalMs: number;
95
+ startupMs?: number;
96
+ commandMs?: number;
97
+ httpMs: number;
98
+ httpCalls: number;
99
+ }): string;
@@ -21,8 +21,8 @@ export interface CommandContext {
21
21
  */
22
22
  export declare const TELEMETRY_COMMAND_ARG_PREFIX = "uip.cmd.arg.";
23
23
  /**
24
- * Default CommandContext for tool packages that sets process.exitCode
25
- * instead of calling process.exit().
24
+ * Default CommandContext for tool packages: records the exit code and lets the
25
+ * handler return, instead of calling process.exit().
26
26
  *
27
27
  * `pollSignal` is resolved from globalThis so it works across bundle
28
28
  * boundaries — the CLI sets it once, all tool bundles see the same signal.
@@ -35,6 +35,29 @@ export declare const processContext: CommandContext;
35
35
  * Call once at CLI startup after creating the poll abort controller.
36
36
  */
37
37
  export declare function setProcessContextPollSignal(signal: AbortSignal): void;
38
+ /**
39
+ * Recorded in place of an argument's value when the value itself is not safe to
40
+ * collect. That the user passed `--body` at all is the analytics signal; what
41
+ * was in it never was.
42
+ */
43
+ export declare const TELEMETRY_ARG_VALUE_WITHHELD = "<provided>";
44
+ /**
45
+ * Recorded in place of an option's value when the option was never passed and
46
+ * Commander filled in the command's own default.
47
+ *
48
+ * Distinct from {@link TELEMETRY_ARG_VALUE_WITHHELD} because it answers the
49
+ * opposite question. `<provided>` means the user supplied a value we refuse to
50
+ * collect; a default means they supplied nothing at all. Reporting both as
51
+ * `<provided>` made "which options are used, how often" — the whole reason the
52
+ * dimension exists — unanswerable, since `uip or folders list` with no
53
+ * arguments still claimed `--limit` and `--offset` were provided.
54
+ *
55
+ * The default's own literal is not reported in its place: a default is usually a
56
+ * constant in our source, but not always (a path derived from the working
57
+ * directory, a resolved home), and a dimension that is a value most of the time
58
+ * is worse than one that is never a value.
59
+ */
60
+ export declare const TELEMETRY_ARG_VALUE_DEFAULTED = "<default>";
38
61
  /**
39
62
  * Derives a telemetry event name from the command hierarchy.
40
63
  * Walks up the parent chain, collects command names, strips the root,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uipath/common",
3
3
  "license": "MIT",
4
- "version": "1.201.0",
4
+ "version": "1.202.0-preview.136",
5
5
  "description": "Common infrastructure needed by uip tools.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -28,6 +28,10 @@
28
28
  "types": "./dist/catch-error.d.ts",
29
29
  "default": "./dist/catch-error.js"
30
30
  },
31
+ "./entity-name-rules": {
32
+ "types": "./dist/entity-name-rules.d.ts",
33
+ "default": "./dist/entity-name-rules.js"
34
+ },
31
35
  "./guid": {
32
36
  "types": "./dist/guid.d.ts",
33
37
  "default": "./dist/guid.js"
@@ -71,5 +75,5 @@
71
75
  "mihaigirleanu",
72
76
  "vlad-uipath"
73
77
  ],
74
- "gitHead": "7933378ad5276ac369900293a1447474dcec6826"
78
+ "gitHead": "f6270de2c7c04f4c43b2f5187b0c3d3c314c2610"
75
79
  }