UNPKG

@arizeai/phoenix-client

Version:
100 lines 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTraces = getTraces; const client_1 = require("../client"); const serverRequirements_1 = require("../constants/serverRequirements"); const projects_1 = require("../types/projects"); const serverVersionUtils_1 = require("../utils/serverVersionUtils"); /** * Get traces from a project with filtering and sorting options. * * This method fetches traces from a project with support for time range filtering, * sorting, session filtering, and cursor-based pagination. * * @requires Phoenix server >= 13.15.0 * * @param params - The parameters to get traces * @returns A paginated response containing traces and optional next cursor * * @example * ```ts * // Get recent traces from a project * const result = await getTraces({ * client, * project: { projectName: "my-project" }, * limit: 50, * }); * * // Get traces in a time range with spans included * const result = await getTraces({ * client, * project: { projectName: "my-project" }, * startTime: new Date("2024-01-01"), * endTime: new Date("2024-01-02"), * includeSpans: true, * }); * * // Paginate through results * let cursor: string | undefined; * do { * const result = await getTraces({ * client, * project: { projectName: "my-project" }, * cursor, * limit: 100, * }); * result.traces.forEach(trace => { * console.log(`Trace: ${trace.trace_id}`); * }); * cursor = result.nextCursor || undefined; * } while (cursor); * ``` */ async function getTraces({ client: _client, project, cursor, limit = 100, startTime, endTime, sort, order, includeSpans, sessionId, }) { var _a, _b; const client = _client !== null && _client !== void 0 ? _client : (0, client_1.createClient)(); await (0, serverVersionUtils_1.ensureServerCapability)({ client, requirement: serverRequirements_1.LIST_PROJECT_TRACES }); const projectIdentifier = (0, projects_1.resolveProjectIdentifier)(project); const params = { limit, }; if (cursor) { params.cursor = cursor; } if (startTime) { params.start_time = startTime instanceof Date ? startTime.toISOString() : startTime; } if (endTime) { params.end_time = endTime instanceof Date ? endTime.toISOString() : endTime; } if (sort) { params.sort = sort; } if (order) { params.order = order; } if (includeSpans) { params.include_spans = true; } if (sessionId) { params.session_identifier = Array.isArray(sessionId) ? sessionId : [sessionId]; } const { data, error } = await client.GET("/v1/projects/{project_identifier}/traces", { params: { path: { project_identifier: projectIdentifier, }, query: params, }, }); if (error) throw error; return { traces: (_a = data === null || data === void 0 ? void 0 : data.data) !== null && _a !== void 0 ? _a : [], nextCursor: (_b = data === null || data === void 0 ? void 0 : data.next_cursor) !== null && _b !== void 0 ? _b : null, }; } //# sourceMappingURL=getTraces.js.map