|
1 |
| -//import * from "./otelapis"; |
2 |
| -/*instrumentation.ts*/ |
| 1 | +console.log("Hello agent") |
| 2 | +import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api'; |
3 | 3 | import { NodeSDK } from '@opentelemetry/sdk-node';
|
4 | 4 | import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node';
|
5 | 5 | import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
6 | 6 | import { PeriodicExportingMetricReader, ConsoleMetricExporter,} from '@opentelemetry/sdk-metrics';
|
7 |
| - |
8 | 7 | import * as opentelemetry from '@opentelemetry/api';
|
9 | 8 | import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
10 | 9 | import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
|
11 |
| - |
12 |
| - //Specify zipkin url. default url is http://localhost:9411/api/v2/spans |
13 |
| - const zipkinUrl = 'http://localhost'; |
14 |
| - const zipkinPort = '9411'; |
15 |
| - const zipkinPath = '/api/v2/spans'; |
16 |
| - const zipkinURL = `${zipkinUrl}:${zipkinPort}${zipkinPath}`; |
17 |
| - |
18 |
| - const options = { |
| 10 | +import { Resource } from '@opentelemetry/resources'; |
| 11 | +import { |
| 12 | + ATTR_SERVICE_NAME, |
| 13 | + ATTR_SERVICE_VERSION, |
| 14 | +} from '@opentelemetry/semantic-conventions'; |
| 15 | +import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; |
| 16 | + |
| 17 | +//Specify zipkin url. default url is http://localhost:9411/api/v2/spans |
| 18 | +const zipkinUrl = 'http://localhost'; |
| 19 | +const zipkinPort = '9411'; |
| 20 | +const zipkinPath = '/api/v2/spans'; |
| 21 | +const zipkinURL = `${zipkinUrl}:${zipkinPort}${zipkinPath}`; |
| 22 | + |
| 23 | +const options = { |
19 | 24 | headers: {
|
20 | 25 | 'module': 'mainai16z',
|
21 | 26 | },
|
22 | 27 | url: zipkinURL,
|
23 |
| - //serviceName: 'your-application-name', |
24 |
| - |
| 28 | + serviceName: 'ai16z', |
| 29 | + |
25 | 30 | // optional interceptor
|
26 | 31 | getExportRequestHeaders: () => {
|
27 |
| - return { |
28 |
| - 'module': 'mainai16z', |
29 |
| - } |
| 32 | + return { |
| 33 | + 'module': 'mainai16z', |
| 34 | + } |
30 | 35 | }
|
31 |
| - } |
| 36 | +} |
32 | 37 | const traceExporter_zipkin = new ZipkinExporter(options);
|
33 | 38 | // parts from https://stackoverflow.com/questions/71654897/opentelemetry-typescript-project-zipkin-exporter
|
34 | 39 |
|
35 | 40 | const sdk = new NodeSDK({
|
| 41 | + resource: new Resource({ |
| 42 | + [ATTR_SERVICE_NAME]: 'eliza-agent', |
| 43 | + [ATTR_SERVICE_VERSION]: '1.0', |
| 44 | + }), |
36 | 45 | //traceExporter: new ConsoleSpanExporter(),
|
37 | 46 | traceExporter: traceExporter_zipkin,
|
38 |
| - metricReader: new PeriodicExportingMetricReader({ |
39 |
| - exporter: new ConsoleMetricExporter(), |
40 |
| - }), |
41 |
| - instrumentations: [getNodeAutoInstrumentations()], |
| 47 | + instrumentations: [getNodeAutoInstrumentations(), |
| 48 | + new HttpInstrumentation() |
| 49 | + |
| 50 | + ], |
42 | 51 | });
|
43 | 52 |
|
44 |
| -sdk.start(); |
| 53 | +// For troubleshooting, set the log level to DiagLogLevel.DEBUG |
| 54 | +diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL); |
| 55 | + |
| 56 | +console.log(sdk.start()); |
| 57 | + |
45 | 58 |
|
46 | 59 | import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
|
47 | 60 | import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
|
@@ -125,7 +138,7 @@ export const wait = (minTime: number = 1000, maxTime: number = 3000) => {
|
125 | 138 | const logFetch = async (url: string, options: any) => {
|
126 | 139 | elizaLogger.debug(`Fetching ${url}`);
|
127 | 140 | // Disabled to avoid disclosure of sensitive information such as API keys
|
128 |
| - // elizaLogger.debug(JSON.stringify(options, null, 2)); |
| 141 | + elizaLogger.debug(JSON.stringify(options, null, 2)); |
129 | 142 | return fetch(url, options);
|
130 | 143 | };
|
131 | 144 |
|
|
0 commit comments