@uipath/common 1.199.0-preview.92 → 1.199.0-preview.99

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.
package/dist/index.js CHANGED
@@ -9450,11 +9450,36 @@ class NodeContextStorage {
9450
9450
  return this.storage.getStore();
9451
9451
  }
9452
9452
  }
9453
+ // src/telemetry/trace-context.ts
9454
+ var TELEMETRY_TRACEPARENT_ENV = "TRACEPARENT";
9455
+ var TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
9456
+ function getProcessEnv() {
9457
+ return globalThis.process?.env;
9458
+ }
9459
+ function parseInboundTraceparent(value) {
9460
+ if (!value) {
9461
+ return;
9462
+ }
9463
+ const match = TRACEPARENT_PATTERN.exec(value.trim().toLowerCase());
9464
+ if (!match) {
9465
+ return;
9466
+ }
9467
+ const [, traceId, parentSpanId] = match;
9468
+ if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId)) {
9469
+ return;
9470
+ }
9471
+ return { traceId, parentSpanId };
9472
+ }
9473
+ function getInboundTraceContext() {
9474
+ return parseInboundTraceparent(getProcessEnv()?.[TELEMETRY_TRACEPARENT_ENV]);
9475
+ }
9476
+
9453
9477
  // src/telemetry/session-id.ts
9454
9478
  var TELEMETRY_SESSION_ID_ENV = "UIPATH_SESSION_ID";
9455
9479
  var TELEMETRY_SESSION_ID_PROPERTY = "session_id";
9456
9480
  var telemetrySessionIdSlot = singleton("TelemetrySessionId");
