@uipath/common 1.198.0-preview.95 → 1.198.0

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
@@ -9427,11 +9427,36 @@ class NodeContextStorage {
9427
9427
  return this.storage.getStore();
9428
9428
  }
9429
9429
  }
9430
+ // src/telemetry/trace-context.ts
9431
+ var TELEMETRY_TRACEPARENT_ENV = "TRACEPARENT";
9432
+ var TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
9433
+ function getProcessEnv() {
9434
+ return globalThis.process?.env;
9435
+ }
9436
+ function parseInboundTraceparent(value) {
9437
+ if (!value) {
9438
+ return;
9439
+ }
9440
+ const match = TRACEPARENT_PATTERN.exec(value.trim().toLowerCase());
9441
+ if (!match) {
9442
+ return;
9443
+ }
9444
+ const [, traceId, parentSpanId] = match;
9445
+ if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId)) {
9446
+ return;
9447
+ }
9448
+ return { traceId, parentSpanId };
9449
+ }
9450
+ function getInboundTraceContext() {
9451
+ return parseInboundTraceparent(getProcessEnv()?.[TELEMETRY_TRACEPARENT_ENV]);
9452
+ }
9453
+
9430
9454
  // src/telemetry/session-id.ts
9431
9455
  var TELEMETRY_SESSION_ID_ENV = "UIPATH_SESSION_ID";
9432
9456
  var TELEMETRY_SESSION_ID_PROPERTY = "session_id";
9433
9457
  var telemetrySessionIdSlot = singleton("TelemetrySessionId");
