-
Notifications
You must be signed in to change notification settings - Fork 620
docs(go): add middleware documentation and examples #4019
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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 Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go/MIDDLEWARE.md
Outdated
| "log" | ||
|
|
||
| "github.com/firebase/genkit/go/core" | ||
| "github.com/firebase/genkit/go/genkit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| return output, err | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a typo with a trailing 'c' at the end of this line.
| - [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. |
go/core/tracing/tracing.go
Outdated
| } | ||
|
|
||
| func (e *filteringExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error { | ||
| var genkitSpans []sdktrace.ReadOnlySpan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| var genkitSpans []sdktrace.ReadOnlySpan | |
| genkitSpans := make([]sdktrace.ReadOnlySpan, 0, len(spans)) |
bb79d88 to
a01ef92
Compare
Signed-off-by: devmanishofficial <devmanishofficial@gmail.com>
Signed-off-by: devmanishofficial <devmanishofficial@gmail.com>
a01ef92 to
eee8bc3
Compare
Description
Added
go/MIDDLEWARE.mdto document how to use Middleware in the Go SDK.This guide includes:
StreamingFuncwrapper pattern.Issues Resolved
Fixes #2822
Checklist (if applicable):