Index of every page on this site: llms.txt
All skills
genkit-ai avatar

/developing-genkit-go

@d12c988
by Genkitgenkit-ai/skills40 stars
13
Run it yourself

Provides guidance on developing AI-powered applications using Genkit in Go. Use when the user asks to build AI features, agents, flows, or tools in Go using Genkit, or when working with Genkit Go code involving generation, prompts, streaming, tool calling, or model providers. Don't use for Genkit in JavaScript/TypeScript, Python, or Dart.

Use this Skill: https://skilld.dev/gh/genkit-ai/skills/developing-genkit-go

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesobservability.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Observability (Tracing, OpenTelemetry, Reflection API)

Pluggable instrumentation, otelgenai, and the reflection API settings require Genkit Go v1.14.0+.


How tracing works

  • In dev (genkit start), Genkit posts spans straight to the Developer UI's telemetry server; no OpenTelemetry SDK is on that path. The Dev UI shows Genkit spans only: spans you write through OTel directly (otelhttp, trace.SpanFromContext(ctx)) go to your OTel backend, not the Dev UI.
  • Elsewhere, spans go through pluggable instrumentation providers. The default, &tracing.OTelInstrumentation{}, creates OTel spans with genkit:* attributes on the TracerProvider you register. Genkit installs none itself, so nothing leaves the process until you (or a plugin such as Firebase) register one.
  • Write span metadata with tracing.SetSpanMetadata. The old tracing.TracerProvider, tracing.Tracer, and WriteTelemetry* helpers are deprecated.

Export OpenTelemetry GenAI semantic conventions (otelgenai)

Sends Genkit telemetry to any OTLP backend in the vendor-neutral gen_ai.* shape (chat <model> spans, token usage and duration metrics).

go get github.com/firebase/genkit/go/plugins/otelgenai
go get go.opentelemetry.io/contrib/exporters/autoexport
import (
	"github.com/firebase/genkit/go/core/tracing"
	"github.com/firebase/genkit/go/plugins/otelgenai"
)

// 1. The app owns the OTel SDK: register TracerProvider / MeterProvider /
//    LoggerProvider (e.g. with autoexport), and defer their Shutdown.
// 2. Set the GenAI instrumentation before genkit.Init:
tracing.SetInstrumentation(otelgenai.New(&otelgenai.Options{
	ContentCapturingMode: otelgenai.SpanOnly, // default NoContent; may contain PII
	EmitToolSpans:        true,
}))
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))

otelgenai.Options: ContentCapturingMode (NoContent, SpanOnly, EventOnly, SpanAndEvent; falls back to OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT), CaptureActionIO, EmitToolSpans, DisableMetrics, ScopeName, and explicit TracerProvider/MeterProvider/LoggerProvider (default: the globals). Pass nil for the defaults.

Gotchas:

  • It replaces the default encoding. To export both, list both: tracing.SetInstrumentation(&tracing.OTelInstrumentation{}, otelgenai.New(nil)).
  • Do not use it alone with the Firebase or Google Cloud telemetry plugins. They build metrics/logs from the genkit:* attributes; without OTelInstrumentation in the list their Genkit metrics stop.
  • EventOnly content goes to the OTel logs signal, which trace-only backends like Jaeger can't show.
  • Runnable sample: go/samples/otel-genai (Jaeger + collector, no Docker).

Custom instrumentation

Implement tracing.Instrumentation (StartSpan returns a tracing.Span with TraceInfo, SetMetadata, and End). Genkit owns the run, so a provider observes it but cannot skip or repeat it. Return a nil Span to ignore a span.

Scope providers to one context (one request, one agent run) with tracing.WithInstrumentation(ctx, providers...). aix.Observer is a ready-made scoped provider that reports each model call, typed; the Budget middleware is built on it:

ctx = tracing.WithInstrumentation(ctx, aix.Observer{
	ModelDone: func(ctx context.Context, call *aix.ModelCall) {
		if u := call.Response.Usage; u != nil {
			meter.Add(tenant, call.Model, u)
		}
	},
})
out, err := supportAgent.RunText(ctx, msg)

Reflection API outside dev

The CLI and Dev UI talk to the app through the reflection API. By default it runs only under GENKIT_ENV=dev on 127.0.0.1:3100+. To run it elsewhere (e.g. staging), turn it on explicitly and protect it:

GENKIT_REFLECTION_ENABLED=true \
GENKIT_REFLECTION_HOST=0.0.0.0 \
GENKIT_REFLECTION_PORT=3100 \
GENKIT_REFLECTION_SECRET_TOKEN="$(openssl rand -hex 32)" \
./server
  • GENKIT_REFLECTION_ENABLED: true on anywhere, false off even under dev. Any other value makes genkit.Init panic.
  • GENKIT_REFLECTION_SECRET_TOKEN: every request must send it in the x-genkit-reflection-secret header (/api/__health stays open). Without it, anyone who can reach the port can run every flow, model, and tool.
  • genkit.WithReflectionPort(3200) binds exactly that port (panics if taken); 0 lets the OS pick. The env var wins over the option, and neither turns the API on.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2d3 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    The skill provides comprehensive documentation and code samples for developing AI applications with Genkit in Go. It includes instructions for installing the Genkit CLI from an official source and documents security features like tool approval and filesystem sandboxing. No malicious patterns were detected.

  • Socket2d

    No alerts

  • Snyk3d

    Risk: MEDIUM · 2 issues

Signed by skilld at d12c988. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 5 days ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}

README badge

README badge for genkit-ai/skills/developing-genkit-go