Ejemplo
go.opentelemetry.io/otel/metric v1.24.0: Int64Counter
Muestra verificada para golang go.opentelemetry.io/otel/metric v1.24.0: Int64Counter. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:6cb39af3efd3dc6ed05c9e6363cb84135fd42f3907a339a5087c892f14dc9e65
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-01 |
Caso
HOW- Objetivo
- verify go.opentelemetry.io/otel/metric.Int64Counter in pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0
- Símbolos
-
- go.opentelemetry.io/otel/metric.Int64Counter
- Entorno
- go 1.26
- Creado
- 2026-09-01T11:22:53Z
Contrato
- Meter creates Int64Counter with description and unit
- Int64Counter records positive measurement increments
- RequestCounter wraps Int64Counter for application telemetry
Archivos
- PROMPT.md
- counter.go
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract_test.go
Código fuente
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 go.opentelemetry.io/otel/metric.Int64Counter in pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0
Demonstrate these symbols/APIs:
- go.opentelemetry.io/otel/metric.Int64Counter
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
import (
"context"
"fmt"
"go.opentelemetry.io/otel/metric"
)
// RequestCounter wraps an OpenTelemetry Int64Counter instrument.
type RequestCounter struct {
counter metric.Int64Counter
}
// NewRequestCounter initializes a new RequestCounter using the provided Meter.
func NewRequestCounter(meter metric.Meter, name string) (*RequestCounter, error) {
if meter == nil {
return nil, fmt.Errorf("meter must not be nil")
}
c, err := meter.Int64Counter(
name,
metric.WithDescription("Counts total number of requests processed"),
metric.WithUnit("{request}"),
)
if err != nil {
return nil, fmt.Errorf("failed to create int64 counter: %w", err)
}
return &RequestCounter{counter: c}, nil
}
// Inc increments the counter by 1.
func (rc *RequestCounter) Inc(ctx context.Context) {
rc.Add(ctx, 1)
}
// Add adds the given delta to the counter with optional metric options.
func (rc *RequestCounter) Add(ctx context.Context, delta int64, opts ...metric.AddOption) {
if rc.counter != nil && delta > 0 {
rc.counter.Add(ctx, delta, opts...)
}
}
// Instrument returns the underlying Int64Counter instrument.
func (rc *RequestCounter) Instrument() metric.Int64Counter {
return rc.counter
}
{"case":{"caseId":"case:sha256:dd2193e73787d0f1b5d9b9b9838ac5b5f025a1552956ee6dec427674d37e6f0a","contract":["Meter creates Int64Counter with description and unit","Int64Counter records positive measurement increments","RequestCounter wraps Int64Counter for application telemetry"],"goal":"verify go.opentelemetry.io/otel/metric.Int64Counter in pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/otel/metric.Int64Counter"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","moduleSystem":"go.mod","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","runtimeVersion":"1.26","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0","symbols":["go.opentelemetry.io/otel/metric.Int64Counter"],"verifierAdapter":"golang@1"}
module example.com/otel-metric-counter-sample
go 1.25.0
require go.opentelemetry.io/otel/metric v1.24.0
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
)
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.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
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.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
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.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
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/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
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/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
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=
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/otel/metric.Int64Counter in pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/otel/metric@v1.24.0"
],
"symbols": [
"go.opentelemetry.io/otel/metric.Int64Counter"
]
}
package test
import (
"context"
"testing"
sample "example.com/otel-metric-counter-sample"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
func TestInt64CounterContract(t *testing.T) {
ctx := context.Background()
provider := noop.NewMeterProvider()
meter := provider.Meter("example.com/contract-test", metric.WithInstrumentationVersion("v1.24.0"))
t.Run("Meter creates Int64Counter with description and unit", func(t *testing.T) {
c, err := meter.Int64Counter(
"http_requests_total",
metric.WithDescription("Total HTTP requests"),
metric.WithUnit("{request}"),
)
if err != nil {
t.Fatalf("unexpected error creating Int64Counter: %v", err)
}
if c == nil {
t.Fatal("expected non-nil Int64Counter")
}
c.Add(ctx, 1)
c.Add(ctx, 42)
})
t.Run("Int64Counter records positive measurement increments", func(t *testing.T) {
c, err := meter.Int64Counter("bytes_transferred_total")
if err != nil {
t.Fatalf("failed to create counter: %v", err)
}
c.Add(ctx, 1024)
c.Add(ctx, 2048)
})
t.Run("RequestCounter wraps Int64Counter for application telemetry", func(t *testing.T) {
rc, err := sample.NewRequestCounter(meter, "app_hits_total")
if err != nil {
t.Fatalf("failed to create RequestCounter: %v", err)
}
if rc == nil || rc.Instrument() == nil {
t.Fatal("expected initialized RequestCounter and instrument")
}
rc.Inc(ctx)
rc.Add(ctx, 5)
_, errNil := sample.NewRequestCounter(nil, "invalid")
if errNil == nil {
t.Fatal("expected error when meter is nil")
}
})
}
Seeder de origen
anónimo