Ejemplo
go.opentelemetry.io/otel/metric v1.47.0
Muestra verificada para golang go.opentelemetry.io/otel/metric v1.47.0. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:e140cc9c9629328a7a959504949c496d6a336c7527e9d41aff9bd3f697a50e1d
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
linux 24 · ubuntu · glibc 2.39 x64 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-10-10 |
Caso
HOW- Objetivo
- verify pkg:golang/go.opentelemetry.io/otel/metric@v1.47.0
- Creado
- 2026-10-10T18:38:39Z
Contrato
- MeterProvider creates Meter instances with instrumentation configuration
- Meter creates Int64Counter and records measurements
- Meter creates Float64ObservableGauge and registers observer callback
- Meter creates Float64Histogram and records distributions
- NewMeterConfig applies instrumentation version and schema URL options
- MetricRecorder integrates instruments and records events
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.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 pkg:golang/go.opentelemetry.io/otel/metric@v1.47.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/otel/metric@v1.47.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.
{"case":{"caseId":"case:sha256:97427682b81e5523f7899c8cff4a2fba065ef799823e394f3930953de3304bbc","contract":["MeterProvider creates Meter instances with instrumentation configuration","Meter creates Int64Counter and records measurements","Meter creates Float64ObservableGauge and registers observer callback","Meter creates Float64Histogram and records distributions","NewMeterConfig applies instrumentation version and schema URL options","MetricRecorder integrates instruments and records events"],"goal":"verify pkg:golang/go.opentelemetry.io/otel/metric@v1.47.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/metric@v1.47.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/metric@v1.47.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/metric@v1.47.0","verifierAdapter":"golang@1"}
module sample
go 1.26.6
require go.opentelemetry.io/otel/metric v1.47.0
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
go.opentelemetry.io/otel v1.47.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.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/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.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM=
go.opentelemetry.io/otel v1.47.0/go.mod h1:8wS9O2qfXrYrzp6hIF/HOYJJf/wIhFPhR2xLuP+iXQU=
go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lqCcI=
go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw=
go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY=
go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU=
go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM=
go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0=
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=
package sample
import (
"context"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
// MetricRecorder demonstrates instruments initialized via a MeterProvider.
type MetricRecorder struct {
meterProvider metric.MeterProvider
meter metric.Meter
counter metric.Int64Counter
histogram metric.Float64Histogram
upDownCounter metric.Int64UpDownCounter
}
// NewMetricRecorder creates a MetricRecorder. If mp is nil, it defaults to noop.NewMeterProvider().
func NewMetricRecorder(mp metric.MeterProvider) (*MetricRecorder, error) {
if mp == nil {
mp = noop.NewMeterProvider()
}
meter := mp.Meter("example.com/noop-metrics", metric.WithInstrumentationVersion("v1.47.0"))
counter, err := meter.Int64Counter("sample.counter", metric.WithDescription("sample counter"), metric.WithUnit("{count}"))
if err != nil {
return nil, err
}
histogram, err := meter.Float64Histogram("sample.histogram", metric.WithDescription("sample histogram"), metric.WithUnit("ms"))
if err != nil {
return nil, err
}
upDownCounter, err := meter.Int64UpDownCounter("sample.updown", metric.WithDescription("sample updown"), metric.WithUnit("1"))
if err != nil {
return nil, err
}
return &MetricRecorder{
meterProvider: mp,
meter: meter,
counter: counter,
histogram: histogram,
upDownCounter: upDownCounter,
}, nil
}
// RecordEvents records metrics using the configured instruments.
func (r *MetricRecorder) RecordEvents(ctx context.Context) {
r.counter.Add(ctx, 1)
r.histogram.Record(ctx, 42.0)
r.upDownCounter.Add(ctx, -1)
}
// MeterProvider returns the underlying MeterProvider.
func (r *MetricRecorder) MeterProvider() metric.MeterProvider {
return r.meterProvider
}
// Meter returns the underlying Meter.
func (r *MetricRecorder) Meter() metric.Meter {
return r.meter
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/go.opentelemetry.io/otel/metric@v1.47.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/otel/metric@v1.47.0"
]
}
package main
import (
"context"
"fmt"
"os"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
"sample"
)
func main() {
ctx := context.Background()
// 1. MeterProvider creates Meter instances with instrumentation configuration
mp := noop.NewMeterProvider()
var provider metric.MeterProvider = mp
meter := provider.Meter(
"example.com/contract-meter",
metric.WithInstrumentationVersion("1.47.0"),
metric.WithSchemaURL("https://example.com/schemas/1.47.0"),
)
if meter == nil {
fmt.Fprintf(os.Stderr, "expected non-nil Meter from MeterProvider\n")
os.Exit(1)
}
// 2. Meter creates Int64Counter and records measurements
counter, err := meter.Int64Counter(
"contract_requests_total",
metric.WithDescription("Total test requests"),
metric.WithUnit("{request}"),
)
if err != nil || counter == nil {
fmt.Fprintf(os.Stderr, "Int64Counter failed: err=%v, counter=%v\n", err, counter)
os.Exit(1)
}
counter.Add(ctx, 1)
counter.Add(ctx, 42)
// 3. Meter creates Float64ObservableGauge and registers observer callback
var gaugeObserved float64
gauge, err := meter.Float64ObservableGauge(
"contract_memory_utilization",
metric.WithDescription("Memory utilization ratio"),
metric.WithUnit("1"),
)
if err != nil || gauge == nil {
fmt.Fprintf(os.Stderr, "Float64ObservableGauge failed: err=%v, gauge=%v\n", err, gauge)
os.Exit(1)
}
reg, err := meter.RegisterCallback(
func(ctx context.Context, obs metric.Observer) error {
obs.ObserveFloat64(gauge, 0.75)
gaugeObserved = 0.75
return nil
},
gauge,
)
if err != nil || reg == nil {
fmt.Fprintf(os.Stderr, "RegisterCallback failed: err=%v, reg=%v\n", err, reg)
os.Exit(1)
}
if gaugeObserved != 0.0 {
// callback not executed until collection
}
if err := reg.Unregister(); err != nil {
fmt.Fprintf(os.Stderr, "Unregister failed: %v\n", err)
os.Exit(1)
}
// 4. Meter creates Float64Histogram and records distributions
histogram, err := meter.Float64Histogram(
"contract_request_latency",
metric.WithDescription("Request latency distribution"),
metric.WithUnit("ms"),
)
if err != nil || histogram == nil {
fmt.Fprintf(os.Stderr, "Float64Histogram failed: err=%v, histogram=%v\n", err, histogram)
os.Exit(1)
}
histogram.Record(ctx, 15.5)
histogram.Record(ctx, 88.2)
// 5. NewMeterConfig applies instrumentation version and schema URL options
cfg := metric.NewMeterConfig(
metric.WithInstrumentationVersion("1.47.0"),
metric.WithSchemaURL("https://example.com/schemas/1.47.0"),
)
if cfg.InstrumentationVersion() != "1.47.0" {
fmt.Fprintf(os.Stderr, "expected version 1.47.0, got %q\n", cfg.InstrumentationVersion())
os.Exit(1)
}
if cfg.SchemaURL() != "https://example.com/schemas/1.47.0" {
fmt.Fprintf(os.Stderr, "expected schema URL, got %q\n", cfg.SchemaURL())
os.Exit(1)
}
// 6. MetricRecorder integrates instruments and records events
recorder, err := sample.NewMetricRecorder(mp)
if err != nil || recorder == nil {
fmt.Fprintf(os.Stderr, "NewMetricRecorder failed: %v\n", err)
os.Exit(1)
}
recorder.RecordEvents(ctx)
fmt.Println("All pkg:golang/go.opentelemetry.io/otel/metric@v1.47.0 contract assertions passed.")
}
Seeder de origen
anónimo