promptfoo 0.115.3 → 0.115.4
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/drizzle/0015_zippy_wallop.sql +29 -0
- package/dist/drizzle/meta/0015_snapshot.json +1003 -0
- package/dist/drizzle/meta/_journal.json +7 -0
- package/dist/package.json +1 -1
- package/dist/src/app/assets/{index-BXsrbFYA.js → index-DwIrymQd.js} +169 -169
- package/dist/src/app/assets/{source-map-support-CNXJ1-7r.js → source-map-support-UIopcc8W.js} +1 -1
- package/dist/src/app/assets/{sync-CYtWtmxM.js → sync-CqTZoCfS.js} +1 -1
- package/dist/src/app/index.html +1 -1
- package/dist/src/database/tables.d.ts +365 -0
- package/dist/src/database/tables.d.ts.map +1 -1
- package/dist/src/database/tables.js +48 -1
- package/dist/src/database/tables.js.map +1 -1
- package/dist/src/evaluator.d.ts.map +1 -1
- package/dist/src/evaluator.js +46 -4
- package/dist/src/evaluator.js.map +1 -1
- package/dist/src/redteam/commands/generate.d.ts.map +1 -1
- package/dist/src/redteam/commands/generate.js +0 -2
- package/dist/src/redteam/commands/generate.js.map +1 -1
- package/dist/src/server/routes/traces.d.ts +2 -0
- package/dist/src/server/routes/traces.d.ts.map +1 -0
- package/dist/src/server/routes/traces.js +45 -0
- package/dist/src/server/routes/traces.js.map +1 -0
- package/dist/src/server/server.d.ts.map +1 -1
- package/dist/src/server/server.js +2 -0
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/tracing/evaluatorTracing.d.ts +39 -0
- package/dist/src/tracing/evaluatorTracing.d.ts.map +1 -0
- package/dist/src/tracing/evaluatorTracing.js +189 -0
- package/dist/src/tracing/evaluatorTracing.js.map +1 -0
- package/dist/src/tracing/otlpReceiver.d.ts +21 -0
- package/dist/src/tracing/otlpReceiver.d.ts.map +1 -0
- package/dist/src/tracing/otlpReceiver.js +278 -0
- package/dist/src/tracing/otlpReceiver.js.map +1 -0
- package/dist/src/tracing/store.d.ts +33 -0
- package/dist/src/tracing/store.d.ts.map +1 -0
- package/dist/src/tracing/store.js +170 -0
- package/dist/src/tracing/store.js.map +1 -0
- package/dist/src/types/index.d.ts +606 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +77 -0
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/providers.d.ts +4 -0
- package/dist/src/types/providers.d.ts.map +1 -1
- package/dist/src/types/providers.js.map +1 -1
- package/dist/src/util/config/load.d.ts.map +1 -1
- package/dist/src/util/config/load.js +3 -0
- package/dist/src/util/config/load.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.generateTraceId = generateTraceId;
|
|
40
|
+
exports.generateSpanId = generateSpanId;
|
|
41
|
+
exports.generateTraceparent = generateTraceparent;
|
|
42
|
+
exports.isOtlpReceiverStarted = isOtlpReceiverStarted;
|
|
43
|
+
exports.startOtlpReceiverIfNeeded = startOtlpReceiverIfNeeded;
|
|
44
|
+
exports.stopOtlpReceiverIfNeeded = stopOtlpReceiverIfNeeded;
|
|
45
|
+
exports.isTracingEnabled = isTracingEnabled;
|
|
46
|
+
exports.generateTraceContextIfNeeded = generateTraceContextIfNeeded;
|
|
47
|
+
const crypto_1 = require("crypto");
|
|
48
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
49
|
+
// Track whether OTLP receiver has been started
|
|
50
|
+
let otlpReceiverStarted = false;
|
|
51
|
+
/**
|
|
52
|
+
* Generate a 16-byte trace ID
|
|
53
|
+
*/
|
|
54
|
+
function generateTraceId() {
|
|
55
|
+
return (0, crypto_1.randomBytes)(16).toString('hex');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generate an 8-byte span ID
|
|
59
|
+
*/
|
|
60
|
+
function generateSpanId() {
|
|
61
|
+
return (0, crypto_1.randomBytes)(8).toString('hex');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Generate W3C Trace Context format traceparent header
|
|
65
|
+
* Format: version-trace-id-parent-id-trace-flags
|
|
66
|
+
*/
|
|
67
|
+
function generateTraceparent(traceId, spanId, sampled = true) {
|
|
68
|
+
const version = '00';
|
|
69
|
+
const traceFlags = sampled ? '01' : '00';
|
|
70
|
+
return `${version}-${traceId}-${spanId}-${traceFlags}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if the OTLP receiver has been started
|
|
74
|
+
*/
|
|
75
|
+
function isOtlpReceiverStarted() {
|
|
76
|
+
return otlpReceiverStarted;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Start the OTLP receiver if tracing is enabled and it hasn't been started yet
|
|
80
|
+
*/
|
|
81
|
+
async function startOtlpReceiverIfNeeded(testSuite) {
|
|
82
|
+
logger_1.default.debug(`[EvaluatorTracing] Checking tracing config: ${JSON.stringify(testSuite.tracing)}`);
|
|
83
|
+
logger_1.default.debug(`[EvaluatorTracing] testSuite keys: ${Object.keys(testSuite)}`);
|
|
84
|
+
logger_1.default.debug(`[EvaluatorTracing] Full testSuite.tracing: ${JSON.stringify(testSuite.tracing, null, 2)}`);
|
|
85
|
+
if (testSuite.tracing?.enabled &&
|
|
86
|
+
testSuite.tracing?.otlp?.http?.enabled &&
|
|
87
|
+
!otlpReceiverStarted) {
|
|
88
|
+
try {
|
|
89
|
+
logger_1.default.debug('[EvaluatorTracing] Tracing configuration detected, starting OTLP receiver');
|
|
90
|
+
const { startOTLPReceiver } = await Promise.resolve().then(() => __importStar(require('./otlpReceiver')));
|
|
91
|
+
const port = testSuite.tracing.otlp.http.port || 4318;
|
|
92
|
+
const host = testSuite.tracing.otlp.http.host || '0.0.0.0';
|
|
93
|
+
logger_1.default.debug(`[EvaluatorTracing] Starting OTLP receiver on ${host}:${port}`);
|
|
94
|
+
await startOTLPReceiver(port, host);
|
|
95
|
+
otlpReceiverStarted = true;
|
|
96
|
+
logger_1.default.info(`[EvaluatorTracing] OTLP receiver successfully started on port ${port} for tracing`);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
logger_1.default.error(`[EvaluatorTracing] Failed to start OTLP receiver: ${error}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (otlpReceiverStarted) {
|
|
104
|
+
logger_1.default.debug('[EvaluatorTracing] OTLP receiver already started, skipping initialization');
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
logger_1.default.debug('[EvaluatorTracing] Tracing not enabled or OTLP HTTP receiver not configured');
|
|
108
|
+
logger_1.default.debug(`[EvaluatorTracing] tracing.enabled: ${testSuite.tracing?.enabled}`);
|
|
109
|
+
logger_1.default.debug(`[EvaluatorTracing] tracing.otlp.http.enabled: ${testSuite.tracing?.otlp?.http?.enabled}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Stop the OTLP receiver if it was started
|
|
115
|
+
*/
|
|
116
|
+
async function stopOtlpReceiverIfNeeded() {
|
|
117
|
+
if (otlpReceiverStarted) {
|
|
118
|
+
try {
|
|
119
|
+
logger_1.default.debug('[EvaluatorTracing] Stopping OTLP receiver');
|
|
120
|
+
const { stopOTLPReceiver } = await Promise.resolve().then(() => __importStar(require('./otlpReceiver')));
|
|
121
|
+
await stopOTLPReceiver();
|
|
122
|
+
otlpReceiverStarted = false;
|
|
123
|
+
logger_1.default.info('[EvaluatorTracing] OTLP receiver stopped successfully');
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
logger_1.default.error(`[EvaluatorTracing] Failed to stop OTLP receiver: ${error}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if tracing is enabled for a test case
|
|
132
|
+
*/
|
|
133
|
+
function isTracingEnabled(test, testSuite) {
|
|
134
|
+
return test.metadata?.tracingEnabled === true || process.env.PROMPTFOO_TRACING_ENABLED === 'true';
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Generate trace context and create trace record if tracing is enabled
|
|
138
|
+
*/
|
|
139
|
+
async function generateTraceContextIfNeeded(test, evaluateOptions, testIdx, promptIdx) {
|
|
140
|
+
const tracingEnabled = isTracingEnabled(test);
|
|
141
|
+
if (tracingEnabled) {
|
|
142
|
+
logger_1.default.debug('[EvaluatorTracing] Tracing enabled for test case');
|
|
143
|
+
logger_1.default.debug(`[EvaluatorTracing] Test metadata: ${JSON.stringify(test.metadata)}`);
|
|
144
|
+
}
|
|
145
|
+
if (!tracingEnabled) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
// Import trace store dynamically to avoid circular dependencies
|
|
149
|
+
logger_1.default.debug('[EvaluatorTracing] Importing trace store');
|
|
150
|
+
const { getTraceStore } = await Promise.resolve().then(() => __importStar(require('./store')));
|
|
151
|
+
const traceStore = getTraceStore();
|
|
152
|
+
// Generate trace context
|
|
153
|
+
const traceId = generateTraceId();
|
|
154
|
+
const spanId = generateSpanId();
|
|
155
|
+
const traceparent = generateTraceparent(traceId, spanId);
|
|
156
|
+
logger_1.default.debug(`[EvaluatorTracing] Generated trace context: traceId=${traceId}, spanId=${spanId}`);
|
|
157
|
+
// Get evaluation ID from test metadata (set by Evaluator class)
|
|
158
|
+
let evaluationId = test.metadata?.evaluationId || evaluateOptions?.eventSource;
|
|
159
|
+
if (!evaluationId) {
|
|
160
|
+
logger_1.default.warn('[EvaluatorTracing] No evaluation ID found in test metadata or evaluateOptions, trace will not be linked to evaluation');
|
|
161
|
+
evaluationId = `eval-${Date.now()}`;
|
|
162
|
+
}
|
|
163
|
+
const testCaseId = test.metadata?.testCaseId || test.id || `${testIdx}-${promptIdx}`;
|
|
164
|
+
// Store trace association in trace store
|
|
165
|
+
try {
|
|
166
|
+
logger_1.default.debug(`[EvaluatorTracing] Creating trace record for traceId=${traceId}`);
|
|
167
|
+
await traceStore.createTrace({
|
|
168
|
+
traceId,
|
|
169
|
+
evaluationId: evaluationId || '',
|
|
170
|
+
testCaseId: testCaseId || '',
|
|
171
|
+
metadata: {
|
|
172
|
+
testIdx,
|
|
173
|
+
promptIdx,
|
|
174
|
+
vars: test.vars,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
logger_1.default.debug('[EvaluatorTracing] Trace record created successfully');
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
logger_1.default.error(`[EvaluatorTracing] Failed to create trace: ${error}`);
|
|
181
|
+
}
|
|
182
|
+
logger_1.default.debug(`[EvaluatorTracing] Trace context ready: ${traceparent} for test case ${testCaseId}`);
|
|
183
|
+
return {
|
|
184
|
+
traceparent,
|
|
185
|
+
evaluationId,
|
|
186
|
+
testCaseId,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=evaluatorTracing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluatorTracing.js","sourceRoot":"","sources":["../../../src/tracing/evaluatorTracing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,0CAEC;AAKD,wCAEC;AAMD,kDAQC;AAKD,sDAEC;AAKD,8DAqCC;AAKD,4DAYC;AAKD,4CAEC;AAKD,oEAqEC;AApLD,mCAAqC;AACrC,uDAA+B;AAG/B,+CAA+C;AAC/C,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC;;GAEG;AACH,SAAgB,eAAe;IAC7B,OAAO,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc;IAC5B,OAAO,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CACjC,OAAe,EACf,MAAc,EACd,UAAmB,IAAI;IAEvB,MAAM,OAAO,GAAG,IAAI,CAAC;IACr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,CAAC;IAE9F,yCAAyC;IACzC,IAAI,CAAC;QACH,gBAAM,CAAC,KAAK,CAAC,wDAAwD,OAAO,EAAE,CAAC,CAAC;QAChF,MAAM,UAAU,CAAC,WAAW,CAAC;YAC3B,OAAO;YACP,YAAY,EAAE,YAAY,IAAI,EAAE;YAChC,UAAU,EAAE,UAAU,IAAI,EAAE;YAC5B,QAAQ,EAAE;gBACR,OAAO;gBACP,SAAS;gBACT,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;SACF,CAAC,CAAC;QACH,gBAAM,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gBAAM,CAAC,KAAK,CAAC,8CAA8C,KAAK,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,gBAAM,CAAC,KAAK,CACV,2CAA2C,WAAW,kBAAkB,UAAU,EAAE,CACrF,CAAC;IAEF,OAAO;QACL,WAAW;QACX,YAAY;QACZ,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
export declare class OTLPReceiver {
|
|
3
|
+
private app;
|
|
4
|
+
private traceStore;
|
|
5
|
+
private port?;
|
|
6
|
+
private server?;
|
|
7
|
+
constructor();
|
|
8
|
+
private setupMiddleware;
|
|
9
|
+
private setupRoutes;
|
|
10
|
+
private parseOTLPJSONRequest;
|
|
11
|
+
private parseAttributes;
|
|
12
|
+
private parseAttributeValue;
|
|
13
|
+
private convertId;
|
|
14
|
+
listen(port?: number, host?: string): Promise<void>;
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
getApp(): express.Application;
|
|
17
|
+
}
|
|
18
|
+
export declare function getOTLPReceiver(): OTLPReceiver;
|
|
19
|
+
export declare function startOTLPReceiver(port?: number, host?: string): Promise<void>;
|
|
20
|
+
export declare function stopOTLPReceiver(): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=otlpReceiver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlpReceiver.d.ts","sourceRoot":"","sources":["../../../src/tracing/otlpReceiver.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAkD9B,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,MAAM,CAAC,CAAM;;IAUrB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,WAAW;IAqGnB,OAAO,CAAC,oBAAoB;IAqD5B,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,mBAAmB;IA0B3B,OAAO,CAAC,SAAS;IAwCjB,MAAM,CAAC,IAAI,GAAE,MAAa,EAAE,IAAI,GAAE,MAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBpE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBrB,MAAM,IAAI,OAAO,CAAC,WAAW;CAG9B;AAKD,wBAAgB,eAAe,IAAI,YAAY,CAK9C;AAED,wBAAsB,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAInF;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAMtD"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OTLPReceiver = void 0;
|
|
7
|
+
exports.getOTLPReceiver = getOTLPReceiver;
|
|
8
|
+
exports.startOTLPReceiver = startOTLPReceiver;
|
|
9
|
+
exports.stopOTLPReceiver = stopOTLPReceiver;
|
|
10
|
+
const express_1 = __importDefault(require("express"));
|
|
11
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
12
|
+
const store_1 = require("./store");
|
|
13
|
+
class OTLPReceiver {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.app = (0, express_1.default)();
|
|
16
|
+
this.traceStore = (0, store_1.getTraceStore)();
|
|
17
|
+
logger_1.default.debug('[OtlpReceiver] Initializing OTLP receiver');
|
|
18
|
+
this.setupMiddleware();
|
|
19
|
+
this.setupRoutes();
|
|
20
|
+
}
|
|
21
|
+
setupMiddleware() {
|
|
22
|
+
// Support both JSON and protobuf (for now, we'll focus on JSON)
|
|
23
|
+
this.app.use(express_1.default.json({ limit: '10mb', type: 'application/json' }));
|
|
24
|
+
this.app.use(express_1.default.raw({ type: 'application/x-protobuf', limit: '10mb' }));
|
|
25
|
+
logger_1.default.debug('[OtlpReceiver] Middleware configured for JSON and protobuf');
|
|
26
|
+
}
|
|
27
|
+
setupRoutes() {
|
|
28
|
+
// OTLP HTTP endpoint for traces
|
|
29
|
+
this.app.post('/v1/traces', async (req, res) => {
|
|
30
|
+
const contentType = req.headers['content-type'] || 'unknown';
|
|
31
|
+
const bodySize = req.body ? JSON.stringify(req.body).length : 0;
|
|
32
|
+
logger_1.default.debug(`[OtlpReceiver] Received trace request: ${req.headers['content-type']} with ${bodySize} bytes`);
|
|
33
|
+
logger_1.default.debug('[OtlpReceiver] Starting to process traces');
|
|
34
|
+
// Check content type first before processing
|
|
35
|
+
if (contentType === 'application/json') {
|
|
36
|
+
// Continue with JSON processing
|
|
37
|
+
}
|
|
38
|
+
else if (contentType === 'application/x-protobuf') {
|
|
39
|
+
logger_1.default.warn('Protobuf format not yet supported, please use JSON');
|
|
40
|
+
res.status(415).json({ error: 'Protobuf format not yet supported' });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
res.status(415).json({ error: 'Unsupported content type' });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
let traces = [];
|
|
49
|
+
// We already validated content type above, so this must be JSON
|
|
50
|
+
logger_1.default.debug('[OtlpReceiver] Parsing OTLP JSON request');
|
|
51
|
+
logger_1.default.debug(`[OtlpReceiver] Request body: ${JSON.stringify(req.body).substring(0, 500)}...`);
|
|
52
|
+
traces = this.parseOTLPJSONRequest(req.body);
|
|
53
|
+
logger_1.default.debug(`[OtlpReceiver] Parsed ${traces.length} traces from request`);
|
|
54
|
+
// Group spans by trace ID
|
|
55
|
+
const spansByTrace = new Map();
|
|
56
|
+
for (const trace of traces) {
|
|
57
|
+
if (!spansByTrace.has(trace.traceId)) {
|
|
58
|
+
spansByTrace.set(trace.traceId, []);
|
|
59
|
+
}
|
|
60
|
+
spansByTrace.get(trace.traceId).push(trace.span);
|
|
61
|
+
}
|
|
62
|
+
logger_1.default.debug(`[OtlpReceiver] Grouped spans into ${spansByTrace.size} traces`);
|
|
63
|
+
// Store spans for each trace
|
|
64
|
+
for (const [traceId, spans] of spansByTrace) {
|
|
65
|
+
logger_1.default.debug(`[OtlpReceiver] Storing ${spans.length} spans for trace ${traceId}`);
|
|
66
|
+
await this.traceStore.addSpans(traceId, spans, { skipTraceCheck: true });
|
|
67
|
+
}
|
|
68
|
+
// OTLP success response
|
|
69
|
+
res.status(200).json({ partialSuccess: {} });
|
|
70
|
+
logger_1.default.debug('[OtlpReceiver] Successfully processed traces');
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger_1.default.error(`[OtlpReceiver] Failed to process OTLP traces: ${error}`);
|
|
74
|
+
logger_1.default.error(`[OtlpReceiver] Error stack: ${error instanceof Error ? error.stack : 'No stack'}`);
|
|
75
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// Health check endpoint
|
|
79
|
+
this.app.get('/health', (req, res) => {
|
|
80
|
+
logger_1.default.debug('[OtlpReceiver] Health check requested');
|
|
81
|
+
res.status(200).json({ status: 'ok' });
|
|
82
|
+
});
|
|
83
|
+
// OTLP service info endpoint
|
|
84
|
+
this.app.get('/v1/traces', (req, res) => {
|
|
85
|
+
res.status(200).json({
|
|
86
|
+
service: 'promptfoo-otlp-receiver',
|
|
87
|
+
version: '1.0.0',
|
|
88
|
+
supported_formats: ['json'], // 'protobuf' will be added in phase 2
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
// Debug endpoint to check receiver status
|
|
92
|
+
this.app.get('/debug/status', async (req, res) => {
|
|
93
|
+
res.status(200).json({
|
|
94
|
+
status: 'running',
|
|
95
|
+
uptime: process.uptime(),
|
|
96
|
+
timestamp: new Date().toISOString(),
|
|
97
|
+
port: this.port || 4318,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
// Global error handler
|
|
101
|
+
this.app.use((error, req, res, next) => {
|
|
102
|
+
logger_1.default.error(`[OtlpReceiver] Global error handler: ${error}`);
|
|
103
|
+
logger_1.default.error(`[OtlpReceiver] Error stack: ${error.stack}`);
|
|
104
|
+
// Handle JSON parsing errors
|
|
105
|
+
if (error instanceof SyntaxError && 'body' in error) {
|
|
106
|
+
res.status(400).json({ error: 'Invalid JSON' });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
parseOTLPJSONRequest(body) {
|
|
113
|
+
const traces = [];
|
|
114
|
+
logger_1.default.debug(`[OtlpReceiver] Parsing request with ${body.resourceSpans?.length || 0} resource spans`);
|
|
115
|
+
for (const resourceSpan of body.resourceSpans) {
|
|
116
|
+
// Extract resource attributes if needed
|
|
117
|
+
const resourceAttributes = this.parseAttributes(resourceSpan.resource?.attributes);
|
|
118
|
+
logger_1.default.debug(`[OtlpReceiver] Parsed ${Object.keys(resourceAttributes).length} resource attributes`);
|
|
119
|
+
for (const scopeSpan of resourceSpan.scopeSpans) {
|
|
120
|
+
for (const span of scopeSpan.spans) {
|
|
121
|
+
// Convert IDs - handle both hex strings and base64 encoded binary
|
|
122
|
+
const traceId = this.convertId(span.traceId, 32); // 32 hex chars = 16 bytes
|
|
123
|
+
const spanId = this.convertId(span.spanId, 16); // 16 hex chars = 8 bytes
|
|
124
|
+
const parentSpanId = span.parentSpanId
|
|
125
|
+
? this.convertId(span.parentSpanId, 16)
|
|
126
|
+
: undefined;
|
|
127
|
+
logger_1.default.debug(`[OtlpReceiver] Processing span: ${span.name} (${spanId}) in trace ${traceId}`);
|
|
128
|
+
// Parse attributes
|
|
129
|
+
const attributes = {
|
|
130
|
+
...resourceAttributes,
|
|
131
|
+
...this.parseAttributes(span.attributes),
|
|
132
|
+
'otel.scope.name': scopeSpan.scope?.name,
|
|
133
|
+
'otel.scope.version': scopeSpan.scope?.version,
|
|
134
|
+
};
|
|
135
|
+
traces.push({
|
|
136
|
+
traceId,
|
|
137
|
+
span: {
|
|
138
|
+
spanId,
|
|
139
|
+
parentSpanId,
|
|
140
|
+
name: span.name,
|
|
141
|
+
startTime: Number(span.startTimeUnixNano) / 1000000, // Convert to ms
|
|
142
|
+
endTime: span.endTimeUnixNano ? Number(span.endTimeUnixNano) / 1000000 : undefined,
|
|
143
|
+
attributes,
|
|
144
|
+
statusCode: span.status?.code,
|
|
145
|
+
statusMessage: span.status?.message,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return traces;
|
|
152
|
+
}
|
|
153
|
+
parseAttributes(attributes) {
|
|
154
|
+
if (!attributes) {
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
const result = {};
|
|
158
|
+
for (const attr of attributes) {
|
|
159
|
+
const value = this.parseAttributeValue(attr.value);
|
|
160
|
+
if (value !== undefined) {
|
|
161
|
+
result[attr.key] = value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
parseAttributeValue(value) {
|
|
167
|
+
if (value.stringValue !== undefined) {
|
|
168
|
+
return value.stringValue;
|
|
169
|
+
}
|
|
170
|
+
if (value.intValue !== undefined) {
|
|
171
|
+
return Number(value.intValue);
|
|
172
|
+
}
|
|
173
|
+
if (value.doubleValue !== undefined) {
|
|
174
|
+
return value.doubleValue;
|
|
175
|
+
}
|
|
176
|
+
if (value.boolValue !== undefined) {
|
|
177
|
+
return value.boolValue;
|
|
178
|
+
}
|
|
179
|
+
if (value.arrayValue?.values) {
|
|
180
|
+
return value.arrayValue.values.map((v) => this.parseAttributeValue(v));
|
|
181
|
+
}
|
|
182
|
+
if (value.kvlistValue?.values) {
|
|
183
|
+
const kvMap = {};
|
|
184
|
+
for (const kv of value.kvlistValue.values) {
|
|
185
|
+
kvMap[kv.key] = this.parseAttributeValue(kv.value);
|
|
186
|
+
}
|
|
187
|
+
return kvMap;
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
convertId(id, expectedHexLength) {
|
|
192
|
+
logger_1.default.debug(`[OtlpReceiver] Converting ID: ${id} (length: ${id.length}, expected hex length: ${expectedHexLength})`);
|
|
193
|
+
// Check if it's already a hex string of the expected length
|
|
194
|
+
if (id.length === expectedHexLength && /^[0-9a-f]+$/i.test(id)) {
|
|
195
|
+
logger_1.default.debug(`[OtlpReceiver] ID is already hex format`);
|
|
196
|
+
return id.toLowerCase();
|
|
197
|
+
}
|
|
198
|
+
// Try base64 decoding
|
|
199
|
+
try {
|
|
200
|
+
const buffer = Buffer.from(id, 'base64');
|
|
201
|
+
const hex = buffer.toString('hex');
|
|
202
|
+
logger_1.default.debug(`[OtlpReceiver] Base64 decoded: ${id} -> ${hex} (${buffer.length} bytes)`);
|
|
203
|
+
// Check if the decoded value looks like it was originally a hex string encoded as UTF-8
|
|
204
|
+
const utf8String = buffer.toString('utf8');
|
|
205
|
+
if (utf8String.length === expectedHexLength && /^[0-9a-f]+$/i.test(utf8String)) {
|
|
206
|
+
logger_1.default.debug(`[OtlpReceiver] Detected hex string encoded as UTF-8: ${utf8String}`);
|
|
207
|
+
return utf8String.toLowerCase();
|
|
208
|
+
}
|
|
209
|
+
// If the resulting hex is the expected length, return it
|
|
210
|
+
if (hex.length === expectedHexLength) {
|
|
211
|
+
return hex;
|
|
212
|
+
}
|
|
213
|
+
// Otherwise, something's wrong
|
|
214
|
+
logger_1.default.warn(`[OtlpReceiver] Unexpected ID format: ${id} -> ${hex} (expected ${expectedHexLength} hex chars)`);
|
|
215
|
+
return id.toLowerCase();
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
logger_1.default.error(`[OtlpReceiver] Failed to convert ID: ${error}`);
|
|
219
|
+
return id.toLowerCase();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
listen(port = 4318, host = '0.0.0.0') {
|
|
223
|
+
this.port = port;
|
|
224
|
+
logger_1.default.debug(`[OtlpReceiver] Starting receiver on ${host}:${port}`);
|
|
225
|
+
return new Promise((resolve, reject) => {
|
|
226
|
+
this.server = this.app.listen(port, host, () => {
|
|
227
|
+
logger_1.default.info(`[OtlpReceiver] Listening on http://${host}:${port}`);
|
|
228
|
+
logger_1.default.debug('[OtlpReceiver] Receiver fully initialized and ready to accept traces');
|
|
229
|
+
resolve();
|
|
230
|
+
});
|
|
231
|
+
this.server.on('error', (error) => {
|
|
232
|
+
logger_1.default.error(`[OtlpReceiver] Failed to start: ${error}`);
|
|
233
|
+
reject(error);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
stop() {
|
|
238
|
+
logger_1.default.debug('[OtlpReceiver] Stopping receiver');
|
|
239
|
+
return new Promise((resolve) => {
|
|
240
|
+
if (this.server) {
|
|
241
|
+
this.server.close(() => {
|
|
242
|
+
logger_1.default.info('[OtlpReceiver] Server stopped');
|
|
243
|
+
this.server = undefined;
|
|
244
|
+
resolve();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
logger_1.default.debug('[OtlpReceiver] No server to stop');
|
|
249
|
+
resolve();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
getApp() {
|
|
254
|
+
return this.app;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.OTLPReceiver = OTLPReceiver;
|
|
258
|
+
// Singleton instance
|
|
259
|
+
let otlpReceiver = null;
|
|
260
|
+
function getOTLPReceiver() {
|
|
261
|
+
if (!otlpReceiver) {
|
|
262
|
+
otlpReceiver = new OTLPReceiver();
|
|
263
|
+
}
|
|
264
|
+
return otlpReceiver;
|
|
265
|
+
}
|
|
266
|
+
async function startOTLPReceiver(port, host) {
|
|
267
|
+
logger_1.default.debug('[OtlpReceiver] Starting receiver through startOTLPReceiver function');
|
|
268
|
+
const receiver = getOTLPReceiver();
|
|
269
|
+
await receiver.listen(port, host);
|
|
270
|
+
}
|
|
271
|
+
async function stopOTLPReceiver() {
|
|
272
|
+
logger_1.default.debug('[OtlpReceiver] Stopping receiver through stopOTLPReceiver function');
|
|
273
|
+
if (otlpReceiver) {
|
|
274
|
+
await otlpReceiver.stop();
|
|
275
|
+
otlpReceiver = null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=otlpReceiver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlpReceiver.js","sourceRoot":"","sources":["../../../src/tracing/otlpReceiver.ts"],"names":[],"mappings":";;;;;;AA8VA,0CAKC;AAED,8CAIC;AAED,4CAMC;AAjXD,sDAA8B;AAC9B,uDAA+B;AAC/B,mCAA0F;AAgD1F,MAAa,YAAY;IAMvB;QACE,IAAI,CAAC,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAA,qBAAa,GAAE,CAAC;QAClC,gBAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IA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AE,IAAI,CAAC,CAAC;AACpC,CAAC;AAEM,KAAK,UAAU,gBAAgB;IACpC,gBAAM,CAAC,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACnF,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC;QAC1B,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface TraceData {
|
|
2
|
+
traceId: string;
|
|
3
|
+
evaluationId: string;
|
|
4
|
+
testCaseId: string;
|
|
5
|
+
metadata?: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface SpanData {
|
|
8
|
+
spanId: string;
|
|
9
|
+
parentSpanId?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
startTime: number;
|
|
12
|
+
endTime?: number;
|
|
13
|
+
attributes?: Record<string, any>;
|
|
14
|
+
statusCode?: number;
|
|
15
|
+
statusMessage?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ParsedTrace {
|
|
18
|
+
traceId: string;
|
|
19
|
+
span: SpanData;
|
|
20
|
+
}
|
|
21
|
+
export declare class TraceStore {
|
|
22
|
+
private db;
|
|
23
|
+
private getDatabase;
|
|
24
|
+
createTrace(trace: TraceData): Promise<void>;
|
|
25
|
+
addSpans(traceId: string, spans: SpanData[], options?: {
|
|
26
|
+
skipTraceCheck?: boolean;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
getTracesByEvaluation(evaluationId: string): Promise<any[]>;
|
|
29
|
+
getTrace(traceId: string): Promise<any | null>;
|
|
30
|
+
deleteOldTraces(retentionDays: number): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare function getTraceStore(): TraceStore;
|
|
33
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/tracing/store.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,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