@uipath/uipath-typescript 1.3.8 → 1.3.9
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/assets/index.cjs +25 -270
- package/dist/assets/index.mjs +25 -270
- package/dist/attachments/index.cjs +23 -267
- package/dist/attachments/index.mjs +23 -267
- package/dist/buckets/index.cjs +54 -270
- package/dist/buckets/index.d.ts +50 -1
- package/dist/buckets/index.mjs +54 -270
- package/dist/cases/index.cjs +408 -337
- package/dist/cases/index.d.ts +534 -2
- package/dist/cases/index.mjs +409 -338
- package/dist/conversational-agent/index.cjs +71 -281
- package/dist/conversational-agent/index.d.ts +62 -12
- package/dist/conversational-agent/index.mjs +71 -282
- package/dist/core/index.cjs +39 -289
- package/dist/core/index.d.ts +9 -98
- package/dist/core/index.mjs +40 -275
- package/dist/document-understanding/index.cjs +18 -1
- package/dist/document-understanding/index.d.ts +636 -610
- package/dist/document-understanding/index.mjs +18 -1
- package/dist/entities/index.cjs +25 -270
- package/dist/entities/index.mjs +25 -270
- package/dist/feedback/index.cjs +23 -268
- package/dist/feedback/index.mjs +23 -268
- package/dist/index.cjs +600 -293
- package/dist/index.d.ts +1603 -722
- package/dist/index.mjs +600 -279
- package/dist/index.umd.js +789 -158
- package/dist/jobs/index.cjs +25 -270
- package/dist/jobs/index.mjs +25 -270
- package/dist/maestro-processes/index.cjs +1751 -1720
- package/dist/maestro-processes/index.d.ts +430 -2
- package/dist/maestro-processes/index.mjs +1752 -1721
- package/dist/processes/index.cjs +25 -270
- package/dist/processes/index.mjs +25 -270
- package/dist/queues/index.cjs +25 -270
- package/dist/queues/index.mjs +25 -270
- package/dist/tasks/index.cjs +25 -270
- package/dist/tasks/index.mjs +25 -270
- package/package.json +8 -10
package/dist/assets/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var coreTelemetry = require('@uipath/core-telemetry');
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
6
6
|
Copyright (c) Microsoft Corporation.
|
|
@@ -1885,278 +1885,33 @@ const AssetMap = {
|
|
|
1885
1885
|
};
|
|
1886
1886
|
|
|
1887
1887
|
/**
|
|
1888
|
-
* SDK Telemetry constants
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
const
|
|
1899
|
-
const CLOUD_CLIENT_ID = "CloudClientId";
|
|
1900
|
-
const CLOUD_REDIRECT_URI = "CloudRedirectUri";
|
|
1901
|
-
const APP_NAME = "ApplicationName";
|
|
1902
|
-
const CLOUD_ROLE_NAME = "uipath-ts-sdk";
|
|
1903
|
-
// Service and logger names
|
|
1904
|
-
const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
|
|
1905
|
-
const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
|
|
1906
|
-
// Event names
|
|
1907
|
-
const SDK_RUN_EVENT = "Sdk.Run";
|
|
1908
|
-
// Default value for unknown/empty attributes
|
|
1909
|
-
const UNKNOWN = "";
|
|
1910
|
-
|
|
1911
|
-
/**
|
|
1912
|
-
* Log exporter that sends ALL logs as Application Insights custom events
|
|
1913
|
-
*/
|
|
1914
|
-
class ApplicationInsightsEventExporter {
|
|
1915
|
-
constructor(connectionString) {
|
|
1916
|
-
this.connectionString = connectionString;
|
|
1917
|
-
}
|
|
1918
|
-
export(logs, resultCallback) {
|
|
1919
|
-
try {
|
|
1920
|
-
logs.forEach(logRecord => {
|
|
1921
|
-
this.sendAsCustomEvent(logRecord);
|
|
1922
|
-
});
|
|
1923
|
-
resultCallback({ code: 0 });
|
|
1924
|
-
}
|
|
1925
|
-
catch (error) {
|
|
1926
|
-
console.debug('Failed to export logs to Application Insights:', error);
|
|
1927
|
-
resultCallback({ code: 2, error });
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
shutdown() {
|
|
1931
|
-
return Promise.resolve();
|
|
1932
|
-
}
|
|
1933
|
-
sendAsCustomEvent(logRecord) {
|
|
1934
|
-
// Get event name from body or attributes
|
|
1935
|
-
const eventName = logRecord.body || SDK_RUN_EVENT;
|
|
1936
|
-
const payload = {
|
|
1937
|
-
name: 'Microsoft.ApplicationInsights.Event',
|
|
1938
|
-
time: new Date().toISOString(),
|
|
1939
|
-
iKey: this.extractInstrumentationKey(),
|
|
1940
|
-
data: {
|
|
1941
|
-
baseType: 'EventData',
|
|
1942
|
-
baseData: {
|
|
1943
|
-
ver: 2,
|
|
1944
|
-
name: eventName,
|
|
1945
|
-
properties: this.convertAttributesToProperties(logRecord.attributes || {})
|
|
1946
|
-
}
|
|
1947
|
-
},
|
|
1948
|
-
tags: {
|
|
1949
|
-
'ai.cloud.role': CLOUD_ROLE_NAME,
|
|
1950
|
-
'ai.cloud.roleInstance': SDK_VERSION
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
this.sendToApplicationInsights(payload);
|
|
1954
|
-
}
|
|
1955
|
-
extractInstrumentationKey() {
|
|
1956
|
-
const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
|
|
1957
|
-
return match ? match[1] : '';
|
|
1958
|
-
}
|
|
1959
|
-
convertAttributesToProperties(attributes) {
|
|
1960
|
-
const properties = {};
|
|
1961
|
-
Object.entries(attributes || {}).forEach(([key, value]) => {
|
|
1962
|
-
properties[key] = String(value);
|
|
1963
|
-
});
|
|
1964
|
-
return properties;
|
|
1965
|
-
}
|
|
1966
|
-
async sendToApplicationInsights(payload) {
|
|
1967
|
-
try {
|
|
1968
|
-
const ingestionEndpoint = this.extractIngestionEndpoint();
|
|
1969
|
-
if (!ingestionEndpoint) {
|
|
1970
|
-
console.debug('No ingestion endpoint found in connection string');
|
|
1971
|
-
return;
|
|
1972
|
-
}
|
|
1973
|
-
const url = `${ingestionEndpoint}/v2/track`;
|
|
1974
|
-
const response = await fetch(url, {
|
|
1975
|
-
method: 'POST',
|
|
1976
|
-
headers: {
|
|
1977
|
-
'Content-Type': 'application/json',
|
|
1978
|
-
},
|
|
1979
|
-
body: JSON.stringify(payload)
|
|
1980
|
-
});
|
|
1981
|
-
if (!response.ok) {
|
|
1982
|
-
console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
catch (error) {
|
|
1986
|
-
console.debug('Error sending event telemetry to Application Insights:', error);
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
extractIngestionEndpoint() {
|
|
1990
|
-
const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
|
|
1991
|
-
return match ? match[1] : '';
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
/**
|
|
1995
|
-
* Singleton telemetry client
|
|
1996
|
-
*/
|
|
1997
|
-
class TelemetryClient {
|
|
1998
|
-
constructor() {
|
|
1999
|
-
this.isInitialized = false;
|
|
2000
|
-
}
|
|
2001
|
-
static getInstance() {
|
|
2002
|
-
if (!TelemetryClient.instance) {
|
|
2003
|
-
TelemetryClient.instance = new TelemetryClient();
|
|
2004
|
-
}
|
|
2005
|
-
return TelemetryClient.instance;
|
|
2006
|
-
}
|
|
2007
|
-
/**
|
|
2008
|
-
* Initialize telemetry
|
|
2009
|
-
*/
|
|
2010
|
-
initialize(config) {
|
|
2011
|
-
if (this.isInitialized) {
|
|
2012
|
-
return;
|
|
2013
|
-
}
|
|
2014
|
-
this.isInitialized = true;
|
|
2015
|
-
if (config) {
|
|
2016
|
-
this.telemetryContext = config;
|
|
2017
|
-
}
|
|
2018
|
-
try {
|
|
2019
|
-
const connectionString = this.getConnectionString();
|
|
2020
|
-
if (!connectionString) {
|
|
2021
|
-
return;
|
|
2022
|
-
}
|
|
2023
|
-
this.setupTelemetryProvider(connectionString);
|
|
2024
|
-
}
|
|
2025
|
-
catch (error) {
|
|
2026
|
-
// Silent failure - telemetry errors shouldn't break functionality
|
|
2027
|
-
console.debug('Failed to initialize OpenTelemetry:', error);
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
getConnectionString() {
|
|
2031
|
-
const connectionString = CONNECTION_STRING;
|
|
2032
|
-
return connectionString;
|
|
2033
|
-
}
|
|
2034
|
-
setupTelemetryProvider(connectionString) {
|
|
2035
|
-
const exporter = new ApplicationInsightsEventExporter(connectionString);
|
|
2036
|
-
const processor = new sdkLogs.BatchLogRecordProcessor(exporter);
|
|
2037
|
-
this.logProvider = new sdkLogs.LoggerProvider({
|
|
2038
|
-
processors: [processor]
|
|
2039
|
-
});
|
|
2040
|
-
this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
|
|
2041
|
-
}
|
|
2042
|
-
/**
|
|
2043
|
-
* Track a telemetry event
|
|
2044
|
-
*/
|
|
2045
|
-
track(eventName, name, extraAttributes = {}) {
|
|
2046
|
-
try {
|
|
2047
|
-
// Skip if logger not initialized
|
|
2048
|
-
if (!this.logger) {
|
|
2049
|
-
return;
|
|
2050
|
-
}
|
|
2051
|
-
const finalDisplayName = name || eventName;
|
|
2052
|
-
const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
|
|
2053
|
-
// Emit as log
|
|
2054
|
-
this.logger.emit({
|
|
2055
|
-
body: finalDisplayName,
|
|
2056
|
-
attributes: attributes,
|
|
2057
|
-
timestamp: Date.now(),
|
|
2058
|
-
});
|
|
2059
|
-
}
|
|
2060
|
-
catch (error) {
|
|
2061
|
-
// Silent failure
|
|
2062
|
-
console.debug('Failed to track telemetry event:', error);
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
/**
|
|
2066
|
-
* Get enriched attributes for telemetry events
|
|
2067
|
-
*/
|
|
2068
|
-
getEnrichedAttributes(extraAttributes, eventName) {
|
|
2069
|
-
const attributes = {
|
|
2070
|
-
[APP_NAME]: SDK_SERVICE_NAME,
|
|
2071
|
-
[VERSION]: SDK_VERSION,
|
|
2072
|
-
[SERVICE]: eventName,
|
|
2073
|
-
[CLOUD_URL]: this.createCloudUrl(),
|
|
2074
|
-
[CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
|
|
2075
|
-
[CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
|
|
2076
|
-
[CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
|
|
2077
|
-
[CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
|
|
2078
|
-
...extraAttributes,
|
|
2079
|
-
};
|
|
2080
|
-
return attributes;
|
|
2081
|
-
}
|
|
2082
|
-
/**
|
|
2083
|
-
* Create cloud URL from base URL, organization ID, and tenant ID
|
|
2084
|
-
*/
|
|
2085
|
-
createCloudUrl() {
|
|
2086
|
-
const baseUrl = this.telemetryContext?.baseUrl;
|
|
2087
|
-
const orgId = this.telemetryContext?.orgName;
|
|
2088
|
-
const tenantId = this.telemetryContext?.tenantName;
|
|
2089
|
-
if (!baseUrl || !orgId || !tenantId) {
|
|
2090
|
-
return UNKNOWN;
|
|
2091
|
-
}
|
|
2092
|
-
return `${baseUrl}/${orgId}/${tenantId}`;
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
// Export singleton instance
|
|
2096
|
-
const telemetryClient = TelemetryClient.getInstance();
|
|
1888
|
+
* SDK Telemetry constants.
|
|
1889
|
+
*
|
|
1890
|
+
* Only the SDK's identity (version, service name, role name, …) lives
|
|
1891
|
+
* here. The Application Insights connection string is injected into
|
|
1892
|
+
* `@uipath/core-telemetry` itself at publish time, and the generic attribute
|
|
1893
|
+
* keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
|
|
1894
|
+
* `@uipath/core-telemetry` and consumed there — they are not part of the
|
|
1895
|
+
* SDK's public API.
|
|
1896
|
+
*/
|
|
1897
|
+
/** SDK version placeholder — patched by the SDK publish workflow. */
|
|
1898
|
+
const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
|
|
2097
1899
|
|
|
2098
1900
|
/**
|
|
2099
|
-
*
|
|
2100
|
-
*/
|
|
2101
|
-
/**
|
|
2102
|
-
* Common tracking logic shared between method and function decorators
|
|
2103
|
-
*/
|
|
2104
|
-
function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
|
|
2105
|
-
return function (...args) {
|
|
2106
|
-
// Determine if we should track this call
|
|
2107
|
-
let shouldTrack = true;
|
|
2108
|
-
if (opts.condition !== undefined) {
|
|
2109
|
-
if (typeof opts.condition === 'function') {
|
|
2110
|
-
shouldTrack = opts.condition.apply(this, args);
|
|
2111
|
-
}
|
|
2112
|
-
else {
|
|
2113
|
-
shouldTrack = opts.condition;
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
// Track the event if enabled
|
|
2117
|
-
if (shouldTrack) {
|
|
2118
|
-
// Use the full name provided in the decorator (e.g., "Queue.GetAll")
|
|
2119
|
-
const serviceMethod = typeof nameOrOptions === 'string'
|
|
2120
|
-
? nameOrOptions
|
|
2121
|
-
: fallbackName;
|
|
2122
|
-
// Use 'Sdk.Run' as the name and serviceMethod as the service
|
|
2123
|
-
telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
|
|
2124
|
-
}
|
|
2125
|
-
// Execute the original function
|
|
2126
|
-
return originalFunction.apply(this, args);
|
|
2127
|
-
};
|
|
2128
|
-
}
|
|
2129
|
-
/**
|
|
2130
|
-
* Track decorator that can be used to automatically track function calls
|
|
2131
|
-
*
|
|
2132
|
-
* Usage:
|
|
2133
|
-
* @track("Service.Method")
|
|
2134
|
-
* function myFunction() { ... }
|
|
1901
|
+
* UiPath TypeScript SDK Telemetry
|
|
2135
1902
|
*
|
|
2136
|
-
*
|
|
2137
|
-
*
|
|
2138
|
-
*
|
|
2139
|
-
*
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
function track(nameOrOptions, options) {
|
|
2149
|
-
return function decorator(_target, propertyKey, descriptor) {
|
|
2150
|
-
const opts = typeof nameOrOptions === 'object' ? nameOrOptions : {};
|
|
2151
|
-
if (descriptor && typeof descriptor.value === 'function') {
|
|
2152
|
-
// Method decorator
|
|
2153
|
-
descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
|
|
2154
|
-
return descriptor;
|
|
2155
|
-
}
|
|
2156
|
-
// Function decorator
|
|
2157
|
-
return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
|
|
2158
|
-
};
|
|
2159
|
-
}
|
|
1903
|
+
* Constructs the SDK's own `TelemetryClient` and binds the SDK-local
|
|
1904
|
+
* `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
|
|
1905
|
+
* does this independently, so events carry their own consumer's identity
|
|
1906
|
+
* and tenant context.
|
|
1907
|
+
*/
|
|
1908
|
+
// Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
|
|
1909
|
+
// same `TelemetryClient` instance at runtime. A single `initialize(...)`
|
|
1910
|
+
// from the `UiPath` constructor therefore wires up `@track` decorators
|
|
1911
|
+
// across every subpath bundle (`assets`, `feedback`, `tasks`, …).
|
|
1912
|
+
const sdkClient = coreTelemetry.getOrCreateClient(CLOUD_ROLE_NAME);
|
|
1913
|
+
const track = coreTelemetry.createTrack(sdkClient);
|
|
1914
|
+
coreTelemetry.createTrackEvent(sdkClient);
|
|
2160
1915
|
|
|
2161
1916
|
/**
|
|
2162
1917
|
* Service for interacting with UiPath Orchestrator Assets API
|
package/dist/assets/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getOrCreateClient, createTrack, createTrackEvent } from '@uipath/core-telemetry';
|
|
2
2
|
|
|
3
3
|
/******************************************************************************
|
|
4
4
|
Copyright (c) Microsoft Corporation.
|
|
@@ -1883,278 +1883,33 @@ const AssetMap = {
|
|
|
1883
1883
|
};
|
|
1884
1884
|
|
|
1885
1885
|
/**
|
|
1886
|
-
* SDK Telemetry constants
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
const
|
|
1897
|
-
const CLOUD_CLIENT_ID = "CloudClientId";
|
|
1898
|
-
const CLOUD_REDIRECT_URI = "CloudRedirectUri";
|
|
1899
|
-
const APP_NAME = "ApplicationName";
|
|
1900
|
-
const CLOUD_ROLE_NAME = "uipath-ts-sdk";
|
|
1901
|
-
// Service and logger names
|
|
1902
|
-
const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
|
|
1903
|
-
const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
|
|
1904
|
-
// Event names
|
|
1905
|
-
const SDK_RUN_EVENT = "Sdk.Run";
|
|
1906
|
-
// Default value for unknown/empty attributes
|
|
1907
|
-
const UNKNOWN = "";
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* Log exporter that sends ALL logs as Application Insights custom events
|
|
1911
|
-
*/
|
|
1912
|
-
class ApplicationInsightsEventExporter {
|
|
1913
|
-
constructor(connectionString) {
|
|
1914
|
-
this.connectionString = connectionString;
|
|
1915
|
-
}
|
|
1916
|
-
export(logs, resultCallback) {
|
|
1917
|
-
try {
|
|
1918
|
-
logs.forEach(logRecord => {
|
|
1919
|
-
this.sendAsCustomEvent(logRecord);
|
|
1920
|
-
});
|
|
1921
|
-
resultCallback({ code: 0 });
|
|
1922
|
-
}
|
|
1923
|
-
catch (error) {
|
|
1924
|
-
console.debug('Failed to export logs to Application Insights:', error);
|
|
1925
|
-
resultCallback({ code: 2, error });
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
shutdown() {
|
|
1929
|
-
return Promise.resolve();
|
|
1930
|
-
}
|
|
1931
|
-
sendAsCustomEvent(logRecord) {
|
|
1932
|
-
// Get event name from body or attributes
|
|
1933
|
-
const eventName = logRecord.body || SDK_RUN_EVENT;
|
|
1934
|
-
const payload = {
|
|
1935
|
-
name: 'Microsoft.ApplicationInsights.Event',
|
|
1936
|
-
time: new Date().toISOString(),
|
|
1937
|
-
iKey: this.extractInstrumentationKey(),
|
|
1938
|
-
data: {
|
|
1939
|
-
baseType: 'EventData',
|
|
1940
|
-
baseData: {
|
|
1941
|
-
ver: 2,
|
|
1942
|
-
name: eventName,
|
|
1943
|
-
properties: this.convertAttributesToProperties(logRecord.attributes || {})
|
|
1944
|
-
}
|
|
1945
|
-
},
|
|
1946
|
-
tags: {
|
|
1947
|
-
'ai.cloud.role': CLOUD_ROLE_NAME,
|
|
1948
|
-
'ai.cloud.roleInstance': SDK_VERSION
|
|
1949
|
-
}
|
|
1950
|
-
};
|
|
1951
|
-
this.sendToApplicationInsights(payload);
|
|
1952
|
-
}
|
|
1953
|
-
extractInstrumentationKey() {
|
|
1954
|
-
const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
|
|
1955
|
-
return match ? match[1] : '';
|
|
1956
|
-
}
|
|
1957
|
-
convertAttributesToProperties(attributes) {
|
|
1958
|
-
const properties = {};
|
|
1959
|
-
Object.entries(attributes || {}).forEach(([key, value]) => {
|
|
1960
|
-
properties[key] = String(value);
|
|
1961
|
-
});
|
|
1962
|
-
return properties;
|
|
1963
|
-
}
|
|
1964
|
-
async sendToApplicationInsights(payload) {
|
|
1965
|
-
try {
|
|
1966
|
-
const ingestionEndpoint = this.extractIngestionEndpoint();
|
|
1967
|
-
if (!ingestionEndpoint) {
|
|
1968
|
-
console.debug('No ingestion endpoint found in connection string');
|
|
1969
|
-
return;
|
|
1970
|
-
}
|
|
1971
|
-
const url = `${ingestionEndpoint}/v2/track`;
|
|
1972
|
-
const response = await fetch(url, {
|
|
1973
|
-
method: 'POST',
|
|
1974
|
-
headers: {
|
|
1975
|
-
'Content-Type': 'application/json',
|
|
1976
|
-
},
|
|
1977
|
-
body: JSON.stringify(payload)
|
|
1978
|
-
});
|
|
1979
|
-
if (!response.ok) {
|
|
1980
|
-
console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
catch (error) {
|
|
1984
|
-
console.debug('Error sending event telemetry to Application Insights:', error);
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
extractIngestionEndpoint() {
|
|
1988
|
-
const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
|
|
1989
|
-
return match ? match[1] : '';
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
/**
|
|
1993
|
-
* Singleton telemetry client
|
|
1994
|
-
*/
|
|
1995
|
-
class TelemetryClient {
|
|
1996
|
-
constructor() {
|
|
1997
|
-
this.isInitialized = false;
|
|
1998
|
-
}
|
|
1999
|
-
static getInstance() {
|
|
2000
|
-
if (!TelemetryClient.instance) {
|
|
2001
|
-
TelemetryClient.instance = new TelemetryClient();
|
|
2002
|
-
}
|
|
2003
|
-
return TelemetryClient.instance;
|
|
2004
|
-
}
|
|
2005
|
-
/**
|
|
2006
|
-
* Initialize telemetry
|
|
2007
|
-
*/
|
|
2008
|
-
initialize(config) {
|
|
2009
|
-
if (this.isInitialized) {
|
|
2010
|
-
return;
|
|
2011
|
-
}
|
|
2012
|
-
this.isInitialized = true;
|
|
2013
|
-
if (config) {
|
|
2014
|
-
this.telemetryContext = config;
|
|
2015
|
-
}
|
|
2016
|
-
try {
|
|
2017
|
-
const connectionString = this.getConnectionString();
|
|
2018
|
-
if (!connectionString) {
|
|
2019
|
-
return;
|
|
2020
|
-
}
|
|
2021
|
-
this.setupTelemetryProvider(connectionString);
|
|
2022
|
-
}
|
|
2023
|
-
catch (error) {
|
|
2024
|
-
// Silent failure - telemetry errors shouldn't break functionality
|
|
2025
|
-
console.debug('Failed to initialize OpenTelemetry:', error);
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
getConnectionString() {
|
|
2029
|
-
const connectionString = CONNECTION_STRING;
|
|
2030
|
-
return connectionString;
|
|
2031
|
-
}
|
|
2032
|
-
setupTelemetryProvider(connectionString) {
|
|
2033
|
-
const exporter = new ApplicationInsightsEventExporter(connectionString);
|
|
2034
|
-
const processor = new BatchLogRecordProcessor(exporter);
|
|
2035
|
-
this.logProvider = new LoggerProvider({
|
|
2036
|
-
processors: [processor]
|
|
2037
|
-
});
|
|
2038
|
-
this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
|
|
2039
|
-
}
|
|
2040
|
-
/**
|
|
2041
|
-
* Track a telemetry event
|
|
2042
|
-
*/
|
|
2043
|
-
track(eventName, name, extraAttributes = {}) {
|
|
2044
|
-
try {
|
|
2045
|
-
// Skip if logger not initialized
|
|
2046
|
-
if (!this.logger) {
|
|
2047
|
-
return;
|
|
2048
|
-
}
|
|
2049
|
-
const finalDisplayName = name || eventName;
|
|
2050
|
-
const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
|
|
2051
|
-
// Emit as log
|
|
2052
|
-
this.logger.emit({
|
|
2053
|
-
body: finalDisplayName,
|
|
2054
|
-
attributes: attributes,
|
|
2055
|
-
timestamp: Date.now(),
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
catch (error) {
|
|
2059
|
-
// Silent failure
|
|
2060
|
-
console.debug('Failed to track telemetry event:', error);
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
/**
|
|
2064
|
-
* Get enriched attributes for telemetry events
|
|
2065
|
-
*/
|
|
2066
|
-
getEnrichedAttributes(extraAttributes, eventName) {
|
|
2067
|
-
const attributes = {
|
|
2068
|
-
[APP_NAME]: SDK_SERVICE_NAME,
|
|
2069
|
-
[VERSION]: SDK_VERSION,
|
|
2070
|
-
[SERVICE]: eventName,
|
|
2071
|
-
[CLOUD_URL]: this.createCloudUrl(),
|
|
2072
|
-
[CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
|
|
2073
|
-
[CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
|
|
2074
|
-
[CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
|
|
2075
|
-
[CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
|
|
2076
|
-
...extraAttributes,
|
|
2077
|
-
};
|
|
2078
|
-
return attributes;
|
|
2079
|
-
}
|
|
2080
|
-
/**
|
|
2081
|
-
* Create cloud URL from base URL, organization ID, and tenant ID
|
|
2082
|
-
*/
|
|
2083
|
-
createCloudUrl() {
|
|
2084
|
-
const baseUrl = this.telemetryContext?.baseUrl;
|
|
2085
|
-
const orgId = this.telemetryContext?.orgName;
|
|
2086
|
-
const tenantId = this.telemetryContext?.tenantName;
|
|
2087
|
-
if (!baseUrl || !orgId || !tenantId) {
|
|
2088
|
-
return UNKNOWN;
|
|
2089
|
-
}
|
|
2090
|
-
return `${baseUrl}/${orgId}/${tenantId}`;
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
// Export singleton instance
|
|
2094
|
-
const telemetryClient = TelemetryClient.getInstance();
|
|
1886
|
+
* SDK Telemetry constants.
|
|
1887
|
+
*
|
|
1888
|
+
* Only the SDK's identity (version, service name, role name, …) lives
|
|
1889
|
+
* here. The Application Insights connection string is injected into
|
|
1890
|
+
* `@uipath/core-telemetry` itself at publish time, and the generic attribute
|
|
1891
|
+
* keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
|
|
1892
|
+
* `@uipath/core-telemetry` and consumed there — they are not part of the
|
|
1893
|
+
* SDK's public API.
|
|
1894
|
+
*/
|
|
1895
|
+
/** SDK version placeholder — patched by the SDK publish workflow. */
|
|
1896
|
+
const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
|
|
2095
1897
|
|
|
2096
1898
|
/**
|
|
2097
|
-
*
|
|
2098
|
-
*/
|
|
2099
|
-
/**
|
|
2100
|
-
* Common tracking logic shared between method and function decorators
|
|
2101
|
-
*/
|
|
2102
|
-
function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
|
|
2103
|
-
return function (...args) {
|
|
2104
|
-
// Determine if we should track this call
|
|
2105
|
-
let shouldTrack = true;
|
|
2106
|
-
if (opts.condition !== undefined) {
|
|
2107
|
-
if (typeof opts.condition === 'function') {
|
|
2108
|
-
shouldTrack = opts.condition.apply(this, args);
|
|
2109
|
-
}
|
|
2110
|
-
else {
|
|
2111
|
-
shouldTrack = opts.condition;
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
// Track the event if enabled
|
|
2115
|
-
if (shouldTrack) {
|
|
2116
|
-
// Use the full name provided in the decorator (e.g., "Queue.GetAll")
|
|
2117
|
-
const serviceMethod = typeof nameOrOptions === 'string'
|
|
2118
|
-
? nameOrOptions
|
|
2119
|
-
: fallbackName;
|
|
2120
|
-
// Use 'Sdk.Run' as the name and serviceMethod as the service
|
|
2121
|
-
telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
|
|
2122
|
-
}
|
|
2123
|
-
// Execute the original function
|
|
2124
|
-
return originalFunction.apply(this, args);
|
|
2125
|
-
};
|
|
2126
|
-
}
|
|
2127
|
-
/**
|
|
2128
|
-
* Track decorator that can be used to automatically track function calls
|
|
2129
|
-
*
|
|
2130
|
-
* Usage:
|
|
2131
|
-
* @track("Service.Method")
|
|
2132
|
-
* function myFunction() { ... }
|
|
1899
|
+
* UiPath TypeScript SDK Telemetry
|
|
2133
1900
|
*
|
|
2134
|
-
*
|
|
2135
|
-
*
|
|
2136
|
-
*
|
|
2137
|
-
*
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
function track(nameOrOptions, options) {
|
|
2147
|
-
return function decorator(_target, propertyKey, descriptor) {
|
|
2148
|
-
const opts = typeof nameOrOptions === 'object' ? nameOrOptions : {};
|
|
2149
|
-
if (descriptor && typeof descriptor.value === 'function') {
|
|
2150
|
-
// Method decorator
|
|
2151
|
-
descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
|
|
2152
|
-
return descriptor;
|
|
2153
|
-
}
|
|
2154
|
-
// Function decorator
|
|
2155
|
-
return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
|
|
2156
|
-
};
|
|
2157
|
-
}
|
|
1901
|
+
* Constructs the SDK's own `TelemetryClient` and binds the SDK-local
|
|
1902
|
+
* `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
|
|
1903
|
+
* does this independently, so events carry their own consumer's identity
|
|
1904
|
+
* and tenant context.
|
|
1905
|
+
*/
|
|
1906
|
+
// Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
|
|
1907
|
+
// same `TelemetryClient` instance at runtime. A single `initialize(...)`
|
|
1908
|
+
// from the `UiPath` constructor therefore wires up `@track` decorators
|
|
1909
|
+
// across every subpath bundle (`assets`, `feedback`, `tasks`, …).
|
|
1910
|
+
const sdkClient = getOrCreateClient(CLOUD_ROLE_NAME);
|
|
1911
|
+
const track = createTrack(sdkClient);
|
|
1912
|
+
createTrackEvent(sdkClient);
|
|
2158
1913
|
|
|
2159
1914
|
/**
|
|
2160
1915
|
* Service for interacting with UiPath Orchestrator Assets API
|