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

Add a source and source version dimension to all metrics for TS. #161

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 10 additions & 4 deletions go/genkit/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func initInstruments() (*metricInstruments, error) {
}

func writeActionSuccess(ctx context.Context, actionName string, latency time.Duration) {
recordAction(ctx, latency, attribute.String("name", actionName))
recordAction(ctx, latency,
attribute.String("name", actionName),
attribute.String("source", "go"))
}

func writeActionFailure(ctx context.Context, actionName string, latency time.Duration, err error) {
Expand All @@ -76,7 +78,8 @@ func writeActionFailure(ctx context.Context, actionName string, latency time.Dur
// TODO(jba): Mitigate against high-cardinality dimensions that arise from
// many different error messages, perhaps by taking a prefix of the error
// message.
attribute.String("errorMessage", err.Error()))
attribute.String("errorMessage", err.Error()),
attribute.String("source", "go"))
}

func errorCode(err error) int {
Expand All @@ -94,7 +97,9 @@ func recordAction(ctx context.Context, latency time.Duration, attrs ...attribute
}

func writeFlowSuccess(ctx context.Context, flowName string, latency time.Duration) {
recordFlow(ctx, latency, attribute.String("name", flowName))
recordFlow(ctx, latency,
attribute.String("name", flowName),
attribute.String("source", "go"))
}

func writeFlowFailure(ctx context.Context, flowName string, latency time.Duration, err error) {
Expand All @@ -103,7 +108,8 @@ func writeFlowFailure(ctx context.Context, flowName string, latency time.Duratio
// TODO(jba): Mitigate against high-cardinality dimensions that arise from
// many different error messages, perhaps by taking a prefix of the error
// message.
attribute.String("errorMessage", err.Error()))
attribute.String("errorMessage", err.Error()),
attribute.String("source", "go"))
}

func recordFlow(ctx context.Context, latency time.Duration, attrs ...attribute.KeyValue) {
Expand Down
11 changes: 11 additions & 0 deletions js/ai/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { GENKIT_VERSION } from '@genkit-ai/core';
import { logger } from '@genkit-ai/core/logging';
import {
internalMetricNamespaceWrap,
Expand Down Expand Up @@ -106,6 +107,8 @@ type SharedDimensions = {
temperature?: number;
topK?: number;
topP?: number;
source?: string;
sourceVersion?: string;
};

export function recordGenerateActionMetrics(
Expand All @@ -131,6 +134,8 @@ export function recordGenerateActionMetrics(
outputImages: opts.response?.usage?.outputImages,
latencyMs: opts.response?.latencyMs,
err: opts.err,
source: 'ts',
sourceVersion: GENKIT_VERSION,
});
}

Expand All @@ -148,6 +153,8 @@ export function recordGenerateActionInputLogs(
topP: options.config?.topP,
maxOutputTokens: options.config?.maxOutputTokens,
stopSequences: options.config?.stopSequences,
source: 'ts',
sourceVersion: GENKIT_VERSION,
});

const messages = input.messages.length;
Expand Down Expand Up @@ -299,6 +306,8 @@ function doRecordGenerateActionMetrics(
outputImages?: number;
latencyMs?: number;
err?: any;
source?: string;
sourceVersion: string;
}
) {
const shared: SharedDimensions = {
Expand All @@ -307,6 +316,8 @@ function doRecordGenerateActionMetrics(
temperature: dimensions.temperature,
topK: dimensions.topK,
topP: dimensions.topP,
source: dimensions.source,
sourceVersion: dimensions.sourceVersion,
};

generateActionCounter.add(1, {
Expand Down
5 changes: 5 additions & 0 deletions js/core/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { ValueType } from '@opentelemetry/api';
import { GENKIT_VERSION } from './index.js';
import {
internalMetricNamespaceWrap,
MetricCounter,
Expand All @@ -40,6 +41,8 @@ const actionLatencies = new MetricHistogram(_N('latency'), {
export function writeActionSuccess(actionName: string, latencyMs: number) {
const dimensions = {
name: actionName,
source: 'ts',
sourceVersion: GENKIT_VERSION,
};
actionCounter.add(1, dimensions);
actionLatencies.record(latencyMs, dimensions);
Expand All @@ -54,6 +57,8 @@ export function writeActionFailure(
name: actionName,
errorCode: err?.code,
errorMessage: err?.message,
source: 'ts',
sourceVersion: GENKIT_VERSION,
};
actionCounter.add(1, dimensions);
actionLatencies.record(latencyMs, dimensions);
Expand Down
11 changes: 11 additions & 0 deletions js/flow/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { GENKIT_VERSION } from '@genkit-ai/core';
import { logger } from '@genkit-ai/core/logging';
import {
internalMetricNamespaceWrap,
Expand Down Expand Up @@ -47,12 +48,16 @@ export function recordError(err: any) {
name: err.name,
message: err.message,
stack: err.stack,
source: 'ts',
sourceVersion: GENKIT_VERSION,
});
}

export function writeFlowSuccess(flowName: string, latencyMs: number) {
const dimensions = {
name: flowName,
source: 'ts',
sourceVersion: GENKIT_VERSION,
};
flowCounter.add(1, dimensions);
flowLatencies.record(latencyMs, dimensions);
Expand All @@ -67,6 +72,8 @@ export function writeFlowFailure(
name: flowName,
errorCode: err?.code,
errorMessage: err?.message,
source: 'ts',
sourceVersion: GENKIT_VERSION,
};
flowCounter.add(1, dimensions);
flowLatencies.record(latencyMs, dimensions);
Expand All @@ -84,6 +91,8 @@ export function logRequest(flowName: string, req: express.Request) {
query: req.query,
originalUrl: req.originalUrl,
path: `/${flowName}`,
source: 'ts',
sourceVersion: GENKIT_VERSION,
});
}

Expand All @@ -93,5 +102,7 @@ export function logResponse(flowName: string, respCode: number, respBody: any) {
path: `/${flowName}`,
code: respCode,
body: respBody,
source: 'ts',
sourceVersion: GENKIT_VERSION,
});
}
Loading