9434
- function getProcessEnv() {
9458
+ var telemetryOperationIdSlot = singleton("TelemetryOperationId");
9459
+ function getProcessEnv2() {
9435
9460
  return globalThis.process?.env;
9436
9461
  }
9437
9462
  function normalizeSessionId(value) {
@@ -9442,7 +9467,7 @@ function normalizeSessionId(value) {
9442
9467
  return trimmed || undefined;
9443
9468
  }
9444
9469
  function getConfiguredTelemetrySessionId() {
9445
- return normalizeSessionId(getProcessEnv()?.[TELEMETRY_SESSION_ID_ENV]);
9470
+ return normalizeSessionId(getProcessEnv2()?.[TELEMETRY_SESSION_ID_ENV]);
9446
9471
  }
9447
9472
  function getTelemetrySessionId() {
9448
9473
  const envSessionId = getConfiguredTelemetrySessionId();
@@ -9460,6 +9485,16 @@ function getTelemetrySessionId() {
9460
9485
  function resolveTelemetrySessionId(existingSessionId) {
9461
9486
  return getConfiguredTelemetrySessionId() ?? normalizeSessionId(existingSessionId);
9462
9487
  }
9488
+ function getTelemetryOperationId() {
9489
+ const existing = telemetryOperationIdSlot.get();
9490
+ if (existing) {
9491
+ return existing;
9492
+ }
9493
+ const inboundTraceId = getInboundTraceContext()?.traceId;
9494
+ const generated = inboundTraceId ?? crypto.randomUUID().replaceAll("-", "");
9495
+ telemetryOperationIdSlot.set(generated);
9496
+ return generated;
9497
+ }
9463
9498
  // src/telemetry/global-telemetry-properties.ts
9464
9499
  var telemetryPropsSlot = singleton("TelemetryDefaultProps");
9465
9500
  function setGlobalTelemetryProperties(properties) {
@@ -9470,7 +9505,144 @@ function getGlobalTelemetryProperties() {
9470
9505
  return telemetryPropsSlot.get();
9471
9506
  }
9472
9507
 
9508
+ // src/telemetry/pii-redactor.ts
9509
+ var REDACTED = "[REDACTED]";
9510
+ var MAX_VALUE_LENGTH = 200;
9511
+ var SENSITIVE_NAME_TOKENS = new Set([
9512
+ "token",
9513
+ "tokens",
9514
+ "secret",
9515
+ "secrets",
9516
+ "password",
9517
+ "passwords",
9518
+ "pwd",
9519
+ "credential",
9520
+ "credentials",
9521
+ "auth",
9522
+ "authentication",
9523
+ "authorization",
9524
+ "authority",
9525
+ "cert",
9526
+ "certificate",
9527
+ "certificates"
9528
+ ]);
9529
+ var SENSITIVE_KEY_PREFIXES = new Set([
9530
+ "api",
9531
+ "access",
9532
+ "client",
9533
+ "private",
9534
+ "public",
9535
+ "signing",
9536
+ "encryption",
9537
+ "session",
9538
+ "master",
9539
+ "shared",
9540
+ "root",
9541
+ "ssh",
9542
+ "rsa",
9543
+ "aes",
9544
+ "hmac",
9545
+ "oauth"
9546
+ ]);
9547
+ 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;
9548
+ var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
9549
+ var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
9550
+ var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
9551
+ var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
9552
+ var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
9553
+ var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
9554
+ function shortHash(input) {
9555
+ let hash = 2166136261;
9556
+ for (let i = 0;i < input.length; i++) {
9557
+ hash ^= input.charCodeAt(i);
9558
+ hash = Math.imul(hash, 16777619);
9559
+ }
9560
+ return (hash >>> 0).toString(16).padStart(8, "0");
9561
+ }
9562
+ function redactUrl(raw) {
9563
+ try {
9564
+ const url = new URL(raw);
9565
+ return `${url.protocol}//${url.host}`;
9566
+ } catch {
9567
+ return `url#${shortHash(raw)}`;
9568
+ }
9569
+ }
9570
+ function redactValueDetectors(value) {
9571
+ let out = value;
9572
+ out = out.replace(JWT_PATTERN, () => REDACTED);
9573
+ out = out.replace(URL_PATTERN, (match) => {
9574
+ const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
9575
+ const core2 = trailing ? match.slice(0, -trailing.length) : match;
9576
+ return `${redactUrl(core2)}${trailing}`;
9577
+ });
9578
+ out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
9579
+ out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
9580
+ out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
9581
+ out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
9582
+ if (out.length > MAX_VALUE_LENGTH) {
9583
+ out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
9584
+ }
9585
+ return out;
9586
+ }
9587
+ function redactValue(value) {
9588
+ return redactValueDetectors(value);
9589
+ }
9590
+ function redactError(error) {
9591
+ const safe = new Error(redactValueDetectors(error.message ?? ""));
9592
+ safe.name = error.name;
9593
+ safe.stack = typeof error.stack === "string" ? redactValueDetectors(error.stack) : undefined;
9594
+ return safe;
9595
+ }
9596
+ function nameTokens(name) {
9597
+ 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);
9598
+ }
9599
+ function isSensitiveName(name) {
9600
+ const tokens = nameTokens(name);
9601
+ for (let i = 0;i < tokens.length; i++) {
9602
+ const token = tokens[i];
9603
+ if (SENSITIVE_NAME_TOKENS.has(token)) {
9604
+ return true;
9605
+ }
9606
+ if (token === "key" || token === "keys") {
9607
+ const prev = tokens[i - 1];
9608
+ if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
9609
+ return true;
9610
+ }
9611
+ }
9612
+ }
9613
+ return false;
9614
+ }
9615
+ function redactProperty(name, value) {
9616
+ if (value === undefined || value === null) {
9617
+ return;
9618
+ }
9619
+ if (isSensitiveName(name)) {
9620
+ return REDACTED;
9621
+ }
9622
+ if (typeof value === "boolean" || typeof value === "number") {
9623
+ return value;
9624
+ }
9625
+ if (typeof value !== "string") {
9626
+ return "[OBJECT]";
9627
+ }
9628
+ return redactValueDetectors(value);
9629
+ }
9630
+ function redactProperties(properties) {
9631
+ const out = {};
9632
+ for (const [name, value] of Object.entries(properties)) {
9633
+ const redacted = redactProperty(name, value);
9634
+ if (redacted !== undefined) {
9635
+ out[name] = redacted;
9636
+ }
9637
+ }
9638
+ return out;
9639
+ }
9640
+
9473
9641
  // src/telemetry/telemetry-service.ts
9642
+ var TELEMETRY_OPERATION_ID_PROPERTY = "uip.trace.operation_id";
9643
+ var TELEMETRY_PARENT_ID_PROPERTY = "uip.trace.parent_id";
9644
+ var TELEMETRY_SPAN_ID_PROPERTY = "uip.trace.span_id";
9645
+
9474
9646
  class TelemetryService {
9475
9647
  telemetryProvider;
9476
9648
  contextStorage;
@@ -9497,11 +9669,15 @@ class TelemetryService {
9497
9669
  trackException(error, properties) {
9498
9670
  const context = this.getCurrentContext();
9499
9671
  const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
9500
- this.telemetryProvider.trackException(error, enrichedProperties);
9672
+ this.telemetryProvider.trackException(redactError(error), enrichedProperties);
9501
9673
  }
9502
9674
  async trackRequest(name, fn, properties) {
9675
+ const parentContext = this.getCurrentContext();
9676
+ const operationId = parentContext?.operationId ?? this.operationId ?? getTelemetryOperationId();
9677
+ const parentId = parentContext ? parentContext.id : this.inboundParentIdFor(operationId);
9503
9678
  const context = {
9504
- operationId: this.operationId ?? this.generateId(),
9679
+ operationId,
9680
+ ...parentId !== undefined ? { parentId } : {},
9505
9681
  id: this.generateId()
9506
9682
  };
9507
9683
  const startTime = performance.now();
@@ -9519,6 +9695,45 @@ class TelemetryService {
9519
9695
  throw error;
9520
9696
  }
9521
9697
  }
9698
+ trackRequestResult(name, durationMs, success, properties, context) {
9699
+ const requestContext = context ?? {
9700
+ operationId: this.operationId ?? getTelemetryOperationId(),
9701
+ id: this.generateId()
9702
+ };
9703
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, requestContext);
9704
+ this.telemetryProvider.trackRequest(name, durationMs, success, enrichedProperties);
9705
+ }
9706
+ createRequestContext() {
9707
+ const operationId = this.operationId ?? getTelemetryOperationId();
9708
+ const parentId = this.inboundParentIdFor(operationId);
9709
+ return {
9710
+ operationId,
9711
+ ...parentId !== undefined ? { parentId } : {},
9712
+ id: this.generateId()
9713
+ };
9714
+ }
9715
+ inboundParentIdFor(operationId) {
9716
+ const inbound = getInboundTraceContext();
9717
+ return inbound && inbound.traceId === operationId ? inbound.parentSpanId : undefined;
9718
+ }
9719
+ runWithContext(context, fn) {
9720
+ return this.contextStorage.run(context, fn);
9721
+ }
9722
+ createDependencyContext() {
9723
+ const parentContext = this.getCurrentContext();
9724
+ if (!parentContext) {
9725
+ return;
9726
+ }
9727
+ return {
9728
+ operationId: parentContext.operationId,
9729
+ parentId: parentContext.id,
9730
+ id: this.generateId()
9731
+ };
9732
+ }
9733
+ trackDependencyResult(name, type2, durationMs, success, properties, context, resultCode) {
9734
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
9735
+ this.telemetryProvider.trackDependency(redactValue(name), type2, durationMs, success, enrichedProperties, resultCode);
9736
+ }
9522
9737
  async trackDependencyOperation(name, type2, fn, properties) {
9523
9738
  const parentContext = this.getCurrentContext();
9524
9739
  if (!parentContext) {
@@ -9555,8 +9770,12 @@ class TelemetryService {
9555
9770
  ...getExecutionContextTelemetryProperties(),
9556
9771
  ...globalProperties,
9557
9772
  ...this.defaultProperties,
9558
- ...properties,
9559
- ...context
9773
+ ...redactProperties(properties ?? {}),
9774
+ ...context ? {
9775
+ [TELEMETRY_OPERATION_ID_PROPERTY]: context.operationId,
9776
+ ...context.parentId !== undefined ? { [TELEMETRY_PARENT_ID_PROPERTY]: context.parentId } : {},
9777
+ [TELEMETRY_SPAN_ID_PROPERTY]: context.id
9778
+ } : {}
9560
9779
  };
9561
9780
  if (sessionId === undefined) {
9562
9781
  delete enriched[TELEMETRY_SESSION_ID_PROPERTY];
@@ -9566,8 +9785,83 @@ class TelemetryService {
9566
9785
  return enriched;
9567
9786
  }
9568
9787
  generateId() {
9569
- return crypto.randomUUID().replaceAll("-", "");
9788
+ const bytes = new Uint8Array(8);
9789
+ let hex = "";
9790
+ do {
9791
+ crypto.getRandomValues(bytes);
9792
+ hex = "";
9793
+ for (const byte of bytes) {
9794
+ hex += byte.toString(16).padStart(2, "0");
9795
+ }
9796
+ } while (/^0+$/.test(hex));
9797
+ return hex;
9798
+ }
9799
+ }
9800
+ // src/telemetry/tracked-fetch.ts
9801
+ var W3C_TRACE_FLAGS_SAMPLED = "01";
9802
+ function makeTrackedFetch(realFetch) {
9803
+ return async (input, init) => {
9804
+ const context = telemetry.createDependencyContext();
9805
+ const url = resolveUrl(input);
9806
+ if (!context || !url) {
9807
+ return realFetch(input, init);
9808
+ }
9809
+ const method = resolveMethod(input, init).toUpperCase();
9810
+ const headers = mergeHeaders(input, init);
9811
+ if (!headers.has("traceparent")) {
9812
+ headers.set("traceparent", `00-${context.operationId}-${context.id}-${W3C_TRACE_FLAGS_SAMPLED}`);
9813
+ }
9814
+ const name = `${method} ${url.pathname}`;
9815
+ const startTime = performance.now();
9816
+ try {
9817
+ const response = await realFetch(input, { ...init, headers });
9818
+ telemetry.trackDependencyResult(name, "HTTP", performance.now() - startTime, response.ok, {
9819
+ "server.address": url.host,
9820
+ "http.request.method": method,
9821
+ "http.response.status_code": response.status
9822
+ }, context, String(response.status));
9823
+ return response;
9824
+ } catch (error) {
9825
+ telemetry.trackDependencyResult(name, "HTTP", performance.now() - startTime, false, {
9826
+ "server.address": url.host,
9827
+ "http.request.method": method,
9828
+ errorMessage: error instanceof Error ? error.message : String(error)
9829
+ }, context);
9830
+ throw error;
9831
+ }
9832
+ };
9833
+ }
9834
+ function resolveUrl(input) {
9835
+ try {
9836
+ if (typeof input === "string")
9837
+ return new URL(input);
9838
+ if (input instanceof URL)
9839
+ return input;
9840
+ if (input instanceof Request)
9841
+ return new URL(input.url);
9842
+ } catch {}
9843
+ return;
9844
+ }
9845
+ function resolveMethod(input, init) {
9846
+ if (init?.method)
9847
+ return init.method;
9848
+ if (input instanceof Request)
9849
+ return input.method;
9850
+ return "GET";
9851
+ }
9852
+ function mergeHeaders(input, init) {
9853
+ const headers = new Headers;
9854
+ if (input instanceof Request) {
9855
+ input.headers.forEach((value, key) => {
9856
+ headers.set(key, value);
9857
+ });
9570
9858
  }
9859
+ if (init?.headers) {
9860
+ new Headers(init.headers).forEach((value, key) => {
9861
+ headers.set(key, value);
9862
+ });
9863
+ }
9864
+ return headers;
9571
9865
  }
9572
9866
  // src/telemetry/node-appinsights-telemetry-provider.ts
9573
9867
  var providerSlot = singleton("TelemetryProvider");
@@ -9714,6 +10008,57 @@ class NodeAppInsightsTelemetryProvider {
9714
10008
  ...properties
9715
10009
  };
9716
10010
  }
10011
+ consumeCorrelation(properties) {
10012
+ const operationId = properties?.[TELEMETRY_OPERATION_ID_PROPERTY] || getTelemetryOperationId();
10013
+ const parentId = properties?.[TELEMETRY_PARENT_ID_PROPERTY];
10014
+ const spanId = properties?.[TELEMETRY_SPAN_ID_PROPERTY];
10015
+ if (properties) {
10016
+ delete properties[TELEMETRY_OPERATION_ID_PROPERTY];
10017
+ delete properties[TELEMETRY_PARENT_ID_PROPERTY];
10018
+ delete properties[TELEMETRY_SPAN_ID_PROPERTY];
10019
+ }
10020
+ return { operationId, parentId, spanId };
10021
+ }
10022
+ promoteSessionTag(merged, tags) {
10023
+ const client = this.client;
10024
+ if (!client || !merged)
10025
+ return;
10026
+ const sessionId = merged[TELEMETRY_SESSION_ID_PROPERTY];
10027
+ delete merged[TELEMETRY_SESSION_ID_PROPERTY];
10028
+ if (sessionId) {
10029
+ tags[client.context.keys.sessionId] = sessionId;
10030
+ }
10031
+ }
10032
+ leafTagOverrides(properties) {
10033
+ const client = this.client;
10034
+ if (!client)
10035
+ return;
10036
+ const keys = client.context.keys;
10037
+ const { operationId, spanId } = this.consumeCorrelation(properties);
10038
+ const tags = {
10039
+ [keys.operationId]: operationId
10040
+ };
10041
+ if (spanId) {
10042
+ tags[keys.operationParentId] = spanId;
10043
+ }
10044
+ this.promoteSessionTag(properties, tags);
10045
+ return tags;
10046
+ }
10047
+ operationCorrelation(properties) {
10048
+ const client = this.client;
10049
+ if (!client)
10050
+ return { tagOverrides: undefined, id: undefined };
10051
+ const keys = client.context.keys;
10052
+ const { operationId, parentId, spanId } = this.consumeCorrelation(properties);
10053
+ const tagOverrides = {
10054
+ [keys.operationId]: operationId
10055
+ };
10056
+ if (parentId) {
10057
+ tagOverrides[keys.operationParentId] = parentId;
10058
+ }
10059
+ this.promoteSessionTag(properties, tagOverrides);
10060
+ return { tagOverrides, id: spanId };
10061
+ }
9717
10062
  async trackEvent(eventName, properties) {
9718
10063
  const client = this.client;
9719
10064
  if (!client)
@@ -9721,7 +10066,8 @@ class NodeAppInsightsTelemetryProvider {
9721
10066
  const merged = this.mergeProperties(properties);
9722
10067
  const [error] = catchError(() => client.trackEvent({
9723
10068
  name: eventName,
9724
- properties: merged
10069
+ properties: merged,
10070
+ tagOverrides: this.leafTagOverrides(merged)
9725
10071
  }));
9726
10072
  if (error) {
9727
10073
  logger.debug(`[AppInsights] trackEvent failed for: ${eventName}`);
@@ -9734,7 +10080,8 @@ class NodeAppInsightsTelemetryProvider {
9734
10080
  const merged = this.mergeProperties(properties);
9735
10081
  const [trackError] = catchError(() => client.trackException({
9736
10082
  exception: error,
9737
- properties: merged
10083
+ properties: merged,
10084
+ tagOverrides: this.leafTagOverrides(merged)
9738
10085
  }));
9739
10086
  if (trackError) {
9740
10087
  logger.debug(`[AppInsights] trackException failed for: ${error.message}`);
@@ -9745,31 +10092,40 @@ class NodeAppInsightsTelemetryProvider {
9745
10092
  if (!client)
9746
10093
  return;
9747
10094
  const merged = this.mergeProperties(properties);
10095
+ const { tagOverrides, id } = this.operationCorrelation(merged);
9748
10096
  const [trackError] = catchError(() => client.trackRequest({
9749
10097
  name,
9750
10098
  url: toOperationUrn(name),
9751
10099
  duration,
9752
10100
  resultCode: success ? "200" : "500",
9753
10101
  success,
9754
- properties: merged
10102
+ ...id ? { id } : {},
10103
+ properties: merged,
10104
+ tagOverrides
9755
10105
  }));
9756
10106
  if (trackError) {
9757
10107
  logger.debug(`[AppInsights] trackRequest failed for: ${name}`);
9758
10108
  }
9759
10109
  }
9760
- async trackDependency(name, type2, duration, success, properties) {
10110
+ async trackDependency(name, type2, duration, success, properties, resultCode) {
9761
10111
  const client = this.client;
9762
10112
  if (!client)
9763
10113
  return;
9764
10114
  const merged = this.mergeProperties(properties);
9765
- client.trackDependency({
10115
+ const { tagOverrides, id } = this.operationCorrelation(merged);
10116
+ const [trackError] = catchError(() => client.trackDependency({
9766
10117
  name,
9767
10118
  dependencyTypeName: type2,
9768
10119
  duration,
9769
- resultCode: success ? "200" : "500",
10120
+ resultCode: resultCode ?? (success ? "200" : "500"),
9770
10121
  success,
9771
- properties: merged
9772
- });
10122
+ ...id ? { id } : {},
10123
+ properties: merged,
10124
+ tagOverrides
10125
+ }));
10126
+ if (trackError) {
10127
+ logger.debug(`[AppInsights] trackDependency failed for: ${name}`);
10128
+ }
9773
10129
  }
9774
10130
  async flush() {
9775
10131
  const client = this.client;
@@ -10705,134 +11061,11 @@ function buildSkillEventTelemetryAttribution(skillSource, uipSubcommand) {
10705
11061
  };
10706
11062
  }
10707
11063
 
10708
- // src/telemetry/pii-redactor.ts
10709
- var REDACTED = "[REDACTED]";
10710
- var MAX_VALUE_LENGTH = 200;
10711
- var SENSITIVE_NAME_TOKENS = new Set([
10712
- "token",
10713
- "tokens",
10714
- "secret",
10715
- "secrets",
10716
- "password",
10717
- "passwords",
10718
- "pwd",
10719
- "credential",
10720
- "credentials",
10721
- "auth",
10722
- "authentication",
10723
- "authorization",
10724
- "authority",
10725
- "cert",
10726
- "certificate",
10727
- "certificates"
10728
- ]);
10729
- var SENSITIVE_KEY_PREFIXES = new Set([
10730
- "api",
10731
- "access",
10732
- "client",
10733
- "private",
10734
- "public",
10735
- "signing",
10736
- "encryption",
10737
- "session",
10738
- "master",
10739
- "shared",
10740
- "root",
10741
- "ssh",
10742
- "rsa",
10743
- "aes",
10744
- "hmac",
10745
- "oauth"
10746
- ]);
10747
- 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;
10748
- var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
10749
- var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
10750
- var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
10751
- var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
10752
- var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
10753
- var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
10754
- function shortHash(input) {
10755
- let hash = 2166136261;
10756
- for (let i = 0;i < input.length; i++) {
10757
- hash ^= input.charCodeAt(i);
10758
- hash = Math.imul(hash, 16777619);
10759
- }
10760
- return (hash >>> 0).toString(16).padStart(8, "0");
10761
- }
10762
- function redactUrl(raw) {
10763
- try {
10764
- const url = new URL(raw);
10765
- return `${url.protocol}//${url.host}`;
10766
- } catch {
10767
- return `url#${shortHash(raw)}`;
10768
- }
10769
- }
10770
- function redactValueDetectors(value) {
10771
- let out = value;
10772
- out = out.replace(JWT_PATTERN, () => REDACTED);
10773
- out = out.replace(URL_PATTERN, (match) => {
10774
- const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
10775
- const core2 = trailing ? match.slice(0, -trailing.length) : match;
10776
- return `${redactUrl(core2)}${trailing}`;
10777
- });
10778
- out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
10779
- out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
10780
- out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
10781
- out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
10782
- if (out.length > MAX_VALUE_LENGTH) {
10783
- out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
10784
- }
10785
- return out;
10786
- }
10787
- function nameTokens(name) {
10788
- 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);
10789
- }
10790
- function isSensitiveName(name) {
10791
- const tokens = nameTokens(name);
10792
- for (let i = 0;i < tokens.length; i++) {
10793
- const token = tokens[i];
10794
- if (SENSITIVE_NAME_TOKENS.has(token)) {
10795
- return true;
10796
- }
10797
- if (token === "key" || token === "keys") {
10798
- const prev = tokens[i - 1];
10799
- if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
10800
- return true;
10801
- }
10802
- }
10803
- }
10804
- return false;
10805
- }
10806
- function redactProperty(name, value) {
10807
- if (value === undefined || value === null) {
10808
- return;
10809
- }
10810
- if (isSensitiveName(name)) {
10811
- return REDACTED;
10812
- }
10813
- if (typeof value === "boolean" || typeof value === "number") {
10814
- return value;
10815
- }
10816
- if (typeof value !== "string") {
10817
- return "[OBJECT]";
10818
- }
10819
- return redactValueDetectors(value);
10820
- }
10821
- function redactProperties(properties) {
10822
- const out = {};
10823
- for (const [name, value] of Object.entries(properties)) {
10824
- const redacted = redactProperty(name, value);
10825
- if (redacted !== undefined) {
10826
- out[name] = redacted;
10827
- }
10828
- }
10829
- return out;
10830
- }
10831
-
10832
11064
  // src/trackedAction.ts
10833
11065
  var pollSignalSlot = singleton("PollSignal");
10834
11066
  var cliErrorCodeValues = new Set(CLI_ERROR_CODES);
10835
11067
  var retryHintValues = new Set(RETRY_HINTS);
11068
+ var TELEMETRY_COMMAND_ARG_PREFIX = "uip.cmd.arg.";
10836
11069
  var processContext = {
10837
11070
  exit: (code) => {
10838
11071
  process.exitCode = code;
@@ -10846,22 +11079,18 @@ function setProcessContextPollSignal(signal) {
10846
11079
  }
10847
11080
  function extractCommandParams(cmd) {
10848
11081
  const params = {};
11082
+ const add2 = (name, value) => {
11083
+ if (name && value !== undefined) {
11084
+ params[`${TELEMETRY_COMMAND_ARG_PREFIX}${name}`] = value;
11085
+ }
11086
+ };
10849
11087
  const registered = cmd.registeredArguments ?? [];
10850
11088
  const processed = cmd.processedArgs ?? [];
10851
11089
  for (let i = 0;i < registered.length; i++) {
10852
- const value = processed[i];
10853
- if (value === undefined) {
10854
- continue;
10855
- }
10856
- const name = registered[i].name();
10857
- if (name) {
10858
- params[name] = value;
10859
- }
11090
+ add2(registered[i].name(), processed[i]);
10860
11091
  }
10861
11092
  for (const [key, value] of Object.entries(cmd.opts())) {
10862
- if (value !== undefined) {
10863
- params[key] = value;
10864
- }
11093
+ add2(key, value);
10865
11094
  }
10866
11095
  return params;
10867
11096
  }
@@ -10904,11 +11133,12 @@ Command.prototype.trackedAction = function(context, fn, properties) {
10904
11133
  return this.action(async (...args) => {
10905
11134
  const telemetryName = deriveCommandPath(command);
10906
11135
  const props = typeof properties === "function" ? properties(...args) : properties;
11136
+ const requestContext = telemetry.createRequestContext();
10907
11137
  const startTime = performance.now();
10908
11138
  let errorMessage;
10909
11139
  let fallbackExitCode = EXIT_CODES.Success;
10910
11140
  clearRecordedCommandFailureTelemetry();
10911
- const [error] = await catchError(fn(...args));
11141
+ const [error] = await catchError(telemetry.runWithContext(requestContext, () => fn(...args)));
10912
11142
  if (error) {
10913
11143
  errorMessage = error instanceof Error ? error.message : String(error);
10914
11144
  logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage}`);
@@ -10944,16 +11174,21 @@ Command.prototype.trackedAction = function(context, fn, properties) {
10944
11174
  recordedFailure,
10945
11175
  pollSignal: context.pollSignal
10946
11176
  });
10947
- telemetry.trackEvent(telemetryName, redactProperties({
10948
- ...extractCommandParams(command),
11177
+ const commandParams = extractCommandParams(command);
11178
+ if (props) {
11179
+ for (const key of Object.keys(props)) {
11180
+ delete commandParams[`${TELEMETRY_COMMAND_ARG_PREFIX}${key}`];
11181
+ }
11182
+ }
11183
+ const baseProperties = redactProperties({
11184
+ ...commandParams,
10949
11185
  ...props,
10950
11186
  ...buildCommandTelemetryAttribution(telemetryName, process.env.UIPATH_SKILL),
10951
11187
  command: "true",
10952
- duration: String(durationMs),
10953
- success: String(success),
10954
11188
  ...terminalTelemetry,
10955
11189
  ...errorMessage ? { errorMessage } : {}
10956
- }));
11190
+ });
11191
+ telemetry.trackRequestResult(telemetryName, durationMs, success, baseProperties, requestContext);
10957
11192
  });
10958
11193
  };
10959
11194
 
@@ -12092,8 +12327,10 @@ export {
12092
12327
  resetLoggerInstance,
12093
12328
  requireConfirmation,
12094
12329
  registerPackageMetadataOptions,
12330
+ redactValue,
12095
12331
  redactProperty,
12096
12332
  redactProperties,
12333
+ redactError,
12097
12334
  recordCommandFailureTelemetry,
12098
12335
  readStdinWithTimeout,
12099
12336
  readStdin,
@@ -12105,6 +12342,7 @@ export {
12105
12342
  parseOffset,
12106
12343
  parseNonNegativeInteger,
12107
12344
  parseLimit,
12345
+ parseInboundTraceparent,
12108
12346
  parseBoundedInt,
12109
12347
  parseAttachmentSpec,
12110
12348
  normalizeSkillName,
@@ -12113,6 +12351,7 @@ export {
12113
12351
  msToDuration,
12114
12352
  mapPollFailure,
12115
12353
  mapPackageMetadataOptions,
12354
+ makeTrackedFetch,
12116
12355
  logger,
12117
12356
  isTerminalStatus,
12118
12357
  isTelemetryDisabled,
@@ -12135,6 +12374,7 @@ export {
12135
12374
  getOutputFilter,
12136
12375
  getLogFilePath,
12137
12376
  getInteractivityMode,
12377
+ getInboundTraceContext,
12138
12378
  getHelpRequested,
12139
12379
  getGlobalLogFilePath,
12140
12380
  getExecutionContextTelemetryProperties,
@@ -12175,8 +12415,13 @@ export {
12175
12415
  addHiddenDeprecatedTenantOption,
12176
12416
  UIPATH_HOME_DIR,
12177
12417
  TelemetryService,
12418
+ TELEMETRY_TRACEPARENT_ENV,
12419
+ TELEMETRY_SPAN_ID_PROPERTY,
12178
12420
  TELEMETRY_SESSION_ID_PROPERTY,
12179
12421
  TELEMETRY_SESSION_ID_ENV,
12422
+ TELEMETRY_PARENT_ID_PROPERTY,
12423
+ TELEMETRY_OPERATION_ID_PROPERTY,
12424
+ TELEMETRY_COMMAND_ARG_PREFIX,
12180
12425
  SuccessOutput,
12181
12426
  ScreenLogger,
12182
12427
  RETRY_HINTS,
@@ -12211,4 +12456,4 @@ export {
12211
12456
  ATTACHMENT_INSTRUCTIONS
12212
12457
  };
12213
12458
 
12214
- //# debugId=B8317EE6AFDCF8C264756E2164756E21
12459
+ //# debugId=770AFB2BE9F8C7B964756E2164756E21