Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logging to ensure correct context for span #533

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions js/ai/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
ToolRequestPart,
ToolResponsePart,
} from './model.js';
import * as telemetry from './telemetry.js';
import {
resolveTools,
ToolAction,
Expand Down Expand Up @@ -609,11 +608,6 @@ export async function generate<
}

const request = await toGenerateRequest(resolvedOptions);
telemetry.recordGenerateActionInputLogs(
model.__action.name,
resolvedOptions,
request
);
const response = await runWithStreamingCallback(
resolvedOptions.streamingCallback
? (chunk: GenerateResponseChunkData) =>
Expand Down Expand Up @@ -678,11 +672,6 @@ export async function generate<
(part) => !!part.toolRequest
);
if (resolvedOptions.returnToolRequests || toolCalls.length === 0) {
telemetry.recordGenerateActionOutputLogs(
model.__action.name,
resolvedOptions,
response
);
return response;
}
const toolResponses: ToolResponsePart[] = await Promise.all(
Expand Down
3 changes: 3 additions & 0 deletions js/ai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,15 @@ export function defineModel<
},
(input) => {
const startTimeMs = performance.now();
telemetry.recordGenerateActionInputLogs(options.name, input);
andrewbrook marked this conversation as resolved.
Show resolved Hide resolved

return runner(input, getStreamingCallback())
.then((response) => {
const timedResponse = {
...response,
latencyMs: performance.now() - startTimeMs,
};
telemetry.recordGenerateActionOutputLogs(options.name, response);
telemetry.recordGenerateActionMetrics(options.name, input, {
response: timedResponse,
});
Expand Down
13 changes: 5 additions & 8 deletions js/ai/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from '@genkit-ai/core/tracing';
import { ValueType } from '@opentelemetry/api';
import { createHash } from 'crypto';
import { GenerateOptions } from './generate.js';
import {
GenerateRequest,
GenerateResponseData,
Expand Down Expand Up @@ -171,7 +170,6 @@ export function recordGenerateActionMetrics(

export function recordGenerateActionInputLogs(
model: string,
options: GenerateOptions,
input: GenerateRequest
) {
const flowName = traceMetadataAls?.getStore()?.flowName;
Expand All @@ -180,11 +178,11 @@ export function recordGenerateActionInputLogs(
const sharedMetadata = { model, path, qualifiedPath, flowName };
logger.logStructured(`Config[${path}, ${model}]`, {
...sharedMetadata,
temperature: options.config?.temperature,
topK: options.config?.topK,
topP: options.config?.topP,
maxOutputTokens: options.config?.maxOutputTokens,
stopSequences: options.config?.stopSequences,
temperature: input.config?.temperature,
topK: input.config?.topK,
topP: input.config?.topP,
maxOutputTokens: input.config?.maxOutputTokens,
stopSequences: input.config?.stopSequences,
source: 'ts',
sourceVersion: GENKIT_VERSION,
});
Expand All @@ -208,7 +206,6 @@ export function recordGenerateActionInputLogs(

export function recordGenerateActionOutputLogs(
model: string,
options: GenerateOptions,
output: GenerateResponseData
) {
const flowName = traceMetadataAls?.getStore()?.flowName;
Expand Down
Loading