@arizeai/phoenix-evals
Version:
A library for running evaluations for AI use cases
58 lines • 2.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tracer = void 0;
exports.getTracer = getTracer;
exports.getTelemetryIntegrations = getTelemetryIntegrations;
const otel_1 = require("@ai-sdk/otel");
const api_1 = require("@opentelemetry/api");
const DEFAULT_TRACER_NAME = "phoenix-evals";
/**
* Returns a lazy tracer that resolves from `trace.getTracer()` on every call,
* so evaluator spans follow whichever provider is currently mounted as global.
*
* Cast to `Tracer` is necessary because `startActiveSpan` has multiple
* overload signatures that cannot be satisfied by a single implementation.
*/
function getTracer(name = DEFAULT_TRACER_NAME) {
return {
startSpan(spanName, options, context) {
return api_1.trace.getTracer(name).startSpan(spanName, options, context);
},
startActiveSpan(...args) {
const tracer = api_1.trace.getTracer(name);
return Reflect.apply(tracer.startActiveSpan, tracer, args);
},
};
}
exports.tracer = getTracer();
/**
* Builds the AI SDK telemetry integrations for an evaluator call. Per-call
* `integrations` replace the SDK's globally registered ones, so the globals
* (application logging, metrics, tracing to other backends) are carried
* forward with a Phoenix tracing integration appended. If a global
* integration already traces with the same tracer instance, the globals are
* used as-is so the call is not traced twice.
*/
function getTelemetryIntegrations(integrationTracer) {
var _a;
const globalIntegrations = (_a = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) !== null && _a !== void 0 ? _a : [];
const hasTracerIntegration = globalIntegrations.some(
// Duck-typed so integrations from a different copy of `@ai-sdk/otel`
// are still recognized.
(integration) => integration.tracer === integrationTracer);
if (hasTracerIntegration) {
return globalIntegrations;
}
return [
...globalIntegrations,
new otel_1.OpenTelemetry({
tracer: integrationTracer,
// Supplemental AI SDK attributes recommended for fuller OpenInference
// coverage of generateObject calls.
usage: true,
providerMetadata: true,
schema: true,
}),
];
}
//# sourceMappingURL=index.js.map