@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
|
@@ -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.
|
|
@@ -475,277 +475,33 @@ const BUCKET_TOKEN_PARAMS = {
|
|
|
475
475
|
};
|
|
476
476
|
|
|
477
477
|
/**
|
|
478
|
-
* SDK Telemetry constants
|
|
478
|
+
* SDK Telemetry constants.
|
|
479
|
+
*
|
|
480
|
+
* Only the SDK's identity (version, service name, role name, …) lives
|
|
481
|
+
* here. The Application Insights connection string is injected into
|
|
482
|
+
* `@uipath/core-telemetry` itself at publish time, and the generic attribute
|
|
483
|
+
* keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
|
|
484
|
+
* `@uipath/core-telemetry` and consumed there — they are not part of the
|
|
485
|
+
* SDK's public API.
|
|
479
486
|
*/
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
// SDK Version placeholder
|
|
483
|
-
const SDK_VERSION = "1.3.8";
|
|
484
|
-
const VERSION = "Version";
|
|
485
|
-
const SERVICE = "Service";
|
|
486
|
-
const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
|
|
487
|
-
const CLOUD_TENANT_NAME = "CloudTenantName";
|
|
488
|
-
const CLOUD_URL = "CloudUrl";
|
|
489
|
-
const CLOUD_CLIENT_ID = "CloudClientId";
|
|
490
|
-
const CLOUD_REDIRECT_URI = "CloudRedirectUri";
|
|
491
|
-
const APP_NAME = "ApplicationName";
|
|
492
|
-
const CLOUD_ROLE_NAME = "uipath-ts-sdk";
|
|
493
|
-
// Service and logger names
|
|
494
|
-
const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
|
|
495
|
-
const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
|
|
496
|
-
// Event names
|
|
497
|
-
const SDK_RUN_EVENT = "Sdk.Run";
|
|
498
|
-
// Default value for unknown/empty attributes
|
|
499
|
-
const UNKNOWN = "";
|
|
487
|
+
/** SDK version placeholder — patched by the SDK publish workflow. */
|
|
488
|
+
const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
|
|
500
489
|
|
|
501
490
|
/**
|
|
502
|
-
*
|
|
503
|
-
*/
|
|
504
|
-
class ApplicationInsightsEventExporter {
|
|
505
|
-
constructor(connectionString) {
|
|
506
|
-
this.connectionString = connectionString;
|
|
507
|
-
}
|
|
508
|
-
export(logs, resultCallback) {
|
|
509
|
-
try {
|
|
510
|
-
logs.forEach(logRecord => {
|
|
511
|
-
this.sendAsCustomEvent(logRecord);
|
|
512
|
-
});
|
|
513
|
-
resultCallback({ code: 0 });
|
|
514
|
-
}
|
|
515
|
-
catch (error) {
|
|
516
|
-
console.debug('Failed to export logs to Application Insights:', error);
|
|
517
|
-
resultCallback({ code: 2, error });
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
shutdown() {
|
|
521
|
-
return Promise.resolve();
|
|
522
|
-
}
|
|
523
|
-
sendAsCustomEvent(logRecord) {
|
|
524
|
-
// Get event name from body or attributes
|
|
525
|
-
const eventName = logRecord.body || SDK_RUN_EVENT;
|
|
526
|
-
const payload = {
|
|
527
|
-
name: 'Microsoft.ApplicationInsights.Event',
|
|
528
|
-
time: new Date().toISOString(),
|
|
529
|
-
iKey: this.extractInstrumentationKey(),
|
|
530
|
-
data: {
|
|
531
|
-
baseType: 'EventData',
|
|
532
|
-
baseData: {
|
|
533
|
-
ver: 2,
|
|
534
|
-
name: eventName,
|
|
535
|
-
properties: this.convertAttributesToProperties(logRecord.attributes || {})
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
tags: {
|
|
539
|
-
'ai.cloud.role': CLOUD_ROLE_NAME,
|
|
540
|
-
'ai.cloud.roleInstance': SDK_VERSION
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
this.sendToApplicationInsights(payload);
|
|
544
|
-
}
|
|
545
|
-
extractInstrumentationKey() {
|
|
546
|
-
const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
|
|
547
|
-
return match ? match[1] : '';
|
|
548
|
-
}
|
|
549
|
-
convertAttributesToProperties(attributes) {
|
|
550
|
-
const properties = {};
|
|
551
|
-
Object.entries(attributes || {}).forEach(([key, value]) => {
|
|
552
|
-
properties[key] = String(value);
|
|
553
|
-
});
|
|
554
|
-
return properties;
|
|
555
|
-
}
|
|
556
|
-
async sendToApplicationInsights(payload) {
|
|
557
|
-
try {
|
|
558
|
-
const ingestionEndpoint = this.extractIngestionEndpoint();
|
|
559
|
-
if (!ingestionEndpoint) {
|
|
560
|
-
console.debug('No ingestion endpoint found in connection string');
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
const url = `${ingestionEndpoint}/v2/track`;
|
|
564
|
-
const response = await fetch(url, {
|
|
565
|
-
method: 'POST',
|
|
566
|
-
headers: {
|
|
567
|
-
'Content-Type': 'application/json',
|
|
568
|
-
},
|
|
569
|
-
body: JSON.stringify(payload)
|
|
570
|
-
});
|
|
571
|
-
if (!response.ok) {
|
|
572
|
-
console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
catch (error) {
|
|
576
|
-
console.debug('Error sending event telemetry to Application Insights:', error);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
extractIngestionEndpoint() {
|
|
580
|
-
const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
|
|
581
|
-
return match ? match[1] : '';
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Singleton telemetry client
|
|
586
|
-
*/
|
|
587
|
-
class TelemetryClient {
|
|
588
|
-
constructor() {
|
|
589
|
-
this.isInitialized = false;
|
|
590
|
-
}
|
|
591
|
-
static getInstance() {
|
|
592
|
-
if (!TelemetryClient.instance) {
|
|
593
|
-
TelemetryClient.instance = new TelemetryClient();
|
|
594
|
-
}
|
|
595
|
-
return TelemetryClient.instance;
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Initialize telemetry
|
|
599
|
-
*/
|
|
600
|
-
initialize(config) {
|
|
601
|
-
if (this.isInitialized) {
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
this.isInitialized = true;
|
|
605
|
-
if (config) {
|
|
606
|
-
this.telemetryContext = config;
|
|
607
|
-
}
|
|
608
|
-
try {
|
|
609
|
-
const connectionString = this.getConnectionString();
|
|
610
|
-
if (!connectionString) {
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
this.setupTelemetryProvider(connectionString);
|
|
614
|
-
}
|
|
615
|
-
catch (error) {
|
|
616
|
-
// Silent failure - telemetry errors shouldn't break functionality
|
|
617
|
-
console.debug('Failed to initialize OpenTelemetry:', error);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
getConnectionString() {
|
|
621
|
-
const connectionString = CONNECTION_STRING;
|
|
622
|
-
return connectionString;
|
|
623
|
-
}
|
|
624
|
-
setupTelemetryProvider(connectionString) {
|
|
625
|
-
const exporter = new ApplicationInsightsEventExporter(connectionString);
|
|
626
|
-
const processor = new sdkLogs.BatchLogRecordProcessor(exporter);
|
|
627
|
-
this.logProvider = new sdkLogs.LoggerProvider({
|
|
628
|
-
processors: [processor]
|
|
629
|
-
});
|
|
630
|
-
this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Track a telemetry event
|
|
634
|
-
*/
|
|
635
|
-
track(eventName, name, extraAttributes = {}) {
|
|
636
|
-
try {
|
|
637
|
-
// Skip if logger not initialized
|
|
638
|
-
if (!this.logger) {
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
const finalDisplayName = name || eventName;
|
|
642
|
-
const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
|
|
643
|
-
// Emit as log
|
|
644
|
-
this.logger.emit({
|
|
645
|
-
body: finalDisplayName,
|
|
646
|
-
attributes: attributes,
|
|
647
|
-
timestamp: Date.now(),
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
catch (error) {
|
|
651
|
-
// Silent failure
|
|
652
|
-
console.debug('Failed to track telemetry event:', error);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Get enriched attributes for telemetry events
|
|
657
|
-
*/
|
|
658
|
-
getEnrichedAttributes(extraAttributes, eventName) {
|
|
659
|
-
const attributes = {
|
|
660
|
-
[APP_NAME]: SDK_SERVICE_NAME,
|
|
661
|
-
[VERSION]: SDK_VERSION,
|
|
662
|
-
[SERVICE]: eventName,
|
|
663
|
-
[CLOUD_URL]: this.createCloudUrl(),
|
|
664
|
-
[CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
|
|
665
|
-
[CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
|
|
666
|
-
[CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
|
|
667
|
-
[CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
|
|
668
|
-
...extraAttributes,
|
|
669
|
-
};
|
|
670
|
-
return attributes;
|
|
671
|
-
}
|
|
672
|
-
/**
|
|
673
|
-
* Create cloud URL from base URL, organization ID, and tenant ID
|
|
674
|
-
*/
|
|
675
|
-
createCloudUrl() {
|
|
676
|
-
const baseUrl = this.telemetryContext?.baseUrl;
|
|
677
|
-
const orgId = this.telemetryContext?.orgName;
|
|
678
|
-
const tenantId = this.telemetryContext?.tenantName;
|
|
679
|
-
if (!baseUrl || !orgId || !tenantId) {
|
|
680
|
-
return UNKNOWN;
|
|
681
|
-
}
|
|
682
|
-
return `${baseUrl}/${orgId}/${tenantId}`;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
// Export singleton instance
|
|
686
|
-
const telemetryClient = TelemetryClient.getInstance();
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* SDK Track decorator and function for telemetry
|
|
690
|
-
*/
|
|
691
|
-
/**
|
|
692
|
-
* Common tracking logic shared between method and function decorators
|
|
693
|
-
*/
|
|
694
|
-
function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
|
|
695
|
-
return function (...args) {
|
|
696
|
-
// Determine if we should track this call
|
|
697
|
-
let shouldTrack = true;
|
|
698
|
-
if (opts.condition !== undefined) {
|
|
699
|
-
if (typeof opts.condition === 'function') {
|
|
700
|
-
shouldTrack = opts.condition.apply(this, args);
|
|
701
|
-
}
|
|
702
|
-
else {
|
|
703
|
-
shouldTrack = opts.condition;
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
// Track the event if enabled
|
|
707
|
-
if (shouldTrack) {
|
|
708
|
-
// Use the full name provided in the decorator (e.g., "Queue.GetAll")
|
|
709
|
-
const serviceMethod = nameOrOptions
|
|
710
|
-
;
|
|
711
|
-
// Use 'Sdk.Run' as the name and serviceMethod as the service
|
|
712
|
-
telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
|
|
713
|
-
}
|
|
714
|
-
// Execute the original function
|
|
715
|
-
return originalFunction.apply(this, args);
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* Track decorator that can be used to automatically track function calls
|
|
720
|
-
*
|
|
721
|
-
* Usage:
|
|
722
|
-
* @track("Service.Method")
|
|
723
|
-
* function myFunction() { ... }
|
|
491
|
+
* UiPath TypeScript SDK Telemetry
|
|
724
492
|
*
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
728
|
-
*
|
|
729
|
-
* async create() { ... }
|
|
730
|
-
*
|
|
731
|
-
* @track("Assets.Update", { condition: false })
|
|
732
|
-
* function myFunction() { ... }
|
|
733
|
-
*
|
|
734
|
-
* @track("Processes.Start", { attributes: { customProp: "value" } })
|
|
735
|
-
* function myFunction() { ... }
|
|
493
|
+
* Constructs the SDK's own `TelemetryClient` and binds the SDK-local
|
|
494
|
+
* `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
|
|
495
|
+
* does this independently, so events carry their own consumer's identity
|
|
496
|
+
* and tenant context.
|
|
736
497
|
*/
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
// Function decorator
|
|
746
|
-
return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
|
|
747
|
-
};
|
|
748
|
-
}
|
|
498
|
+
// Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
|
|
499
|
+
// same `TelemetryClient` instance at runtime. A single `initialize(...)`
|
|
500
|
+
// from the `UiPath` constructor therefore wires up `@track` decorators
|
|
501
|
+
// across every subpath bundle (`assets`, `feedback`, `tasks`, …).
|
|
502
|
+
const sdkClient = coreTelemetry.getOrCreateClient(CLOUD_ROLE_NAME);
|
|
503
|
+
const track = coreTelemetry.createTrack(sdkClient);
|
|
504
|
+
coreTelemetry.createTrackEvent(sdkClient);
|
|
749
505
|
|
|
750
506
|
/**
|
|
751
507
|
* Maps fields for Attachment entities to ensure consistent naming
|
|
@@ -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.
|
|
@@ -473,277 +473,33 @@ const BUCKET_TOKEN_PARAMS = {
|
|
|
473
473
|
};
|
|
474
474
|
|
|
475
475
|
/**
|
|
476
|
-
* SDK Telemetry constants
|
|
476
|
+
* SDK Telemetry constants.
|
|
477
|
+
*
|
|
478
|
+
* Only the SDK's identity (version, service name, role name, …) lives
|
|
479
|
+
* here. The Application Insights connection string is injected into
|
|
480
|
+
* `@uipath/core-telemetry` itself at publish time, and the generic attribute
|
|
481
|
+
* keys (`Version`, `Service`, `CloudOrganizationName`, …) are owned by
|
|
482
|
+
* `@uipath/core-telemetry` and consumed there — they are not part of the
|
|
483
|
+
* SDK's public API.
|
|
477
484
|
*/
|
|
478
|
-
|
|
479
|
-
const
|
|
480
|
-
// SDK Version placeholder
|
|
481
|
-
const SDK_VERSION = "1.3.8";
|
|
482
|
-
const VERSION = "Version";
|
|
483
|
-
const SERVICE = "Service";
|
|
484
|
-
const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
|
|
485
|
-
const CLOUD_TENANT_NAME = "CloudTenantName";
|
|
486
|
-
const CLOUD_URL = "CloudUrl";
|
|
487
|
-
const CLOUD_CLIENT_ID = "CloudClientId";
|
|
488
|
-
const CLOUD_REDIRECT_URI = "CloudRedirectUri";
|
|
489
|
-
const APP_NAME = "ApplicationName";
|
|
490
|
-
const CLOUD_ROLE_NAME = "uipath-ts-sdk";
|
|
491
|
-
// Service and logger names
|
|
492
|
-
const SDK_SERVICE_NAME = "UiPath.TypeScript.Sdk";
|
|
493
|
-
const SDK_LOGGER_NAME = "uipath-ts-sdk-telemetry";
|
|
494
|
-
// Event names
|
|
495
|
-
const SDK_RUN_EVENT = "Sdk.Run";
|
|
496
|
-
// Default value for unknown/empty attributes
|
|
497
|
-
const UNKNOWN = "";
|
|
485
|
+
/** SDK version placeholder — patched by the SDK publish workflow. */
|
|
486
|
+
const CLOUD_ROLE_NAME = 'uipath-ts-sdk';
|
|
498
487
|
|
|
499
488
|
/**
|
|
500
|
-
*
|
|
501
|
-
*/
|
|
502
|
-
class ApplicationInsightsEventExporter {
|
|
503
|
-
constructor(connectionString) {
|
|
504
|
-
this.connectionString = connectionString;
|
|
505
|
-
}
|
|
506
|
-
export(logs, resultCallback) {
|
|
507
|
-
try {
|
|
508
|
-
logs.forEach(logRecord => {
|
|
509
|
-
this.sendAsCustomEvent(logRecord);
|
|
510
|
-
});
|
|
511
|
-
resultCallback({ code: 0 });
|
|
512
|
-
}
|
|
513
|
-
catch (error) {
|
|
514
|
-
console.debug('Failed to export logs to Application Insights:', error);
|
|
515
|
-
resultCallback({ code: 2, error });
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
shutdown() {
|
|
519
|
-
return Promise.resolve();
|
|
520
|
-
}
|
|
521
|
-
sendAsCustomEvent(logRecord) {
|
|
522
|
-
// Get event name from body or attributes
|
|
523
|
-
const eventName = logRecord.body || SDK_RUN_EVENT;
|
|
524
|
-
const payload = {
|
|
525
|
-
name: 'Microsoft.ApplicationInsights.Event',
|
|
526
|
-
time: new Date().toISOString(),
|
|
527
|
-
iKey: this.extractInstrumentationKey(),
|
|
528
|
-
data: {
|
|
529
|
-
baseType: 'EventData',
|
|
530
|
-
baseData: {
|
|
531
|
-
ver: 2,
|
|
532
|
-
name: eventName,
|
|
533
|
-
properties: this.convertAttributesToProperties(logRecord.attributes || {})
|
|
534
|
-
}
|
|
535
|
-
},
|
|
536
|
-
tags: {
|
|
537
|
-
'ai.cloud.role': CLOUD_ROLE_NAME,
|
|
538
|
-
'ai.cloud.roleInstance': SDK_VERSION
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
this.sendToApplicationInsights(payload);
|
|
542
|
-
}
|
|
543
|
-
extractInstrumentationKey() {
|
|
544
|
-
const match = this.connectionString.match(/InstrumentationKey=([^;]+)/);
|
|
545
|
-
return match ? match[1] : '';
|
|
546
|
-
}
|
|
547
|
-
convertAttributesToProperties(attributes) {
|
|
548
|
-
const properties = {};
|
|
549
|
-
Object.entries(attributes || {}).forEach(([key, value]) => {
|
|
550
|
-
properties[key] = String(value);
|
|
551
|
-
});
|
|
552
|
-
return properties;
|
|
553
|
-
}
|
|
554
|
-
async sendToApplicationInsights(payload) {
|
|
555
|
-
try {
|
|
556
|
-
const ingestionEndpoint = this.extractIngestionEndpoint();
|
|
557
|
-
if (!ingestionEndpoint) {
|
|
558
|
-
console.debug('No ingestion endpoint found in connection string');
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
const url = `${ingestionEndpoint}/v2/track`;
|
|
562
|
-
const response = await fetch(url, {
|
|
563
|
-
method: 'POST',
|
|
564
|
-
headers: {
|
|
565
|
-
'Content-Type': 'application/json',
|
|
566
|
-
},
|
|
567
|
-
body: JSON.stringify(payload)
|
|
568
|
-
});
|
|
569
|
-
if (!response.ok) {
|
|
570
|
-
console.debug(`Failed to send event telemetry: ${response.status} ${response.statusText}`);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
catch (error) {
|
|
574
|
-
console.debug('Error sending event telemetry to Application Insights:', error);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
extractIngestionEndpoint() {
|
|
578
|
-
const match = this.connectionString.match(/IngestionEndpoint=([^;]+)/);
|
|
579
|
-
return match ? match[1] : '';
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Singleton telemetry client
|
|
584
|
-
*/
|
|
585
|
-
class TelemetryClient {
|
|
586
|
-
constructor() {
|
|
587
|
-
this.isInitialized = false;
|
|
588
|
-
}
|
|
589
|
-
static getInstance() {
|
|
590
|
-
if (!TelemetryClient.instance) {
|
|
591
|
-
TelemetryClient.instance = new TelemetryClient();
|
|
592
|
-
}
|
|
593
|
-
return TelemetryClient.instance;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Initialize telemetry
|
|
597
|
-
*/
|
|
598
|
-
initialize(config) {
|
|
599
|
-
if (this.isInitialized) {
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
this.isInitialized = true;
|
|
603
|
-
if (config) {
|
|
604
|
-
this.telemetryContext = config;
|
|
605
|
-
}
|
|
606
|
-
try {
|
|
607
|
-
const connectionString = this.getConnectionString();
|
|
608
|
-
if (!connectionString) {
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
this.setupTelemetryProvider(connectionString);
|
|
612
|
-
}
|
|
613
|
-
catch (error) {
|
|
614
|
-
// Silent failure - telemetry errors shouldn't break functionality
|
|
615
|
-
console.debug('Failed to initialize OpenTelemetry:', error);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
getConnectionString() {
|
|
619
|
-
const connectionString = CONNECTION_STRING;
|
|
620
|
-
return connectionString;
|
|
621
|
-
}
|
|
622
|
-
setupTelemetryProvider(connectionString) {
|
|
623
|
-
const exporter = new ApplicationInsightsEventExporter(connectionString);
|
|
624
|
-
const processor = new BatchLogRecordProcessor(exporter);
|
|
625
|
-
this.logProvider = new LoggerProvider({
|
|
626
|
-
processors: [processor]
|
|
627
|
-
});
|
|
628
|
-
this.logger = this.logProvider.getLogger(SDK_LOGGER_NAME);
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* Track a telemetry event
|
|
632
|
-
*/
|
|
633
|
-
track(eventName, name, extraAttributes = {}) {
|
|
634
|
-
try {
|
|
635
|
-
// Skip if logger not initialized
|
|
636
|
-
if (!this.logger) {
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
const finalDisplayName = name || eventName;
|
|
640
|
-
const attributes = this.getEnrichedAttributes(extraAttributes, eventName);
|
|
641
|
-
// Emit as log
|
|
642
|
-
this.logger.emit({
|
|
643
|
-
body: finalDisplayName,
|
|
644
|
-
attributes: attributes,
|
|
645
|
-
timestamp: Date.now(),
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
catch (error) {
|
|
649
|
-
// Silent failure
|
|
650
|
-
console.debug('Failed to track telemetry event:', error);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Get enriched attributes for telemetry events
|
|
655
|
-
*/
|
|
656
|
-
getEnrichedAttributes(extraAttributes, eventName) {
|
|
657
|
-
const attributes = {
|
|
658
|
-
[APP_NAME]: SDK_SERVICE_NAME,
|
|
659
|
-
[VERSION]: SDK_VERSION,
|
|
660
|
-
[SERVICE]: eventName,
|
|
661
|
-
[CLOUD_URL]: this.createCloudUrl(),
|
|
662
|
-
[CLOUD_ORGANIZATION_NAME]: this.telemetryContext?.orgName || UNKNOWN,
|
|
663
|
-
[CLOUD_TENANT_NAME]: this.telemetryContext?.tenantName || UNKNOWN,
|
|
664
|
-
[CLOUD_REDIRECT_URI]: this.telemetryContext?.redirectUri || UNKNOWN,
|
|
665
|
-
[CLOUD_CLIENT_ID]: this.telemetryContext?.clientId || UNKNOWN,
|
|
666
|
-
...extraAttributes,
|
|
667
|
-
};
|
|
668
|
-
return attributes;
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Create cloud URL from base URL, organization ID, and tenant ID
|
|
672
|
-
*/
|
|
673
|
-
createCloudUrl() {
|
|
674
|
-
const baseUrl = this.telemetryContext?.baseUrl;
|
|
675
|
-
const orgId = this.telemetryContext?.orgName;
|
|
676
|
-
const tenantId = this.telemetryContext?.tenantName;
|
|
677
|
-
if (!baseUrl || !orgId || !tenantId) {
|
|
678
|
-
return UNKNOWN;
|
|
679
|
-
}
|
|
680
|
-
return `${baseUrl}/${orgId}/${tenantId}`;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
// Export singleton instance
|
|
684
|
-
const telemetryClient = TelemetryClient.getInstance();
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* SDK Track decorator and function for telemetry
|
|
688
|
-
*/
|
|
689
|
-
/**
|
|
690
|
-
* Common tracking logic shared between method and function decorators
|
|
691
|
-
*/
|
|
692
|
-
function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, opts) {
|
|
693
|
-
return function (...args) {
|
|
694
|
-
// Determine if we should track this call
|
|
695
|
-
let shouldTrack = true;
|
|
696
|
-
if (opts.condition !== undefined) {
|
|
697
|
-
if (typeof opts.condition === 'function') {
|
|
698
|
-
shouldTrack = opts.condition.apply(this, args);
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
shouldTrack = opts.condition;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
// Track the event if enabled
|
|
705
|
-
if (shouldTrack) {
|
|
706
|
-
// Use the full name provided in the decorator (e.g., "Queue.GetAll")
|
|
707
|
-
const serviceMethod = nameOrOptions
|
|
708
|
-
;
|
|
709
|
-
// Use 'Sdk.Run' as the name and serviceMethod as the service
|
|
710
|
-
telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
|
|
711
|
-
}
|
|
712
|
-
// Execute the original function
|
|
713
|
-
return originalFunction.apply(this, args);
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* Track decorator that can be used to automatically track function calls
|
|
718
|
-
*
|
|
719
|
-
* Usage:
|
|
720
|
-
* @track("Service.Method")
|
|
721
|
-
* function myFunction() { ... }
|
|
489
|
+
* UiPath TypeScript SDK Telemetry
|
|
722
490
|
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
* async create() { ... }
|
|
728
|
-
*
|
|
729
|
-
* @track("Assets.Update", { condition: false })
|
|
730
|
-
* function myFunction() { ... }
|
|
731
|
-
*
|
|
732
|
-
* @track("Processes.Start", { attributes: { customProp: "value" } })
|
|
733
|
-
* function myFunction() { ... }
|
|
491
|
+
* Constructs the SDK's own `TelemetryClient` and binds the SDK-local
|
|
492
|
+
* `track` / `trackEvent` to it. Each consumer of `@uipath/core-telemetry`
|
|
493
|
+
* does this independently, so events carry their own consumer's identity
|
|
494
|
+
* and tenant context.
|
|
734
495
|
*/
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
// Function decorator
|
|
744
|
-
return (originalFunction) => createTrackedFunction(originalFunction, nameOrOptions, originalFunction.name || 'unknown_function', opts);
|
|
745
|
-
};
|
|
746
|
-
}
|
|
496
|
+
// Keyed by `CLOUD_ROLE_NAME` so every SDK subpath bundle resolves to the
|
|
497
|
+
// same `TelemetryClient` instance at runtime. A single `initialize(...)`
|
|
498
|
+
// from the `UiPath` constructor therefore wires up `@track` decorators
|
|
499
|
+
// across every subpath bundle (`assets`, `feedback`, `tasks`, …).
|
|
500
|
+
const sdkClient = getOrCreateClient(CLOUD_ROLE_NAME);
|
|
501
|
+
const track = createTrack(sdkClient);
|
|
502
|
+
createTrackEvent(sdkClient);
|
|
747
503
|
|
|
748
504
|
/**
|
|
749
505
|
* Maps fields for Attachment entities to ensure consistent naming
|