9457
- function getProcessEnv() {
9481
+ var telemetryOperationIdSlot = singleton("TelemetryOperationId");
9482
+ function getProcessEnv2() {
9458
9483
  return globalThis.process?.env;
9459
9484
  }
9460
9485
  function normalizeSessionId(value) {
@@ -9465,7 +9490,7 @@ function normalizeSessionId(value) {
9465
9490
  return trimmed || undefined;
9466
9491
  }
9467
9492
  function getConfiguredTelemetrySessionId() {
9468
- return normalizeSessionId(getProcessEnv()?.[TELEMETRY_SESSION_ID_ENV]);
9493
+ return normalizeSessionId(getProcessEnv2()?.[TELEMETRY_SESSION_ID_ENV]);
9469
9494
  }
9470
9495
  function getTelemetrySessionId() {
9471
9496
  const envSessionId = getConfiguredTelemetrySessionId();
@@ -9483,6 +9508,16 @@ function getTelemetrySessionId() {
9483
9508
  function resolveTelemetrySessionId(existingSessionId) {
9484
9509
  return getConfiguredTelemetrySessionId() ?? normalizeSessionId(existingSessionId);
9485
9510
  }
9511
+ function getTelemetryOperationId() {
9512
+ const existing = telemetryOperationIdSlot.get();
9513
+ if (existing) {
9514
+ return existing;
9515
+ }
9516
+ const inboundTraceId = getInboundTraceContext()?.traceId;
9517
+ const generated = inboundTraceId ?? crypto.randomUUID().replaceAll("-", "");
9518
+ telemetryOperationIdSlot.set(generated);
9519
+ return generated;
9520
+ }
9486
9521
  // src/telemetry/global-telemetry-properties.ts
9487
9522
  var telemetryPropsSlot = singleton("TelemetryDefaultProps");
9488
9523
  function setGlobalTelemetryProperties(properties) {
@@ -9493,7 +9528,144 @@ function getGlobalTelemetryProperties() {
9493
9528
  return telemetryPropsSlot.get();
9494
9529
  }
9495
9530
 
9531
+ // src/telemetry/pii-redactor.ts
9532
+ var REDACTED = "[REDACTED]";
9533
+ var MAX_VALUE_LENGTH = 200;
9534
+ var SENSITIVE_NAME_TOKENS = new Set([
9535
+ "token",
9536
+ "tokens",
9537
+ "secret",
9538
+ "secrets",
9539
+ "password",
9540
+ "passwords",
9541
+ "pwd",
9542
+ "credential",
9543
+ "credentials",
9544
+ "auth",
9545
+ "authentication",
9546
+ "authorization",
9547
+ "authority",
9548
+ "cert",
9549
+ "certificate",
9550
+ "certificates"
9551
+ ]);
9552
+ var SENSITIVE_KEY_PREFIXES = new Set([
9553
+ "api",
9554
+ "access",
9555
+ "client",
9556
+ "private",
9557
+ "public",
9558
+ "signing",
9559
+ "encryption",
9560
+ "session",
9561
+ "master",
9562
+ "shared",
9563
+ "root",
9564
+ "ssh",
9565
+ "rsa",
9566
+ "aes",
9567
+ "hmac",
9568
+ "oauth"
9569
+ ]);
9570
+ var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
9571
+ var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
9572
+ var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
9573
+ var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
9574
+ var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
9575
+ var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
9576
+ var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
9577
+ function shortHash(input) {
9578
+ let hash = 2166136261;
9579
+ for (let i = 0;i < input.length; i++) {
9580
+ hash ^= input.charCodeAt(i);
9581
+ hash = Math.imul(hash, 16777619);
9582
+ }
9583
+ return (hash >>> 0).toString(16).padStart(8, "0");
9584
+ }
9585
+ function redactUrl(raw) {
9586
+ try {
9587
+ const url = new URL(raw);
9588
+ return `${url.protocol}//${url.host}`;
9589
+ } catch {
9590
+ return `url#${shortHash(raw)}`;
9591
+ }
9592
+ }
9593
+ function redactValueDetectors(value) {
9594
+ let out = value;
9595
+ out = out.replace(JWT_PATTERN, () => REDACTED);
9596
+ out = out.replace(URL_PATTERN, (match) => {
9597
+ const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
9598
+ const core2 = trailing ? match.slice(0, -trailing.length) : match;
9599
+ return `${redactUrl(core2)}${trailing}`;
9600
+ });
9601
+ out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
9602
+ out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
9603
+ out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
9604
+ out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
9605
+ if (out.length > MAX_VALUE_LENGTH) {
9606
+ out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
9607
+ }
9608
+ return out;
9609
+ }
9610
+ function redactValue(value) {
9611
+ return redactValueDetectors(value);
9612
+ }
9613
+ function redactError(error) {
9614
+ const safe = new Error(redactValueDetectors(error.message ?? ""));
9615
+ safe.name = error.name;
9616
+ safe.stack = typeof error.stack === "string" ? redactValueDetectors(error.stack) : undefined;
9617
+ return safe;
9618
+ }
9619
+ function nameTokens(name) {
9620
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s._-]+/).map((t) => t.toLowerCase()).filter(Boolean);
9621
+ }
9622
+ function isSensitiveName(name) {
9623
+ const tokens = nameTokens(name);
9624
+ for (let i = 0;i < tokens.length; i++) {
9625
+ const token = tokens[i];
9626
+ if (SENSITIVE_NAME_TOKENS.has(token)) {
9627
+ return true;
9628
+ }
9629
+ if (token === "key" || token === "keys") {
9630
+ const prev = tokens[i - 1];
9631
+ if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
9632
+ return true;
9633
+ }
9634
+ }
9635
+ }
9636
+ return false;
9637
+ }
9638
+ function redactProperty(name, value) {
9639
+ if (value === undefined || value === null) {
9640
+ return;
9641
+ }
9642
+ if (isSensitiveName(name)) {
9643
+ return REDACTED;
9644
+ }
9645
+ if (typeof value === "boolean" || typeof value === "number") {
9646
+ return value;
9647
+ }
9648
+ if (typeof value !== "string") {
9649
+ return "[OBJECT]";
9650
+ }
9651
+ return redactValueDetectors(value);
9652
+ }
9653
+ function redactProperties(properties) {
9654
+ const out = {};
9655
+ for (const [name, value] of Object.entries(properties)) {
9656
+ const redacted = redactProperty(name, value);
9657
+ if (redacted !== undefined) {
9658
+ out[name] = redacted;
9659
+ }
9660
+ }
9661
+ return out;
9662
+ }
9663
+
9496
9664
  // src/telemetry/telemetry-service.ts
9665
+ var TELEMETRY_OPERATION_ID_PROPERTY = "uip.trace.operation_id";
9666
+ var TELEMETRY_PARENT_ID_PROPERTY = "uip.trace.parent_id";
9667
+ var TELEMETRY_SPAN_ID_PROPERTY = "uip.trace.span_id";
9668
+
9497
9669
  class TelemetryService {
9498
9670
  telemetryProvider;
9499
9671
  contextStorage;
@@ -9520,11 +9692,15 @@ class TelemetryService {
9520
9692
  trackException(error, properties) {
9521
9693
  const context = this.getCurrentContext();
9522
9694
  const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
9523
- this.telemetryProvider.trackException(error, enrichedProperties);
9695
+ this.telemetryProvider.trackException(redactError(error), enrichedProperties);
9524
9696
  }
9525
9697
  async trackRequest(name, fn, properties) {
9698
+ const parentContext = this.getCurrentContext();
9699
+ const operationId = parentContext?.operationId ?? this.operationId ?? getTelemetryOperationId();
9700
+ const parentId = parentContext ? parentContext.id : this.inboundParentIdFor(operationId);
9526
9701
  const context = {
9527
- operationId: this.operationId ?? this.generateId(),
9702
+ operationId,
9703
+ ...parentId !== undefined ? { parentId } : {},
9528
9704
  id: this.generateId()
9529
9705
  };
9530
9706
  const startTime = performance.now();
@@ -9542,6 +9718,45 @@ class TelemetryService {
9542
9718
  throw error;
9543
9719
  }
9544
9720
  }
9721
+ trackRequestResult(name, durationMs, success, properties, context) {
9722
+ const requestContext = context ?? {
9723
+ operationId: this.operationId ?? getTelemetryOperationId(),
9724
+ id: this.generateId()
9725
+ };
9726
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, requestContext);
9727
+ this.telemetryProvider.trackRequest(name, durationMs, success, enrichedProperties);
9728
+ }
9729
+ createRequestContext() {
9730
+ const operationId = this.operationId ?? getTelemetryOperationId();
9731
+ const parentId = this.inboundParentIdFor(operationId);
9732
+ return {
9733
+ operationId,
9734
+ ...parentId !== undefined ? { parentId } : {},
9735
+ id: this.generateId()
9736
+ };
9737
+ }
9738
+ inboundParentIdFor(operationId) {
9739
+ const inbound = getInboundTraceContext();
9740
+ return inbound && inbound.traceId === operationId ? inbound.parentSpanId : undefined;
9741
+ }
9742
+ runWithContext(context, fn) {
9743
+ return this.contextStorage.run(context, fn);
9744
+ }
9745
+ createDependencyContext() {
9746
+ const parentContext = this.getCurrentContext();
9747
+ if (!parentContext) {
9748
+ return;
9749
+ }
9750
+ return {
9751
+ operationId: parentContext.operationId,
9752
+ parentId: parentContext.id,
9753
+ id: this.generateId()
9754
+ };
9755
+ }
9756
+ trackDependencyResult(name, type2, durationMs, success, properties, context, resultCode) {
9757
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
9758
+ this.telemetryProvider.trackDependency(redactValue(name), type2, durationMs, success, enrichedProperties, resultCode);
9759
+ }
9545
9760
  async trackDependencyOperation(name, type2, fn, properties) {
9546
9761
  const parentContext = this.getCurrentContext();
9547
9762
  if (!parentContext) {
@@ -9578,8 +9793,12 @@ class TelemetryService {
9578
9793
  ...getExecutionContextTelemetryProperties(),
9579
9794
  ...globalProperties,
9580
9795
  ...this.defaultProperties,
9581
- ...properties,
9582
- ...context
9796
+ ...redactProperties(properties ?? {}),
9797
+ ...context ? {
9798
+ [TELEMETRY_OPERATION_ID_PROPERTY]: context.operationId,
9799
+ ...context.parentId !== undefined ? { [TELEMETRY_PARENT_ID_PROPERTY]: context.parentId } : {},
9800
+ [TELEMETRY_SPAN_ID_PROPERTY]: context.id
9801
+ } : {}
9583
9802
  };
9584
9803
  if (sessionId === undefined) {
9585
9804
  delete enriched[TELEMETRY_SESSION_ID_PROPERTY];
@@ -9589,8 +9808,83 @@ class TelemetryService {
9589
9808
  return enriched;
9590
9809
  }
9591
9810
  generateId() {
9592
- return crypto.randomUUID().replaceAll("-", "");
9811
+ const bytes = new Uint8Array(8);
9812
+ let hex = "";
9813
+ do {
9814
+ crypto.getRandomValues(bytes);
9815
+ hex = "";
9816
+ for (const byte of bytes) {
9817
+ hex += byte.toString(16).padStart(2, "0");
9818
+ }
9819
+ } while (/^0+$/.test(hex));
9820
+ return hex;
9821
+ }
9822
+ }
9823
+ // src/telemetry/tracked-fetch.ts
9824
+ var W3C_TRACE_FLAGS_SAMPLED = "01";
9825
+ function makeTrackedFetch(realFetch) {
9826
+ return async (input, init) => {
9827
+ const context = telemetry.createDependencyContext();
9828
+ const url = resolveUrl(input);
9829
+ if (!context || !url) {
9830
+ return realFetch(input, init);
9831
+ }
9832
+ const method = resolveMethod(input, init).toUpperCase();
9833
+ const headers = mergeHeaders(input, init);
9834
+ if (!headers.has("traceparent")) {
9835
+ headers.set("traceparent", `00-${context.operationId}-${context.id}-${W3C_TRACE_FLAGS_SAMPLED}`);
9836
+ }
9837
+ const name = `${method} ${url.pathname}`;
9838
+ const startTime = performance.now();
9839
+ try {
9840
+ const response = await realFetch(input, { ...init, headers });
9841
+ telemetry.trackDependencyResult(name, "HTTP", performance.now() - startTime, response.ok, {
9842
+ "server.address": url.host,
9843
+ "http.request.method": method,
9844
+ "http.response.status_code": response.status
9845
+ }, context, String(response.status));
9846
+ return response;
9847
+ } catch (error) {
9848
+ telemetry.trackDependencyResult(name, "HTTP", performance.now() - startTime, false, {
9849
+ "server.address": url.host,
9850
+ "http.request.method": method,
9851
+ errorMessage: error instanceof Error ? error.message : String(error)
9852
+ }, context);
9853
+ throw error;
9854
+ }
9855
+ };
9856
+ }
9857
+ function resolveUrl(input) {
9858
+ try {
9859
+ if (typeof input === "string")
9860
+ return new URL(input);
9861
+ if (input instanceof URL)
9862
+ return input;
9863
+ if (input instanceof Request)
9864
+ return new URL(input.url);
9865
+ } catch {}
9866
+ return;
9867
+ }
9868
+ function resolveMethod(input, init) {
9869
+ if (init?.method)
9870
+ return init.method;
9871
+ if (input instanceof Request)
9872
+ return input.method;
9873
+ return "GET";
9874
+ }
9875
+ function mergeHeaders(input, init) {
9876
+ const headers = new Headers;
9877
+ if (input instanceof Request) {
9878
+ input.headers.forEach((value, key) => {
9879
+ headers.set(key, value);
9880
+ });
9593
9881
  }
9882
+ if (init?.headers) {
9883
+ new Headers(init.headers).forEach((value, key) => {
9884
+ headers.set(key, value);
9885
+ });
9886
+ }
9887
+ return headers;
9594
9888
  }
9595
9889
  // src/telemetry/node-appinsights-telemetry-provider.ts
9596
9890
  var providerSlot = singleton("TelemetryProvider");
@@ -9737,6 +10031,57 @@ class NodeAppInsightsTelemetryProvider {
9737
10031
  ...properties
9738
10032
  };
9739
10033
  }
10034
+ consumeCorrelation(properties) {
10035
+ const operationId = properties?.[TELEMETRY_OPERATION_ID_PROPERTY] || getTelemetryOperationId();
10036
+ const parentId = properties?.[TELEMETRY_PARENT_ID_PROPERTY];
10037
+ const spanId = properties?.[TELEMETRY_SPAN_ID_PROPERTY];
10038
+ if (properties) {
10039
+ delete properties[TELEMETRY_OPERATION_ID_PROPERTY];
10040
+ delete properties[TELEMETRY_PARENT_ID_PROPERTY];
10041
+ delete properties[TELEMETRY_SPAN_ID_PROPERTY];
10042
+ }
10043
+ return { operationId, parentId, spanId };
10044
+ }
10045
+ promoteSessionTag(merged, tags) {
10046
+ const client = this.client;
10047
+ if (!client || !merged)
10048
+ return;
10049
+ const sessionId = merged[TELEMETRY_SESSION_ID_PROPERTY];
10050
+ delete merged[TELEMETRY_SESSION_ID_PROPERTY];
10051
+ if (sessionId) {
10052
+ tags[client.context.keys.sessionId] = sessionId;
10053
+ }
10054
+ }
10055
+ leafTagOverrides(properties) {
10056
+ const client = this.client;
10057
+ if (!client)
10058
+ return;
10059
+ const keys = client.context.keys;
10060
+ const { operationId, spanId } = this.consumeCorrelation(properties);
10061
+ const tags = {
10062
+ [keys.operationId]: operationId
10063
+ };
10064
+ if (spanId) {
10065
+ tags[keys.operationParentId] = spanId;
10066
+ }
10067
+ this.promoteSessionTag(properties, tags);
10068
+ return tags;
10069
+ }
10070
+ operationCorrelation(properties) {
10071
+ const client = this.client;
10072
+ if (!client)
10073
+ return { tagOverrides: undefined, id: undefined };
10074
+ const keys = client.context.keys;
10075
+ const { operationId, parentId, spanId } = this.consumeCorrelation(properties);
10076
+ const tagOverrides = {
10077
+ [keys.operationId]: operationId
10078
+ };
10079
+ if (parentId) {
10080
+ tagOverrides[keys.operationParentId] = parentId;
10081
+ }
10082
+ this.promoteSessionTag(properties, tagOverrides);
10083
+ return { tagOverrides, id: spanId };
10084
+ }
9740
10085
  async trackEvent(eventName, properties) {
9741
10086
  const client = this.client;
9742
10087
  if (!client)
@@ -9744,7 +10089,8 @@ class NodeAppInsightsTelemetryProvider {
9744
10089
  const merged = this.mergeProperties(properties);
9745
10090
  const [error] = catchError(() => client.trackEvent({
9746
10091
  name: eventName,
9747
- properties: merged
10092
+ properties: merged,
10093
+ tagOverrides: this.leafTagOverrides(merged)
9748
10094
  }));
9749
10095
  if (error) {
9750
10096
  logger.debug(`[AppInsights] trackEvent failed for: ${eventName}`);
@@ -9757,7 +10103,8 @@ class NodeAppInsightsTelemetryProvider {
9757
10103
  const merged = this.mergeProperties(properties);
9758
10104
  const [trackError] = catchError(() => client.trackException({
9759
10105
  exception: error,
9760
- properties: merged
10106
+ properties: merged,
10107
+ tagOverrides: this.leafTagOverrides(merged)
9761
10108
  }));
9762
10109
  if (trackError) {
9763
10110
  logger.debug(`[AppInsights] trackException failed for: ${error.message}`);
@@ -9768,31 +10115,40 @@ class NodeAppInsightsTelemetryProvider {
9768
10115
  if (!client)
9769
10116
  return;
9770
10117
  const merged = this.mergeProperties(properties);
10118
+ const { tagOverrides, id } = this.operationCorrelation(merged);
9771
10119
  const [trackError] = catchError(() => client.trackRequest({
9772
10120
  name,
9773
10121
  url: toOperationUrn(name),
9774
10122
  duration,
9775
10123
  resultCode: success ? "200" : "500",
9776
10124
  success,
9777
- properties: merged
10125
+ ...id ? { id } : {},
10126
+ properties: merged,
10127
+ tagOverrides
9778
10128
  }));
9779
10129
  if (trackError) {
9780
10130
  logger.debug(`[AppInsights] trackRequest failed for: ${name}`);
9781
10131
  }
9782
10132
  }
9783
- async trackDependency(name, type2, duration, success, properties) {
10133
+ async trackDependency(name, type2, duration, success, properties, resultCode) {
9784
10134
  const client = this.client;
9785
10135
  if (!client)
9786
10136
  return;
9787
10137
  const merged = this.mergeProperties(properties);
9788
- client.trackDependency({
10138
+ const { tagOverrides, id } = this.operationCorrelation(merged);
10139
+ const [trackError] = catchError(() => client.trackDependency({
9789
10140
  name,
9790
10141
  dependencyTypeName: type2,
9791
10142
  duration,
9792
- resultCode: success ? "200" : "500",
10143
+ resultCode: resultCode ?? (success ? "200" : "500"),
9793
10144
  success,
9794
- properties: merged
9795
- });
10145
+ ...id ? { id } : {},
10146
+ properties: merged,
10147
+ tagOverrides
10148
+ }));
10149
+ if (trackError) {
10150
+ logger.debug(`[AppInsights] trackDependency failed for: ${name}`);
10151
+ }
9796
10152
  }
9797
10153
  async flush() {
9798
10154
  const client = this.client;
@@ -10729,134 +11085,11 @@ function buildSkillEventTelemetryAttribution(skillSource, uipSubcommand) {
10729
11085
  };
10730
11086
  }
10731
11087
 
10732
- // src/telemetry/pii-redactor.ts
10733
- var REDACTED = "[REDACTED]";
10734
- var MAX_VALUE_LENGTH = 200;
10735
- var SENSITIVE_NAME_TOKENS = new Set([
10736
- "token",
10737
- "tokens",
10738
- "secret",
10739
- "secrets",
10740
- "password",
10741
- "passwords",
10742
- "pwd",
10743
- "credential",
10744
- "credentials",
10745
- "auth",
10746
- "authentication",
10747
- "authorization",
10748
- "authority",
10749
- "cert",
10750
- "certificate",
10751
- "certificates"
10752
- ]);
10753
- var SENSITIVE_KEY_PREFIXES = new Set([
10754
- "api",
10755
- "access",
10756
- "client",
10757
- "private",
10758
- "public",
10759
- "signing",
10760
- "encryption",
10761
- "session",
10762
- "master",
10763
- "shared",
10764
- "root",
10765
- "ssh",
10766
- "rsa",
10767
- "aes",
10768
- "hmac",
10769
- "oauth"
10770
- ]);
10771
- var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
10772
- var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
10773
- var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
10774
- var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
10775
- var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
10776
- var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
10777
- var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
10778
- function shortHash(input) {
10779
- let hash = 2166136261;
10780
- for (let i = 0;i < input.length; i++) {
10781
- hash ^= input.charCodeAt(i);
10782
- hash = Math.imul(hash, 16777619);
10783
- }
10784
- return (hash >>> 0).toString(16).padStart(8, "0");
10785
- }
10786
- function redactUrl(raw) {
10787
- try {
10788
- const url = new URL(raw);
10789
- return `${url.protocol}//${url.host}`;
10790
- } catch {
10791
- return `url#${shortHash(raw)}`;
10792
- }
10793
- }
10794
- function redactValueDetectors(value) {
10795
- let out = value;
10796
- out = out.replace(JWT_PATTERN, () => REDACTED);
10797
- out = out.replace(URL_PATTERN, (match) => {
10798
- const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
10799
- const core2 = trailing ? match.slice(0, -trailing.length) : match;
10800
- return `${redactUrl(core2)}${trailing}`;
10801
- });
10802
- out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
10803
- out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
10804
- out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
10805
- out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
10806
- if (out.length > MAX_VALUE_LENGTH) {
10807
- out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
10808
- }
10809
- return out;
10810
- }
10811
- function nameTokens(name) {
10812
- return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).map((t) => t.toLowerCase()).filter(Boolean);
10813
- }
10814
- function isSensitiveName(name) {
10815
- const tokens = nameTokens(name);
10816
- for (let i = 0;i < tokens.length; i++) {
10817
- const token = tokens[i];
10818
- if (SENSITIVE_NAME_TOKENS.has(token)) {
10819
- return true;
10820
- }
10821
- if (token === "key" || token === "keys") {
10822
- const prev = tokens[i - 1];
10823
- if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
10824
- return true;
10825
- }
10826
- }
10827
- }
10828
- return false;
10829
- }
10830
- function redactProperty(name, value) {
10831
- if (value === undefined || value === null) {
10832
- return;
10833
- }
10834
- if (isSensitiveName(name)) {
10835
- return REDACTED;
10836
- }
10837
- if (typeof value === "boolean" || typeof value === "number") {
10838
- return value;
10839
- }
10840
- if (typeof value !== "string") {
10841
- return "[OBJECT]";
10842
- }
10843
- return redactValueDetectors(value);
10844
- }
10845
- function redactProperties(properties) {
10846
- const out = {};
10847
- for (const [name, value] of Object.entries(properties)) {
10848
- const redacted = redactProperty(name, value);
10849
- if (redacted !== undefined) {
10850
- out[name] = redacted;
10851
- }
10852
- }
10853
- return out;
10854
- }
10855
-
10856
11088
  // src/trackedAction.ts
10857
11089
  var pollSignalSlot = singleton("PollSignal");
10858
11090
  var cliErrorCodeValues = new Set(CLI_ERROR_CODES);
10859
11091
  var retryHintValues = new Set(RETRY_HINTS);
11092
+ var TELEMETRY_COMMAND_ARG_PREFIX = "uip.cmd.arg.";
10860
11093
  var processContext = {
10861
11094
  exit: (code) => {
10862
11095
  process.exitCode = code;
@@ -10870,22 +11103,18 @@ function setProcessContextPollSignal(signal) {
10870
11103
  }
10871
11104
  function extractCommandParams(cmd) {
10872
11105
  const params = {};
11106
+ const add2 = (name, value) => {
11107
+ if (name && value !== undefined) {
11108
+ params[`${TELEMETRY_COMMAND_ARG_PREFIX}${name}`] = value;
11109
+ }
11110
+ };
10873
11111
  const registered = cmd.registeredArguments ?? [];
10874
11112
  const processed = cmd.processedArgs ?? [];
10875
11113
  for (let i = 0;i < registered.length; i++) {
10876
- const value = processed[i];
10877
- if (value === undefined) {
10878
- continue;
10879
- }
10880
- const name = registered[i].name();
10881
- if (name) {
10882
- params[name] = value;
10883
- }
11114
+ add2(registered[i].name(), processed[i]);
10884
11115
  }
10885
11116
  for (const [key, value] of Object.entries(cmd.opts())) {
10886
- if (value !== undefined) {
10887
- params[key] = value;
10888
- }
11117
+ add2(key, value);
10889
11118
  }
10890
11119
  return params;
10891
11120
  }
@@ -10928,11 +11157,12 @@ Command.prototype.trackedAction = function(context, fn, properties) {
10928
11157
  return this.action(async (...args) => {
10929
11158
  const telemetryName = deriveCommandPath(command);
10930
11159
  const props = typeof properties === "function" ? properties(...args) : properties;
11160
+ const requestContext = telemetry.createRequestContext();
10931
11161
  const startTime = performance.now();
10932
11162
  let errorMessage;
10933
11163
  let fallbackExitCode = EXIT_CODES.Success;
10934
11164
  clearRecordedCommandFailureTelemetry();
10935
- const [error] = await catchError(fn(...args));
11165
+ const [error] = await catchError(telemetry.runWithContext(requestContext, () => fn(...args)));
10936
11166
  if (error) {
10937
11167
  errorMessage = error instanceof Error ? error.message : String(error);
10938
11168
  logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage}`);
@@ -10968,16 +11198,21 @@ Command.prototype.trackedAction = function(context, fn, properties) {
10968
11198
  recordedFailure,
10969
11199
  pollSignal: context.pollSignal
10970
11200
  });
10971
- telemetry.trackEvent(telemetryName, redactProperties({
10972
- ...extractCommandParams(command),
11201
+ const commandParams = extractCommandParams(command);
11202
+ if (props) {
11203
+ for (const key of Object.keys(props)) {
11204
+ delete commandParams[`${TELEMETRY_COMMAND_ARG_PREFIX}${key}`];
11205
+ }
11206
+ }
11207
+ const baseProperties = redactProperties({
11208
+ ...commandParams,
10973
11209
  ...props,
10974
11210
  ...buildCommandTelemetryAttribution(telemetryName, process.env.UIPATH_SKILL),
10975
11211
  command: "true",
10976
- duration: String(durationMs),
10977
- success: String(success),
10978
11212
  ...terminalTelemetry,
10979
11213
  ...errorMessage ? { errorMessage } : {}
10980
- }));
11214
+ });
11215
+ telemetry.trackRequestResult(telemetryName, durationMs, success, baseProperties, requestContext);
10981
11216
  });
10982
11217
  };
10983
11218
 
@@ -12118,8 +12353,10 @@ export {
12118
12353
  resetLoggerInstance,
12119
12354
  requireConfirmation,
12120
12355
  registerPackageMetadataOptions,
12356
+ redactValue,
12121
12357
  redactProperty,
12122
12358
  redactProperties,
12359
+ redactError,
12123
12360
  recordCommandFailureTelemetry,
12124
12361
  readStdinWithTimeout,
12125
12362
  readStdin,
@@ -12131,6 +12368,7 @@ export {
12131
12368
  parseOffset,
12132
12369
  parseNonNegativeInteger,
12133
12370
  parseLimit,
12371
+ parseInboundTraceparent,
12134
12372
  parseBoundedInt,
12135
12373
  parseAttachmentSpec,
12136
12374
  normalizeSkillName,
@@ -12139,6 +12377,7 @@ export {
12139
12377
  msToDuration,
12140
12378
  mapPollFailure,
12141
12379
  mapPackageMetadataOptions,
12380
+ makeTrackedFetch,
12142
12381
  logger,
12143
12382
  isTerminalStatus,
12144
12383
  isTelemetryDisabled,
@@ -12161,6 +12400,7 @@ export {
12161
12400
  getOutputFilter,
12162
12401
  getLogFilePath,
12163
12402
  getInteractivityMode,
12403
+ getInboundTraceContext,
12164
12404
  getHelpRequested,
12165
12405
  getGlobalLogFilePath,
12166
12406
  getExecutionContextTelemetryProperties,
@@ -12202,8 +12442,13 @@ export {
12202
12442
  addHiddenDeprecatedTenantOption,
12203
12443
  UIPATH_HOME_DIR,
12204
12444
  TelemetryService,
12445
+ TELEMETRY_TRACEPARENT_ENV,
12446
+ TELEMETRY_SPAN_ID_PROPERTY,
12205
12447
  TELEMETRY_SESSION_ID_PROPERTY,
12206
12448
  TELEMETRY_SESSION_ID_ENV,
12449
+ TELEMETRY_PARENT_ID_PROPERTY,
12450
+ TELEMETRY_OPERATION_ID_PROPERTY,
12451
+ TELEMETRY_COMMAND_ARG_PREFIX,
12207
12452
  SuccessOutput,
12208
12453
  ScreenLogger,
12209
12454
  RETRY_HINTS,
@@ -12238,4 +12483,4 @@ export {
12238
12483
  ATTACHMENT_INSTRUCTIONS
12239
12484
  };
12240
12485
 
12241
- //# debugId=B3D24B72053B092C64756E2164756E21
12486
+ //# debugId=0104AD30EA6F6A7264756E2164756E21