Skip to content

Commit

Permalink
start of tracing
Browse files Browse the repository at this point in the history
Not working just yet, the otel is not integrated yet in the server
but enough information is being collected that I want to share these
results.

Together with the
meta-introspector/eliza-starter#2
this allows for debugging of the server.
  • Loading branch information
mike dupont committed Jan 2, 2025
1 parent 46412e8 commit 2d9cd8b
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 78 deletions.
13 changes: 7 additions & 6 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"main": "src/index.ts",
"type": "module",
"scripts": {
"start": "node --loader ts-node/esm src/index.ts",
"skip": "--trace-deprecation ,node.async_hooks,,,node.threadpoolwork.sync,node.threadpoolwork.async,node.dns.native,,node.promises.rejections,,node.module_timer,node.perf,node.perf.usertiming,node.perf.timerify --trace-warnings",
"start": "node --trace-event-categories node,node.bootstrap,node.console,node.vm.script,v8,node.http,node.net.native,node.environment,node.fs.sync,node.fs_dir.sync,node.fs.async,node.fs_dir.async --loader ts-node/esm src/index.ts",
"dev": "node --loader ts-node/esm src/index.ts",
"check-types": "tsc --noEmit",
"test": "jest"
Expand Down Expand Up @@ -49,19 +50,19 @@
"@elizaos/plugin-intiface": "workspace:*",
"@elizaos/plugin-multiversx": "workspace:*",
"@elizaos/plugin-near": "workspace:*",
"@elizaos/plugin-nft-generation": "workspace:*",
"@elizaos/plugin-node": "workspace:*",
"@elizaos/plugin-solana": "workspace:*",
"@elizaos/plugin-starknet": "workspace:*",
"@elizaos/plugin-story": "workspace:*",
"@elizaos/plugin-sui": "workspace:*",
"@elizaos/plugin-tee": "workspace:*",
"@elizaos/plugin-ton": "workspace:*",
"@elizaos/plugin-twitter": "workspace:*",
"@elizaos/plugin-zksync-era": "workspace:*",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.55.0",
"@opentelemetry/exporter-zipkin": "^1.30.0",
"@opentelemetry/instrumentation-express": "^0.47.0",
"@opentelemetry/instrumentation-fetch": "^0.57.0",
"@opentelemetry/instrumentation-fs": "^0.19.0",
"@opentelemetry/instrumentation-http": "^0.57.0",
"@opentelemetry/instrumentation-pg": "^0.50.0",
"@opentelemetry/sdk-metrics": "^1.30.0",
"@opentelemetry/sdk-node": "^0.57.0",
"@opentelemetry/sdk-trace-node": "^1.30.0",
Expand Down
59 changes: 36 additions & 23 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
//import * from "./otelapis";
/*instrumentation.ts*/
console.log("Hello agent")
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { PeriodicExportingMetricReader, ConsoleMetricExporter,} from '@opentelemetry/sdk-metrics';

import * as opentelemetry from '@opentelemetry/api';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';

//Specify zipkin url. default url is http://localhost:9411/api/v2/spans
const zipkinUrl = 'http://localhost';
const zipkinPort = '9411';
const zipkinPath = '/api/v2/spans';
const zipkinURL = `${zipkinUrl}:${zipkinPort}${zipkinPath}`;

const options = {
import { Resource } from '@opentelemetry/resources';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
} from '@opentelemetry/semantic-conventions';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';

//Specify zipkin url. default url is http://localhost:9411/api/v2/spans
const zipkinUrl = 'http://localhost';
const zipkinPort = '9411';
const zipkinPath = '/api/v2/spans';
const zipkinURL = `${zipkinUrl}:${zipkinPort}${zipkinPath}`;

const options = {
headers: {
'module': 'mainai16z',
},
url: zipkinURL,
//serviceName: 'your-application-name',

serviceName: 'ai16z',
// optional interceptor
getExportRequestHeaders: () => {
return {
'module': 'mainai16z',
}
return {
'module': 'mainai16z',
}
}
}
}
const traceExporter_zipkin = new ZipkinExporter(options);
// parts from https://stackoverflow.com/questions/71654897/opentelemetry-typescript-project-zipkin-exporter

const sdk = new NodeSDK({
resource: new Resource({
[ATTR_SERVICE_NAME]: 'eliza-agent',
[ATTR_SERVICE_VERSION]: '1.0',
}),
//traceExporter: new ConsoleSpanExporter(),
traceExporter: traceExporter_zipkin,
metricReader: new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
}),
instrumentations: [getNodeAutoInstrumentations()],
instrumentations: [getNodeAutoInstrumentations(),
new HttpInstrumentation()

],
});

sdk.start();
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL);

console.log(sdk.start());


import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
Expand Down Expand Up @@ -125,7 +138,7 @@ export const wait = (minTime: number = 1000, maxTime: number = 3000) => {
const logFetch = async (url: string, options: any) => {
elizaLogger.debug(`Fetching ${url}`);
// Disabled to avoid disclosure of sensitive information such as API keys
// elizaLogger.debug(JSON.stringify(options, null, 2));
elizaLogger.debug(JSON.stringify(options, null, 2));
return fetch(url, options);
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build-docker": "turbo run build",
"cleanstart": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && pnpm --filter \"@elizaos/agent\" start --isRoot",
"cleanstart:debug": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot",
"start": "pnpm --filter \"@elizaos/agent\" start --isRoot",
"start": "pnpm --filter \"@elizaos/agent\" start --isRoot --characters=characters/eliza.character.json",
"start:client": "pnpm --dir client dev",
"start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot",
"dev": "bash ./scripts/dev.sh",
Expand Down
2 changes: 1 addition & 1 deletion packages/client-direct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class DirectClient {
content,
createdAt: Date.now(),
};

console.log("Memory",memory);
await runtime.messageManager.addEmbeddingToMemory(memory);
await runtime.messageManager.createMemory(memory);

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ class ElizaLogger {
debug(...strings) {
if (!this.verbose) {
// for diagnosing verbose logging issues
// console.log(
// "[ElizaLogger] Debug message suppressed (verbose=false):",
// ...strings
// );
console.log(
"[ElizaLogger] Debug message suppressed (verbose=false):",
...strings
);
return;
}
this.#logWithStyle(strings, {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class MemoryManager implements IMemoryManager {
return memory;
}

const memoryText = memory.content.text;
const memoryText = memory?.content?.text;

// Validate memory has text content
if (!memoryText) {
Expand Down
Loading

0 comments on commit 2d9cd8b

Please sign in to comment.