Skip to content

Commit

Permalink
Merge pull request #84 from parea-ai/PAI-1458-add-log-sampling-params…
Browse files Browse the repository at this point in the history
…-to-tracing-decorator

feat: sample logs
  • Loading branch information
joschkabraun authored Aug 12, 2024
2 parents 4c44f31 + e39e842 commit 012da83
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type Completion = {
log_omit_inputs?: boolean;
log_omit_outputs?: boolean;
log_omit?: boolean;
log_sample_rate?: number;
experiment_uuid?: string | null;
project_uuid?: string;
};
Expand Down Expand Up @@ -164,6 +165,7 @@ export type TraceLog = EvaluatedLog & {
deployment_id?: string;
output_for_eval_metrics?: string;
apply_eval_frac?: number;
log_sample_rate?: number;
cache_hit?: boolean;
evaluation_metric_names?: string[];
feedback_score?: number;
Expand Down Expand Up @@ -197,6 +199,7 @@ export type TraceOptions = {
applyEvalFrac?: number;
deploymentId?: string;
target?: string;
logSampleRate?: number;
};

export type UpdateLog = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/core/Trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Trace {
executionOrder: number = 0,
) {
this.evalFuncs = options?.evalFuncs || [];
const { endUserIdentifier, sessionId, deploymentId, ...opts } = options || {};
const { endUserIdentifier, sessionId, deploymentId, logSampleRate, ...opts } = options || {};

this.id = genTraceId();
this.name = name;
Expand All @@ -56,6 +56,7 @@ export class Trace {
root_trace_id: this.rootId,
children: this.children,
end_user_identifier: endUserIdentifier,
log_sample_rate: logSampleRate,
session_id: sessionId,
deployment_id: deploymentId,
...opts,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/core/TraceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class TraceManager {
options.target = parentTarget;
}

if (parentTrace && parentTrace.getLog().log_sample_rate !== options.logSampleRate) {
options.logSampleRate = parentTrace.getLog().log_sample_rate;
}

const trace = new Trace(name, options, parentId, rootId, depth, executionOrder);

if (parentTrace) {
Expand Down

0 comments on commit 012da83

Please sign in to comment.