Skip to content

Conversation

@DEVMANISHOFFL
Copy link

Description

Added go/MIDDLEWARE.md to document how to use Middleware in the Go SDK.

This guide includes:

  • Explanation of the StreamingFunc wrapper pattern.
  • Code samples for common use cases:
    • Logging: detailed request/response logging.
    • Authentication: context-based user validation.

Issues Resolved

Fixes #2822

Checklist (if applicable):

@github-actions github-actions bot added docs Improvements or additions to documentation go labels Dec 29, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @DEVMANISHOFFL, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the Go SDK by introducing detailed documentation for middleware implementation, making it easier for developers to add cross-cutting concerns like logging and authentication to their flows. Concurrently, it enhances the GenkitError type to support standard Go error wrapping, providing more robust error handling capabilities. Finally, telemetry data export is optimized to focus solely on Genkit-specific spans, streamlining monitoring and debugging efforts.

Highlights

  • New Go Middleware Documentation: A new guide, go/MIDDLEWARE.md, has been added to comprehensively document how to implement and use middleware in the Go SDK, including the StreamingFunc pattern and practical examples for logging and authentication.
  • Enhanced Error Wrapping in GenkitError: The GenkitError type in go/core/error.go now supports error wrapping by including an originalError field and implementing the Unwrap() method, improving compatibility with Go's standard error inspection functions like errors.Is and errors.As.
  • Telemetry Span Filtering: Telemetry export has been refined in go/core/tracing/tracing.go to include a filteringExporter, ensuring that only spans specifically related to Genkit (those with 'genkit' prefixed attributes) are exported, reducing noise in telemetry data.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@DEVMANISHOFFL DEVMANISHOFFL changed the title Docs/go middleware docs(go): add middleware documentation and examples Dec 29, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces documentation for Go middleware, which is a great addition for developers using the Go SDK. The changes also include an important improvement to error handling by enabling error wrapping, making it compatible with errors.Is and errors.As. Additionally, telemetry tracing is refined to filter for Genkit-specific spans, reducing noise. My review includes a few minor suggestions for the documentation and a small performance improvement in the tracing code.

go/MIDDLEWARE.md Outdated

import (
"context"
"fmt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The fmt package is imported but not used in this code example. Please remove this line to keep the code clean.

go/MIDDLEWARE.md Outdated
"log"

"github.com/firebase/genkit/go/core"
"github.com/firebase/genkit/go/genkit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The genkit package is imported but not used in this code example. Please remove this line to keep the code clean.


return output, err
}
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's a standard convention to end files with a newline character. Please add one here.

Suggested change
}
}

go/README.md Outdated
This package is the Go version of Genkit, a framework for building
AI-powered apps. See: https://genkit.dev/go/docs/get-started-go

- [Middleware Guide](MIDDLEWARE.md): Learn how to add logging, authentication, and custom logic to your flows.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There appears to be a typo with a trailing 'c' at the end of this line.

Suggested change
- [Middleware Guide](MIDDLEWARE.md): Learn how to add logging, authentication, and custom logic to your flows.c
- [Middleware Guide](MIDDLEWARE.md): Learn how to add logging, authentication, and custom logic to your flows.

}

func (e *filteringExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error {
var genkitSpans []sdktrace.ReadOnlySpan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve performance and avoid potential reallocations inside the loop, it's a good practice to pre-allocate the slice with a known capacity. Since the maximum size of genkitSpans is len(spans), you can initialize it with that capacity.

Suggested change
var genkitSpans []sdktrace.ReadOnlySpan
genkitSpans := make([]sdktrace.ReadOnlySpan, 0, len(spans))

Signed-off-by: devmanishofficial <devmanishofficial@gmail.com>
Signed-off-by: devmanishofficial <devmanishofficial@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation go

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Docs] Document middleware

1 participant