Sample
go.uber.org/zap/exp v0.3.0: zapslog.NewHandler, zapslog.WithName, zapslog.WithCaller
Verified sample for golang go.uber.org/zap/exp v0.3.0: zapslog.NewHandler, zapslog.WithName, zapslog.WithCaller. The contract ran on go 1.26 · linux…
sha256:d8a991d0832b523415b8a068e180f72defd0f210434a44e3c672e422e0b2cde4
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-28 |
Case
HOW- Goal
- verify pkg:golang/go.uber.org/zap/exp@v0.3.0
- Packages
- Symbols
-
- zapslog.NewHandler
- zapslog.WithName
- zapslog.WithCaller
- zapslog.AddStacktraceAt
- zapfield.Str
- zapfield.Strs
- Environment
- go 1.26.6
- Created
- 2026-08-28T04:35:10Z
Contract
- zapslog.NewHandler wraps a zapcore.Core to provide a slog.Handler bridging structured log records to Zap encoders.
- zapslog.NewHandler respects slog log levels, properly emitting enabled levels and suppressing filtered levels.
- zapslog.WithName annotates emitted log entries with the configured logger name.
- zapslog.WithCaller attaches caller filename and line number to emitted log entries.
- zapslog.AddStacktraceAt records stack traces for log entries at or above the configured log level.
- slog.Handler.WithGroup and WithAttrs correctly namespace and nest structured fields within Zap log entries.
- zapfield.Str and zapfield.Strs construct type-safe zap.Field instances for custom string types and string slices.
Files
- PROMPT.md
- contract_test.go
- csx.json
- go.mod
- go.sum
- spec.json
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:golang/go.uber.org/zap/exp@v0.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.uber.org/zap/exp@v0.3.0
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
package sample_test
import (
"bytes"
"context"
"encoding/json"
"log/slog"
"testing"
"time"
"go.uber.org/zap"
"go.uber.org/zap/exp/zapfield"
"go.uber.org/zap/exp/zapslog"
"go.uber.org/zap/zapcore"
)
func newBufferLogger(level zapcore.Level) (*zap.Logger, *bytes.Buffer) {
buf := &bytes.Buffer{}
encCfg := zapcore.EncoderConfig{
MessageKey: "msg",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
StacktraceKey: "stacktrace",
TimeKey: "time",
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
core := zapcore.NewCore(
zapcore.NewJSONEncoder(encCfg),
zapcore.AddSync(buf),
level,
)
return zap.New(core), buf
}
func parseLogEntry(t *testing.T, buf *bytes.Buffer) map[string]any {
t.Helper()
var entry map[string]any
if err := json.Unmarshal(buf.Bytes(), &entry); err != nil {
t.Fatalf("failed to decode JSON log: %v (raw: %s)", err, buf.String())
}
return entry
}
func TestZapslogHandlerBasicLogging(t *testing.T) {
zapLogger, buf := newBufferLogger(zap.DebugLevel)
handler := zapslog.NewHandler(zapLogger.Core())
logger := slog.New(handler)
ctx := context.Background()
logger.InfoContext(ctx, "database connected", "host", "localhost", "port", 5432)
entry := parseLogEntry(t, buf)
if entry["msg"] != "database connected" {
t.Errorf("expected msg 'database connected', got %v", entry["msg"])
}
if entry["level"] != "info" {
t.Errorf("expected level 'info', got %v", entry["level"])
}
if entry["host"] != "localhost" {
t.Errorf("expected host 'localhost', got %v", entry["host"])
}
if entry["port"] != float64(5432) {
t.Errorf("expected port 5432, got %v", entry["port"])
}
}
func TestZapslogHandlerLevelFiltering(t *testing.T) {
zapLogger, buf := newBufferLogger(zap.WarnLevel)
handler := zapslog.NewHandler(zapLogger.Core())
logger := slog.New(handler)
logger.Info("info message should be ignored")
if buf.Len() != 0 {
t.Errorf("expected info message to be filtered out at WarnLevel, got: %s", buf.String())
}
logger.Warn("warning message should be recorded")
entry := parseLogEntry(t, buf)
if entry["msg"] != "warning message should be recorded" {
t.Errorf("expected warning msg, got %v", entry["msg"])
}
if entry["level"] != "warn" {
t.Errorf("expected level 'warn', got %v", entry["level"])
}
}
func TestZapslogOptions(t *testing.T) {
zapLogger, buf := newBufferLogger(zap.DebugLevel)
handler := zapslog.NewHandler(
zapLogger.Core(),
zapslog.WithName("service.auth"),
zapslog.WithCaller(true),
zapslog.AddStacktraceAt(slog.LevelError),
)
logger := slog.New(handler)
logger.Info("user logged in", "user_id", "u-12345")
entry := parseLogEntry(t, buf)
if entry["logger"] != "service.auth" {
t.Errorf("expected logger 'service.auth', got %v", entry["logger"])
}
if entry["caller"] == nil {
t.Errorf("expected caller field present")
}
if entry["stacktrace"] != nil {
t.Errorf("expected no stacktrace for info level")
}
buf.Reset()
logger.Error("authentication failed", "reason", "invalid_token")
errEntry := parseLogEntry(t, buf)
if errEntry["stacktrace"] == nil {
t.Errorf("expected stacktrace for error level")
}
}
func TestZapslogGroupsAndAttributes(t *testing.T) {
zapLogger, buf := newBufferLogger(zap.DebugLevel)
handler := zapslog.NewHandler(zapLogger.Core())
logger := slog.New(handler).
With("env", "production").
WithGroup("http").
With("method", "GET")
logger.Info("handled request", "path", "/status", "code", 200, "latency", time.Millisecond*25)
entry := parseLogEntry(t, buf)
if entry["env"] != "production" {
t.Errorf("expected env 'production', got %v", entry["env"])
}
httpGroup, ok := entry["http"].(map[string]any)
if !ok {
t.Fatalf("expected http group object, got %v", entry["http"])
}
if httpGroup["method"] != "GET" {
t.Errorf("expected http.method 'GET', got %v", httpGroup["method"])
}
if httpGroup["path"] != "/status" {
t.Errorf("expected http.path '/status', got %v", httpGroup["path"])
}
if httpGroup["code"] != float64(200) {
t.Errorf("expected http.code 200, got %v", httpGroup["code"])
}
}
func TestZapfieldConstructors(t *testing.T) {
type CustomKey string
type CustomVal string
var k CustomKey = "metric_name"
var v CustomVal = "cpu_usage"
field := zapfield.Str(k, v)
if field.Key != "metric_name" || field.String != "cpu_usage" {
t.Errorf("zapfield.Str failed: key=%s val=%s", field.Key, field.String)
}
var sliceKey CustomKey = "tags"
sliceVals := []CustomVal{"env:prod", "region:us-east-1"}
sliceField := zapfield.Strs(sliceKey, sliceVals)
if sliceField.Key != "tags" {
t.Errorf("zapfield.Strs key mismatch: got %s", sliceField.Key)
}
enc := zapcore.NewJSONEncoder(zapcore.EncoderConfig{})
fields := []zap.Field{field, sliceField}
buf, err := enc.EncodeEntry(zapcore.Entry{}, fields)
if err != nil {
t.Fatalf("failed to encode zapfield: %v", err)
}
var encoded map[string]any
if err := json.Unmarshal(buf.Bytes(), &encoded); err != nil {
t.Fatalf("failed to parse encoded fields: %v", err)
}
if encoded["metric_name"] != "cpu_usage" {
t.Errorf("expected metric_name 'cpu_usage', got %v", encoded["metric_name"])
}
tags, ok := encoded["tags"].([]any)
if !ok || len(tags) != 2 || tags[0] != "env:prod" || tags[1] != "region:us-east-1" {
t.Errorf("unexpected tags serialization: %v", encoded["tags"])
}
}
{"case":{"caseId":"case:sha256:f7490fc27877098eaf8b0d9ea4c8e357d782787534a502a450e02ffcd1ce09aa","contract":["zapslog.NewHandler wraps a zapcore.Core to provide a slog.Handler bridging structured log records to Zap encoders.","zapslog.NewHandler respects slog log levels, properly emitting enabled levels and suppressing filtered levels.","zapslog.WithName annotates emitted log entries with the configured logger name.","zapslog.WithCaller attaches caller filename and line number to emitted log entries.","zapslog.AddStacktraceAt records stack traces for log entries at or above the configured log level.","slog.Handler.WithGroup and WithAttrs correctly namespace and nest structured fields within Zap log entries.","zapfield.Str and zapfield.Strs construct type-safe zap.Field instances for custom string types and string slices."],"goal":"verify pkg:golang/go.uber.org/zap/exp@v0.3.0","kind":"HOW","packages":["pkg:golang/go.uber.org/zap/exp@v0.3.0"],"schemaVersion":1,"symbols":["zapslog.NewHandler","zapslog.WithName","zapslog.WithCaller","zapslog.AddStacktraceAt","zapfield.Str","zapfield.Strs"]},"contractCommand":["go","test","-v","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/go.uber.org/zap/exp@v0.3.0"],"schemaVersion":1,"subject":"pkg:golang/go.uber.org/zap/exp@v0.3.0","symbols":["zapslog.NewHandler","zapslog.WithName","zapslog.WithCaller","zapslog.AddStacktraceAt","zapfield.Str","zapfield.Strs"],"verifierAdapter":"golang@1"}
module sample
go 1.22
require (
go.uber.org/zap v1.26.0
go.uber.org/zap/exp v0.3.0
)
require go.uber.org/multierr v1.10.0 // indirect
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
go.uber.org/zap/exp v0.3.0 h1:6JYzdifzYkGmTdRR59oYH+Ng7k49H9qVpWwNSsGJj3U=
go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
{
"schemaVersion": 1,
"goal": "verify pkg:golang/go.uber.org/zap/exp@v0.3.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.uber.org/zap/exp@v0.3.0"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
Origin Seeder
anonymous