@@ -21,6 +21,7 @@ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
21
21
import { wrapTracer } from '@opentelemetry/api/experimental' ;
22
22
23
23
//Specify zipkin url. default url is http://localhost:9411/api/v2/spans
24
+ // docker run -d -p 9411:9411 openzipkin/zipkin
24
25
const zipkinUrl = 'http://localhost' ;
25
26
const zipkinPort = '9411' ;
26
27
const zipkinPath = '/api/v2/spans' ;
@@ -89,24 +90,10 @@ try {
89
90
} catch ( error ) {
90
91
elizaLogger . log ( "ERROR" , error )
91
92
}
92
- // const sdk = new NodeSDK({ resource: new Resource({
93
-
94
- //const tracer=opentelemetry.trace.getTracer('ai16z');
95
-
96
-
97
93
94
+ // wrapper
98
95
const tracer = wrapTracer ( opentelemetry . trace . getTracer ( 'ai16z-agent' ) )
99
96
100
- // //traceExporter: new ConsoleSpanExporter(),
101
- // traceExporter: myExporter,
102
- // //traceExporter_zipkin
103
- // instrumentations: [, new HttpInstrumentation() ],
104
- // });
105
- // // For troubleshooting, set the log level to DiagLogLevel.DEBUG
106
- // diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL);
107
- // console.log(sdk.start());
108
-
109
-
110
97
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres" ;
111
98
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite" ;
112
99
import { AutoClientInterface } from "@elizaos/client-auto" ;
@@ -220,7 +207,7 @@ export function parseArguments(): {
220
207
221
208
function tryLoadFile ( filePath : string ) : string | null {
222
209
elizaLogger . log ( `tryLoadFile filePath: ${ filePath } ` ) ;
223
- return tracer . withActiveSpan ( ' tryLoadFile' , ( ) => {
210
+ return tracer . withActiveSpan ( ` tryLoadFile filePath: ${ filePath } ` , ( ) => {
224
211
try {
225
212
const ret = fs . readFileSync ( filePath , "utf8" ) ;
226
213
return ret ;
@@ -473,6 +460,7 @@ export function getTokenForProvider(
473
460
}
474
461
475
462
function initializeDatabase ( dataDir : string ) {
463
+ return tracer . withActiveSpan ( 'initializeDatabase' , ( ) => {
476
464
if ( process . env . POSTGRES_URL ) {
477
465
elizaLogger . info ( "Initializing PostgreSQL connection..." ) ;
478
466
const db = new PostgresDatabaseAdapter ( {
@@ -499,13 +487,16 @@ function initializeDatabase(dataDir: string) {
499
487
const db = new SqliteDatabaseAdapter ( new Database ( filePath ) ) ;
500
488
return db ;
501
489
}
490
+ } )
502
491
}
503
492
504
493
// also adds plugins from character file into the runtime
505
494
export async function initializeClients (
506
495
character : Character ,
507
496
runtime : IAgentRuntime
508
497
) {
498
+
499
+ return await tracer . withActiveSpan ( 'initializeClients' , async ( ) => {
509
500
// each client can only register once
510
501
// and if we want two we can explicitly support it
511
502
const clients : Record < string , any > = { } ;
@@ -590,11 +581,15 @@ export async function initializeClients(
590
581
}
591
582
}
592
583
584
+
593
585
return clients ;
586
+ } ) ;
594
587
}
595
588
596
589
function getSecret ( character : Character , secret : string ) {
597
- return character . settings ?. secrets ?. [ secret ] || process . env [ secret ] ;
590
+ return tracer . withActiveSpan ( 'getSecret' , ( ) => {
591
+ return character . settings ?. secrets ?. [ secret ] || process . env [ secret ] ;
592
+ } ) ;
598
593
}
599
594
600
595
let nodePlugin : any | undefined ;
@@ -605,6 +600,8 @@ export async function createAgent(
605
600
cache : ICacheManager ,
606
601
token : string
607
602
) : Promise < AgentRuntime > {
603
+ return await tracer . withActiveSpan ( 'createAgent' , async ( ) => {
604
+
608
605
elizaLogger . success (
609
606
elizaLogger . successesTitle ,
610
607
"Creating runtime for character" ,
@@ -727,18 +724,23 @@ export async function createAgent(
727
724
cacheManager : cache ,
728
725
fetch : logFetch ,
729
726
} ) ;
727
+ } ) ;
730
728
}
731
729
732
- function initializeFsCache ( baseDir : string , character : Character ) {
730
+ function initializeFsCache ( baseDir : string , character : Character ) {
731
+ return tracer . withActiveSpan ( 'initializeFsCache' , ( ) => {
733
732
const cacheDir = path . resolve ( baseDir , character . id , "cache" ) ;
734
733
735
734
const cache = new CacheManager ( new FsCacheAdapter ( cacheDir ) ) ;
736
- return cache ;
735
+ return cache ;
736
+ } ) ;
737
737
}
738
738
739
- function initializeDbCache ( character : Character , db : IDatabaseCacheAdapter ) {
740
- const cache = new CacheManager ( new DbCacheAdapter ( db , character . id ) ) ;
741
- return cache ;
739
+ function initializeDbCache ( character : Character , db : IDatabaseCacheAdapter ) {
740
+ return tracer . withActiveSpan ( 'initializeDbCache' , ( ) => {
741
+ const cache = new CacheManager ( new DbCacheAdapter ( db , character . id ) ) ;
742
+ return cache ;
743
+ } ) ;
742
744
}
743
745
744
746
function initializeCache (
@@ -747,6 +749,7 @@ function initializeCache(
747
749
baseDir ?: string ,
748
750
db ?: IDatabaseCacheAdapter
749
751
) {
752
+ return tracer . withActiveSpan ( 'initializeCache' , ( ) => {
750
753
switch ( cacheStore ) {
751
754
case CacheStore . REDIS :
752
755
if ( process . env . REDIS_URL ) {
@@ -778,12 +781,14 @@ function initializeCache(
778
781
`Invalid cache store: ${ cacheStore } or required configuration missing.`
779
782
) ;
780
783
}
784
+ } ) ;
781
785
}
782
786
783
787
async function startAgent (
784
788
character : Character ,
785
789
directClient : DirectClient
786
790
) : Promise < AgentRuntime > {
791
+
787
792
let db : IDatabaseAdapter & IDatabaseCacheAdapter ;
788
793
try {
789
794
character . id ??= stringToUuid ( character . name ) ;
0 commit comments