Exemple
go.opentelemetry.io/otel/trace v1.24.0: TraceIDFromHex
Échantillon vérifié pour golang go.opentelemetry.io/otel/trace v1.24.0: TraceIDFromHex. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a…
sha256:c36635bd51bf449e3efbf1935d7e26eb9a67f24ce2caa0d8b8320dae50b18929
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 go
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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-03 |
Cas
HOW- Objectif
- verify TraceIDFromHex in pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0
- Symboles
-
- TraceIDFromHex
- Créé
- 2026-09-03T00:59:06Z
Contrat
- TraceIDFromHex parses a valid 32-character lowercase hex string into a valid TraceID
- TraceIDFromHex round-trips correctly with TraceID.String
- TraceIDFromHex rejects an all-zero hex string with an error
- TraceIDFromHex rejects hex strings not matching length 32
- TraceIDFromHex rejects hex strings with uppercase or non-hex characters
Fichiers
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
- trace_id.go
Code 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 TraceIDFromHex in pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0
Demonstrate these symbols/APIs:
- TraceIDFromHex
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.
{"case":{"caseId":"case:sha256:6b5a0bb32016390cd276c624ef69cb22c55c669b0854a3b35450ff34b6e0c2a0","contract":["TraceIDFromHex parses a valid 32-character lowercase hex string into a valid TraceID","TraceIDFromHex round-trips correctly with TraceID.String","TraceIDFromHex rejects an all-zero hex string with an error","TraceIDFromHex rejects hex strings not matching length 32","TraceIDFromHex rejects hex strings with uppercase or non-hex characters"],"goal":"verify TraceIDFromHex in pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0"],"schemaVersion":1,"symbols":["TraceIDFromHex"]},"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/trace@v1.24.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0","symbols":["TraceIDFromHex"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require go.opentelemetry.io/otel/trace v1.24.0
require go.opentelemetry.io/otel v1.24.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/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
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.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
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 TraceIDFromHex in pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/otel/trace@v1.24.0"
],
"symbols": [
"TraceIDFromHex"
]
}
package main
import (
"fmt"
"os"
"go.opentelemetry.io/otel/trace"
"sample"
)
func main() {
// Assertion 1: TraceIDFromHex parses a valid 32-character lowercase hex string into a valid TraceID
validHex := "4bf92f3577b34da6a3ce929d0e0e4736"
tid, err := trace.TraceIDFromHex(validHex)
if err != nil {
fmt.Fprintf(os.Stderr, "expected nil error for valid hex %s, got: %v\n", validHex, err)
os.Exit(1)
}
if !tid.IsValid() {
fmt.Fprintf(os.Stderr, "expected tid.IsValid() to be true for %s\n", validHex)
os.Exit(1)
}
// Assertion 2: TraceIDFromHex round-trips correctly with TraceID.String
if str := tid.String(); str != validHex {
fmt.Fprintf(os.Stderr, "expected round-trip string %q, got %q\n", validHex, str)
os.Exit(1)
}
// Assertion 3: TraceIDFromHex rejects an all-zero hex string with an error
zeroHex := "00000000000000000000000000000000"
zeroTid, zeroErr := trace.TraceIDFromHex(zeroHex)
if zeroErr == nil {
fmt.Fprintf(os.Stderr, "expected error for all-zero hex string, got nil\n")
os.Exit(1)
}
if zeroTid.IsValid() {
fmt.Fprintf(os.Stderr, "expected all-zero TraceID to be invalid\n")
os.Exit(1)
}
// Assertion 4: TraceIDFromHex rejects hex strings not matching length 32
shortHex := "4bf92f3577b34da6"
if _, err := trace.TraceIDFromHex(shortHex); err == nil {
fmt.Fprintf(os.Stderr, "expected error for short hex string %s, got nil\n", shortHex)
os.Exit(1)
}
longHex := "4bf92f3577b34da6a3ce929d0e0e4736ff"
if _, err := trace.TraceIDFromHex(longHex); err == nil {
fmt.Fprintf(os.Stderr, "expected error for long hex string %s, got nil\n", longHex)
os.Exit(1)
}
// Assertion 5: TraceIDFromHex rejects hex strings with uppercase or non-hex characters
upperHex := "4BF92F3577B34DA6A3CE929D0E0E4736"
if _, err := trace.TraceIDFromHex(upperHex); err == nil {
fmt.Fprintf(os.Stderr, "expected error for uppercase hex string, got nil\n")
os.Exit(1)
}
invalidChars := "4bf92f3577b34da6a3ce929d0e0e473g"
if _, err := trace.TraceIDFromHex(invalidChars); err == nil {
fmt.Fprintf(os.Stderr, "expected error for invalid hex character, got nil\n")
os.Exit(1)
}
// Helper verification using sample package
parsed, err := sample.ParseTraceID(validHex)
if err != nil || parsed != tid {
fmt.Fprintf(os.Stderr, "sample.ParseTraceID mismatch\n")
os.Exit(1)
}
mustParsed := sample.MustTraceID(validHex)
if mustParsed != tid {
fmt.Fprintf(os.Stderr, "sample.MustTraceID mismatch\n")
os.Exit(1)
}
fmt.Println("PASS")
}
package sample
import (
"fmt"
"go.opentelemetry.io/otel/trace"
)
// ParseTraceID parses a 32-character hexadecimal string into an OpenTelemetry TraceID.
// It returns an error if the hex string is invalid, not 32 characters, contains uppercase characters,
// or consists of all zeros.
func ParseTraceID(hexID string) (trace.TraceID, error) {
tid, err := trace.TraceIDFromHex(hexID)
if err != nil {
return trace.TraceID{}, fmt.Errorf("failed to parse trace ID: %w", err)
}
return tid, nil
}
// MustTraceID parses a hex string and panics if parsing fails.
func MustTraceID(hexID string) trace.TraceID {
tid, err := ParseTraceID(hexID)
if err != nil {
panic(err)
}
return tid
}
Seeder d'origine
anonyme