|
1 |
| -console.log("Hello agent") |
| 1 | +// |
| 2 | +import { registerInstrumentations } from '@opentelemetry/instrumentation'; |
| 3 | +import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; |
2 | 4 | import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
|
3 |
| -import { NodeSDK } from '@opentelemetry/sdk-node'; |
| 5 | +//import { NodeSDK } from '@opentelemetry/sdk-node'; |
| 6 | +import { SpanExporter, Span } from '@opentelemetry/sdk-trace-base'; |
| 7 | +// , ExportResult |
4 | 8 | import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node';
|
5 | 9 | import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
6 | 10 | import { PeriodicExportingMetricReader, ConsoleMetricExporter,} from '@opentelemetry/sdk-metrics';
|
@@ -35,25 +39,80 @@ const options = {
|
35 | 39 | }
|
36 | 40 | }
|
37 | 41 | const traceExporter_zipkin = new ZipkinExporter(options);
|
38 |
| -// parts from https://stackoverflow.com/questions/71654897/opentelemetry-typescript-project-zipkin-exporter |
39 |
| - |
40 |
| -const sdk = new NodeSDK({ |
41 |
| - resource: new Resource({ |
42 |
| - [ATTR_SERVICE_NAME]: 'eliza-agent', |
43 |
| - [ATTR_SERVICE_VERSION]: '1.0', |
44 |
| - }), |
45 |
| - //traceExporter: new ConsoleSpanExporter(), |
46 |
| - traceExporter: traceExporter_zipkin, |
47 |
| - instrumentations: [getNodeAutoInstrumentations(), |
48 |
| - new HttpInstrumentation() |
49 |
| - |
50 |
| - ], |
51 |
| -}); |
| 42 | +const traceExporter = new ConsoleSpanExporter(); |
| 43 | + |
| 44 | + |
| 45 | +export class CustomConsoleSpanExporter implements SpanExporter { |
| 46 | + export(spans: Span[], resultCallback: (result: ExportResult) => void): void { |
| 47 | + console.log("hello1") |
| 48 | + traceExporter.export(spans,resultCallback); |
| 49 | + traceExporter.export(traceExporter_zipkin,resultCallback); |
| 50 | + for (const span of spans) { |
| 51 | + const spanData = { |
| 52 | + name: span.name, |
| 53 | + traceId: span.spanContext().traceId, |
| 54 | + spanId: span.spanContext().spanId, |
| 55 | + startTime: span.startTime, |
| 56 | + endTime: span.endTime, |
| 57 | + attributes: span.attributes, |
| 58 | + events: span.events, |
| 59 | + status: span.status, |
| 60 | + kind: span.kind, |
| 61 | + }; |
| 62 | + console.log(JSON.stringify(spanData, null, 2)); |
| 63 | + } |
| 64 | + resultCallback(ExportResult.SUCCESS); |
| 65 | + } |
| 66 | + shutdown(): Promise<void> { |
| 67 | + return Promise.resolve(); |
| 68 | + } |
| 69 | +} |
| 70 | +//const myExporter = new CustomConsoleSpanExporter() |
52 | 71 |
|
53 |
| -// For troubleshooting, set the log level to DiagLogLevel.DEBUG |
54 |
| -diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL); |
| 72 | +// parts from https://stackoverflow.com/questions/71654897/opentelemetry-typescript-project-zipkin-exporter |
| 73 | +//const { SimpleSpanProcessor } = import('@opentelemetry/sdk-trace-base'); |
| 74 | +import { NodeTracerProvider, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node"; |
| 75 | +const txz=new SimpleSpanProcessor(traceExporter_zipkin); |
| 76 | +const tx=new SimpleSpanProcessor(traceExporter); |
| 77 | + |
| 78 | +try { |
| 79 | + const serviceName = 'eliza-agent'; |
| 80 | + const provider = new NodeTracerProvider({ |
| 81 | + resource: new Resource({ |
| 82 | + [SEMRESATTRS_SERVICE_NAME]: serviceName, |
| 83 | + [ATTR_SERVICE_NAME]: serviceName, |
| 84 | + [ATTR_SERVICE_VERSION]: '1.0', }), |
| 85 | + spanProcessors: [ |
| 86 | + txz, |
| 87 | + tx |
| 88 | + ] |
| 89 | + }); |
55 | 90 |
|
56 |
| -console.log(sdk.start()); |
| 91 | + // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings |
| 92 | + provider.register(); |
| 93 | + |
| 94 | + registerInstrumentations({ |
| 95 | + instrumentations: [ |
| 96 | + getNodeAutoInstrumentations(), |
| 97 | + new HttpInstrumentation(), |
| 98 | + ], |
| 99 | + }); |
| 100 | + |
| 101 | + opentelemetry.trace.getTracer('http-example'); |
| 102 | + console.log("setup!") |
| 103 | +} catch(error){ |
| 104 | + console.log("ERROR",error) |
| 105 | +} |
| 106 | +// const sdk = new NodeSDK({ resource: new Resource({ |
| 107 | + |
| 108 | +// //traceExporter: new ConsoleSpanExporter(), |
| 109 | +// traceExporter: myExporter, |
| 110 | +// //traceExporter_zipkin |
| 111 | +// instrumentations: [, new HttpInstrumentation() ], |
| 112 | +// }); |
| 113 | +// // For troubleshooting, set the log level to DiagLogLevel.DEBUG |
| 114 | +// diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL); |
| 115 | +// console.log(sdk.start()); |
57 | 116 |
|
58 | 117 |
|
59 | 118 | import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
|
|
0 commit comments