CodeSampleX

Sample

go.opentelemetry.io/otel/sdk/log/logtest v0.22.0

Verified sample for golang go.opentelemetry.io/otel/sdk/log/logtest v0.22.0. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:cde519ce128a54d489d0f0b374e89d27327befc89272c9017b818ef6e0ab8c95

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 linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-16

Case

HOW
Goal
verify pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0
Packages
Created
2026-09-16T20:31:15Z

Contract

  1. RecordFactory empty instance produces a zero-value Record with empty event name and zero timestamps.
  2. RecordFactory configures EventName, Timestamp, ObservedTimestamp, Severity, SeverityText, and Body correctly.
  3. RecordFactory configures Attributes and enables attribute retrieval via WalkAttributes.
  4. RecordFactory configures TraceID, SpanID, TraceFlags, Resource, and InstrumentationScope on the resulting Record.
  5. RecordFactory configures DroppedAttributes count on the resulting Record.
  6. Modifying RecordFactory produces distinct independent Record instances without affecting previously generated records.

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
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.opentelemetry.io/otel/sdk/log/logtest@v0.22.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0

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.
csx.json
{"case":{"caseId":"case:sha256:984bfce7726d4cbe248579329f4ac18197f78508ae1111df3610509a1bb4168a","contract":["RecordFactory empty instance produces a zero-value Record with empty event name and zero timestamps.","RecordFactory configures EventName, Timestamp, ObservedTimestamp, Severity, SeverityText, and Body correctly.","RecordFactory configures Attributes and enables attribute retrieval via WalkAttributes.","RecordFactory configures TraceID, SpanID, TraceFlags, Resource, and InstrumentationScope on the resulting Record.","RecordFactory configures DroppedAttributes count on the resulting Record.","Modifying RecordFactory produces distinct independent Record instances without affecting previously generated records."],"goal":"verify pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	go.opentelemetry.io/otel v1.46.0
	go.opentelemetry.io/otel/log v0.22.0
	go.opentelemetry.io/otel/sdk v1.46.0
	go.opentelemetry.io/otel/sdk/log/logtest v0.22.0
	go.opentelemetry.io/otel/trace v1.46.0
)

require (
	github.com/cespare/xxhash/v2 v2.3.0 // indirect
	github.com/go-logr/logr v1.4.4 // indirect
	github.com/go-logr/stdr v1.2.2 // indirect
	github.com/google/uuid v1.6.0 // indirect
	go.opentelemetry.io/auto/sdk v1.2.1 // indirect
	go.opentelemetry.io/otel/metric v1.46.0 // indirect
	go.opentelemetry.io/otel/sdk/log v0.22.0 // indirect
	golang.org/x/sys v0.47.0 // indirect
)
go.sum
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.46.0 h1:FHt5/CDyVxi/8IM1CH7VE/rRgq3kLHa2mSTVMO8AWyc=
go.opentelemetry.io/otel v1.46.0/go.mod h1:Gj3SEScelsNC45tp4nSxRYlS+f5iez7W8XPMCt905kE=
go.opentelemetry.io/otel/log v0.22.0 h1:5DBNnfvaJ6CVdkJ+Jle8Tzs50aSSv49TXGj9XRsEYw0=
go.opentelemetry.io/otel/log v0.22.0/go.mod h1:gzOt/R67vF2GniAqWu8Qv0SXy89f71muHcrkz76PCdc=
go.opentelemetry.io/otel/metric v1.46.0 h1:yBnkXvgV7AXFILZc5K6IZe/CBFF3OS7BJ8ov6/lj0K8=
go.opentelemetry.io/otel/metric v1.46.0/go.mod h1:iPmdWqifKUdzziPkvvzIJXITl56fQx2mGM/DHLB3/2o=
go.opentelemetry.io/otel/sdk v1.46.0 h1:h5CNQQjEbuQXY/JfZtgt3i7HVFV3aHPO2OAwO2eTYPI=
go.opentelemetry.io/otel/sdk v1.46.0/go.mod h1:GAERFXFt5SYCEB+YiKUbMBeza6UaDH7GmGOZEfh2gSM=
go.opentelemetry.io/otel/sdk/log v0.22.0 h1:PRL+s6P63XT4E/bheEflopPUpVxuvANqZwtt89yhoGk=
go.opentelemetry.io/otel/sdk/log v0.22.0/go.mod h1:JNp0sBELrjCTcu5W3GzABVypeU6vDJjBS+X0JISuz+g=
go.opentelemetry.io/otel/sdk/log/logtest v0.22.0 h1:infPnfNrhCNgOUZRs3gWUg8vhoBUHihq02gwK05gzlg=
go.opentelemetry.io/otel/sdk/log/logtest v0.22.0/go.mod h1:gkQZA3z15Bv3KU9vigBTi8dFechSozRP7v94X4VZv+s=
go.opentelemetry.io/otel/sdk/metric v1.46.0 h1:0piZ26EG4RBfebb2jhDH6ERCYHoVWduc3kLgPCwSnSE=
go.opentelemetry.io/otel/sdk/metric v1.46.0/go.mod h1:I1PbKrdVc8Qu8HYVDNtqVIwLwjNrhsV/uFuxfwg8mO4=
go.opentelemetry.io/otel/trace v1.46.0 h1:OULy7ccdJnZtJ0UDYFOIGaCmiWzJ8Vi2G/Rsu60qs1c=
go.opentelemetry.io/otel/trace v1.46.0/go.mod h1:J7GAXweO77XSFkB/rmAqk9D6ihszhFjLU+d9WuUxDLI=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
main.go
package main

import (
	"fmt"
	"time"

	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/log"
	"go.opentelemetry.io/otel/sdk/instrumentation"
	"go.opentelemetry.io/otel/sdk/log/logtest"
)

func main() {
	now := time.Now()
	rf := logtest.RecordFactory{
		EventName:    "user.login",
		Timestamp:    now,
		Severity:     log.SeverityInfo,
		SeverityText: "INFO",
		Body:         attribute.StringValue("User logged in successfully"),
		Attributes: []attribute.KeyValue{
			attribute.String("user.id", "u-12345"),
			attribute.Int("attempt", 1),
		},
		InstrumentationScope: &instrumentation.Scope{
			Name:    "auth-service",
			Version: "1.0.0",
		},
	}

	record := rf.NewRecord()
	fmt.Printf("Created record: Event=%s, Severity=%s, Body=%s, Scope=%s\n",
		record.EventName(),
		record.SeverityText(),
		record.Body().AsString(),
		record.InstrumentationScope().Name,
	)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.opentelemetry.io/otel/sdk/log/logtest@v0.22.0"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"slices"
	"time"

	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/log"
	"go.opentelemetry.io/otel/sdk/instrumentation"
	"go.opentelemetry.io/otel/sdk/log/logtest"
	"go.opentelemetry.io/otel/sdk/resource"
	"go.opentelemetry.io/otel/trace"
)

func main() {
	// Assertion 1: RecordFactory empty instance produces a zero-value Record with empty event name and zero timestamps.
	emptyRecord := logtest.RecordFactory{}.NewRecord()
	if emptyRecord.EventName() != "" {
		fmt.Fprintf(os.Stderr, "FAIL: expected empty EventName, got %q\n", emptyRecord.EventName())
		os.Exit(1)
	}
	if !emptyRecord.Timestamp().IsZero() {
		fmt.Fprintf(os.Stderr, "FAIL: expected zero Timestamp\n")
		os.Exit(1)
	}
	if !emptyRecord.ObservedTimestamp().IsZero() {
		fmt.Fprintf(os.Stderr, "FAIL: expected zero ObservedTimestamp\n")
		os.Exit(1)
	}
	if emptyRecord.Severity() != log.SeverityUndefined {
		fmt.Fprintf(os.Stderr, "FAIL: expected SeverityUndefined, got %v\n", emptyRecord.Severity())
		os.Exit(1)
	}

	// Assertion 2: RecordFactory configures EventName, Timestamp, ObservedTimestamp, Severity, SeverityText, and Body correctly.
	now := time.Now()
	observed := now.Add(2 * time.Second)
	body := attribute.StringValue("operational message")
	rf := logtest.RecordFactory{
		EventName:         "service.event",
		Timestamp:         now,
		ObservedTimestamp: observed,
		Severity:          log.SeverityInfo,
		SeverityText:      "INFO",
		Body:              body,
	}
	rec := rf.NewRecord()
	if rec.EventName() != "service.event" {
		fmt.Fprintf(os.Stderr, "FAIL: expected EventName 'service.event', got %q\n", rec.EventName())
		os.Exit(1)
	}
	if !rec.Timestamp().Equal(now) {
		fmt.Fprintf(os.Stderr, "FAIL: expected Timestamp %v, got %v\n", now, rec.Timestamp())
		os.Exit(1)
	}
	if !rec.ObservedTimestamp().Equal(observed) {
		fmt.Fprintf(os.Stderr, "FAIL: expected ObservedTimestamp %v, got %v\n", observed, rec.ObservedTimestamp())
		os.Exit(1)
	}
	if rec.Severity() != log.SeverityInfo {
		fmt.Fprintf(os.Stderr, "FAIL: expected SeverityInfo, got %v\n", rec.Severity())
		os.Exit(1)
	}
	if rec.SeverityText() != "INFO" {
		fmt.Fprintf(os.Stderr, "FAIL: expected SeverityText 'INFO', got %q\n", rec.SeverityText())
		os.Exit(1)
	}
	if rec.Body().AsString() != body.AsString() {
		fmt.Fprintf(os.Stderr, "FAIL: expected Body %v, got %v\n", body.AsString(), rec.Body().AsString())
		os.Exit(1)
	}

	// Assertion 3: RecordFactory configures Attributes and enables attribute retrieval via WalkAttributes.
	attrs := []attribute.KeyValue{
		attribute.String("key1", "val1"),
		attribute.Int("key2", 42),
		attribute.Bool("key3", true),
	}
	rfAttrs := logtest.RecordFactory{
		Attributes: attrs,
	}
	recAttrs := rfAttrs.NewRecord()
	if recAttrs.AttributesLen() != 3 {
		fmt.Fprintf(os.Stderr, "FAIL: expected 3 attributes, got %d\n", recAttrs.AttributesLen())
		os.Exit(1)
	}
	var walked []attribute.KeyValue
	recAttrs.WalkAttributes(func(kv attribute.KeyValue) bool {
		walked = append(walked, kv)
		return true
	})
	if !slices.EqualFunc(attrs, walked, func(a, b attribute.KeyValue) bool {
		return a.Key == b.Key && a.Value.Emit() == b.Value.Emit()
	}) {
		fmt.Fprintf(os.Stderr, "FAIL: walked attributes do not match expected attributes\n")
		os.Exit(1)
	}

	// Assertion 4: RecordFactory configures TraceID, SpanID, TraceFlags, Resource, and InstrumentationScope on the resulting Record.
	traceID := trace.TraceID([16]byte{1, 2, 3, 4})
	spanID := trace.SpanID([8]byte{5, 6, 7, 8})
	traceFlags := trace.FlagsSampled
	res := resource.NewSchemaless(attribute.String("env", "test"))
	scope := instrumentation.Scope{
		Name:    "test-scope",
		Version: "1.0.0",
	}
	rfContext := logtest.RecordFactory{
		TraceID:              traceID,
		SpanID:               spanID,
		TraceFlags:           traceFlags,
		Resource:             res,
		InstrumentationScope: &scope,
	}
	recContext := rfContext.NewRecord()
	if recContext.TraceID() != traceID {
		fmt.Fprintf(os.Stderr, "FAIL: expected TraceID %v, got %v\n", traceID, recContext.TraceID())
		os.Exit(1)
	}
	if recContext.SpanID() != spanID {
		fmt.Fprintf(os.Stderr, "FAIL: expected SpanID %v, got %v\n", spanID, recContext.SpanID())
		os.Exit(1)
	}
	if recContext.TraceFlags() != traceFlags {
		fmt.Fprintf(os.Stderr, "FAIL: expected TraceFlags %v, got %v\n", traceFlags, recContext.TraceFlags())
		os.Exit(1)
	}
	if recContext.Resource() != res {
		fmt.Fprintf(os.Stderr, "FAIL: expected Resource %v, got %v\n", res, recContext.Resource())
		os.Exit(1)
	}
	if recContext.InstrumentationScope() != scope {
		fmt.Fprintf(os.Stderr, "FAIL: expected InstrumentationScope %v, got %v\n", scope, recContext.InstrumentationScope())
		os.Exit(1)
	}

	// Assertion 5: RecordFactory configures DroppedAttributes count on the resulting Record.
	rfDropped := logtest.RecordFactory{
		DroppedAttributes: 5,
	}
	recDropped := rfDropped.NewRecord()
	if recDropped.DroppedAttributes() != 5 {
		fmt.Fprintf(os.Stderr, "FAIL: expected 5 DroppedAttributes, got %d\n", recDropped.DroppedAttributes())
		os.Exit(1)
	}

	// Assertion 6: Modifying RecordFactory produces distinct independent Record instances without affecting previously generated records.
	builder := logtest.RecordFactory{
		EventName: "first",
		Timestamp: now,
	}
	rec1 := builder.NewRecord()

	builder.EventName = "second"
	builder.Timestamp = observed
	rec2 := builder.NewRecord()

	if rec1.EventName() != "first" || !rec1.Timestamp().Equal(now) {
		fmt.Fprintf(os.Stderr, "FAIL: rec1 was mutated by subsequent builder changes\n")
		os.Exit(1)
	}
	if rec2.EventName() != "second" || !rec2.Timestamp().Equal(observed) {
		fmt.Fprintf(os.Stderr, "FAIL: rec2 did not reflect updated builder values\n")
		os.Exit(1)
	}

	fmt.Println("PASS: all RecordFactory contract assertions passed.")
}

Origin Seeder

anonymous