diff --git a/go/genkit/metrics.go b/go/genkit/metrics.go index adfcaa09b..ef7920536 100644 --- a/go/genkit/metrics.go +++ b/go/genkit/metrics.go @@ -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) { @@ -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 { @@ -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) { @@ -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) { diff --git a/js/ai/src/telemetry.ts b/js/ai/src/telemetry.ts index 8c2168f5c..039f7986b 100644 --- a/js/ai/src/telemetry.ts +++ b/js/ai/src/telemetry.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { GENKIT_VERSION } from '@genkit-ai/core'; import { logger } from '@genkit-ai/core/logging'; import { internalMetricNamespaceWrap, @@ -106,6 +107,8 @@ type SharedDimensions = { temperature?: number; topK?: number; topP?: number; + source?: string; + sourceVersion?: string; }; export function recordGenerateActionMetrics( @@ -131,6 +134,8 @@ export function recordGenerateActionMetrics( outputImages: opts.response?.usage?.outputImages, latencyMs: opts.response?.latencyMs, err: opts.err, + source: 'ts', + sourceVersion: GENKIT_VERSION, }); } @@ -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; @@ -299,6 +306,8 @@ function doRecordGenerateActionMetrics( outputImages?: number; latencyMs?: number; err?: any; + source?: string; + sourceVersion: string; } ) { const shared: SharedDimensions = { @@ -307,6 +316,8 @@ function doRecordGenerateActionMetrics( temperature: dimensions.temperature, topK: dimensions.topK, topP: dimensions.topP, + source: dimensions.source, + sourceVersion: dimensions.sourceVersion, }; generateActionCounter.add(1, { diff --git a/js/core/src/telemetry.ts b/js/core/src/telemetry.ts index b7bc7bed3..46cafacf5 100644 --- a/js/core/src/telemetry.ts +++ b/js/core/src/telemetry.ts @@ -15,6 +15,7 @@ */ import { ValueType } from '@opentelemetry/api'; +import { GENKIT_VERSION } from './index.js'; import { internalMetricNamespaceWrap, MetricCounter, @@ -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); @@ -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); diff --git a/js/flow/src/telemetry.ts b/js/flow/src/telemetry.ts index e62234613..6562e5e05 100644 --- a/js/flow/src/telemetry.ts +++ b/js/flow/src/telemetry.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { GENKIT_VERSION } from '@genkit-ai/core'; import { logger } from '@genkit-ai/core/logging'; import { internalMetricNamespaceWrap, @@ -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); @@ -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); @@ -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, }); } @@ -93,5 +102,7 @@ export function logResponse(flowName: string, respCode: number, respBody: any) { path: `/${flowName}`, code: respCode, body: respBody, + source: 'ts', + sourceVersion: GENKIT_VERSION, }); }