diff --git a/framework/version b/framework/version index a9707166ba..b668c3b2c1 100644 --- a/framework/version +++ b/framework/version @@ -1 +1 @@ -1.0.15 +1.0.16 diff --git a/plugins/governance/version b/plugins/governance/version index db6fb4a911..9d4f8239dc 100644 --- a/plugins/governance/version +++ b/plugins/governance/version @@ -1 +1 @@ -1.2.8 +1.2.9 diff --git a/plugins/jsonparser/version b/plugins/jsonparser/version index a77d7d9272..5975b143a0 100644 --- a/plugins/jsonparser/version +++ b/plugins/jsonparser/version @@ -1 +1 @@ -1.2.7 \ No newline at end of file +1.2.8 \ No newline at end of file diff --git a/plugins/logging/version b/plugins/logging/version index db6fb4a911..9d4f8239dc 100644 --- a/plugins/logging/version +++ b/plugins/logging/version @@ -1 +1 @@ -1.2.8 +1.2.9 diff --git a/plugins/maxim/main.go b/plugins/maxim/main.go index 4083333e42..8af0db1acf 100644 --- a/plugins/maxim/main.go +++ b/plugins/maxim/main.go @@ -57,9 +57,12 @@ type ContextKey string // This constant provides a consistent key for tracking request traces // throughout the request/response lifecycle. const ( - SessionIDKey ContextKey = "session-id" - TraceIDKey ContextKey = "trace-id" - GenerationIDKey ContextKey = "generation-id" + SessionIDKey ContextKey = "session-id" + TraceIDKey ContextKey = "trace-id" + TraceNameKey ContextKey = "trace-name" + GenerationIDKey ContextKey = "generation-id" + GenerationNameKey ContextKey = "generation-name" + TagsKey ContextKey = "maxim-tags" ) // The plugin provides request/response tracing functionality by integrating with Maxim's logging system. @@ -113,7 +116,10 @@ func (plugin *Plugin) GetName() string { // - error: Any error that occurred during trace/generation creation func (plugin *Plugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.PluginShortCircuit, error) { var traceID string + var traceName string var sessionID string + var generationName string + var tags map[string]string // Check if context already has traceID and generationID if ctx != nil { @@ -130,20 +136,42 @@ func (plugin *Plugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) if existingSessionID, ok := (*ctx).Value(SessionIDKey).(string); ok && existingSessionID != "" { sessionID = existingSessionID } + + if existingTraceName, ok := (*ctx).Value(TraceNameKey).(string); ok && existingTraceName != "" { + traceName = existingTraceName + } + + if existingGenerationName, ok := (*ctx).Value(GenerationNameKey).(string); ok && existingGenerationName != "" { + generationName = existingGenerationName + } + + // retrieve all tags from context + // the transport layer now stores all maxim tags in a single map + if tagsValue := (*ctx).Value(TagsKey); tagsValue != nil { + if tagsMap, ok := tagsValue.(map[string]string); ok { + tags = make(map[string]string) + for key, value := range tagsMap { + tags[key] = value + } + } + } } // Determine request type and set appropriate tags var requestType string - var tags map[string]string var messages []logging.CompletionRequest var latestMessage string + // Initialize tags map if not already initialized from context + if tags == nil { + tags = make(map[string]string) + } + + // Add model to tags + tags["model"] = req.Model + if req.Input.ChatCompletionInput != nil { requestType = "chat_completion" - tags = map[string]string{ - "action": "chat_completion", - "model": req.Model, - } for _, message := range *req.Input.ChatCompletionInput { messages = append(messages, logging.CompletionRequest{ Role: string(message.Role), @@ -171,10 +199,6 @@ func (plugin *Plugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) } } else if req.Input.TextCompletionInput != nil { requestType = "text_completion" - tags = map[string]string{ - "action": "text_completion", - "model": req.Model, - } messages = append(messages, logging.CompletionRequest{ Role: string(schemas.ModelChatMessageRoleUser), Content: req.Input.TextCompletionInput, @@ -182,13 +206,20 @@ func (plugin *Plugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) latestMessage = *req.Input.TextCompletionInput } + // Set action tag after determining request type + tags["action"] = requestType + if traceID == "" { // If traceID is not set, create a new trace traceID = uuid.New().String() + name := fmt.Sprintf("bifrost_%s", requestType) + if traceName != "" { + name = traceName + } traceConfig := logging.TraceConfig{ Id: traceID, - Name: maxim.StrPtr(fmt.Sprintf("bifrost_%s", requestType)), + Name: maxim.StrPtr(name), Tags: &tags, } @@ -213,14 +244,20 @@ func (plugin *Plugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) generationID := uuid.New().String() - plugin.logger.AddGenerationToTrace(traceID, &logging.GenerationConfig{ + generationConfig := logging.GenerationConfig{ Id: generationID, Model: req.Model, Provider: string(req.Provider), Tags: &tags, Messages: messages, ModelParameters: modelParams, - }) + } + + if generationName != "" { + generationConfig.Name = &generationName + } + + plugin.logger.AddGenerationToTrace(traceID, &generationConfig) if ctx != nil { if _, ok := (*ctx).Value(TraceIDKey).(string); !ok { diff --git a/plugins/maxim/version b/plugins/maxim/version index 3c43790f5d..c04c650a7a 100644 --- a/plugins/maxim/version +++ b/plugins/maxim/version @@ -1 +1 @@ -1.2.6 +1.2.7 diff --git a/plugins/mocker/version b/plugins/mocker/version index 3c43790f5d..c04c650a7a 100644 --- a/plugins/mocker/version +++ b/plugins/mocker/version @@ -1 +1 @@ -1.2.6 +1.2.7 diff --git a/plugins/semanticcache/version b/plugins/semanticcache/version index 9d4f8239dc..db6fb4a911 100644 --- a/plugins/semanticcache/version +++ b/plugins/semanticcache/version @@ -1 +1 @@ -1.2.9 +1.2.8 diff --git a/plugins/telemetry/version b/plugins/telemetry/version index c04c650a7a..db6fb4a911 100644 --- a/plugins/telemetry/version +++ b/plugins/telemetry/version @@ -1 +1 @@ -1.2.7 +1.2.8 diff --git a/transports/bifrost-http/lib/ctx.go b/transports/bifrost-http/lib/ctx.go index 85144b895b..5f92dabda6 100644 --- a/transports/bifrost-http/lib/ctx.go +++ b/transports/bifrost-http/lib/ctx.go @@ -77,6 +77,9 @@ func ConvertToBifrostContext(ctx *fasthttp.RequestCtx, allowDirectKeys bool) *co } bifrostCtx = context.WithValue(bifrostCtx, schemas.BifrostContextKey("request-id"), requestID) + // Initialize tags map for collecting maxim tags + maximTags := make(map[string]string) + // Then process other headers ctx.Request.Header.All()(func(key, value []byte) bool { keyStr := strings.ToLower(string(key)) @@ -100,6 +103,20 @@ func ConvertToBifrostContext(ctx *fasthttp.RequestCtx, allowDirectKeys bool) *co if labelName == string(maxim.SessionIDKey) { bifrostCtx = context.WithValue(bifrostCtx, maxim.ContextKey(labelName), string(value)) } + + if labelName == string(maxim.TraceNameKey) { + bifrostCtx = context.WithValue(bifrostCtx, maxim.ContextKey(labelName), string(value)) + } + + if labelName == string(maxim.GenerationNameKey) { + bifrostCtx = context.WithValue(bifrostCtx, maxim.ContextKey(labelName), string(value)) + } + + // apart from these all headers starting with x-bf-maxim- are keys for tags + // collect them in the maximTags map + if labelName != string(maxim.GenerationIDKey) && labelName != string(maxim.TraceIDKey) && labelName != string(maxim.SessionIDKey) && labelName != string(maxim.TraceNameKey) && labelName != string(maxim.GenerationNameKey) { + maximTags[labelName] = string(value) + } } if strings.HasPrefix(keyStr, "x-bf-mcp-") { @@ -174,6 +191,11 @@ func ConvertToBifrostContext(ctx *fasthttp.RequestCtx, allowDirectKeys bool) *co return true }) + // Store the collected maxim tags in the context + if len(maximTags) > 0 { + bifrostCtx = context.WithValue(bifrostCtx, maxim.ContextKey(maxim.TagsKey), maximTags) + } + if allowDirectKeys { // Extract API key from Authorization header (Bearer format) or x-api-key header var apiKey string diff --git a/transports/version b/transports/version index f2ae0b4a2c..0b1f1edf11 100644 --- a/transports/version +++ b/transports/version @@ -1 +1 @@ -1.2.12 +1.2.13