Observability
Tracing with OpenTelemetry and structured logging with slog. Use when adding observability to services, handlers, or debugging production issues.From its SKILL.md
npx -y skills add cemezgin/go-service-guide --skill observabilityAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 6 stars6 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
1.7 KB, as published. Nobody here has run it
Observability
References: Examples
Tracing (OpenTelemetry)
Mandatory for: repositories, API clients, Lambdas, usecases
func (s *Service) GetOrder(ctx context.Context, id string) (*Order, error) {
ctx, span := tracing.StartSpan(ctx, "Service.GetOrder")
defer span.End()
span.SetAttributes(attribute.String("order.id", id))
// business logic...
}
Structured Logging (slog)
Use log/slog with structured JSON:
slog.InfoContext(ctx, "order retrieved",
"order_id", orderID,
"reference_id", referenceID,
)
Log Levels
| Level | Use When |
|---|---|
| INFO | Normal operations, successful requests |
| WARN | Recoverable errors, degraded state, fallbacks used |
| ERROR | Failures requiring attention, unrecoverable errors |
Lambda Lifecycle
func main() {
ctx := context.Background()
otelShutdown, err := otel.Setup(ctx)
if err != nil {
fmt.Printf("Error setting up OpenTelemetry: %v\n", err)
os.Exit(1)
}
defer func() {
if err := otelShutdown(context.Background()); err != nil {
fmt.Printf("Error shutting down: %v\n", err)
}
}()
lambda.Start(otellambda.InstrumentHandler(handler))
}
HTTP Client Tracing
client := tracing.NewRestyClient(baseURL,
tracing.WithTimeout(30*time.Second),
tracing.WithRetryCount(3),
)