CodeSampleX

Sample

go.opentelemetry.io/otel/metric v1.44.0

Verified sample for golang go.opentelemetry.io/otel/metric v1.44.0. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:316babe39478b372f43a3f60d6ec5ff1cb37da80b7be6d2efe710f23c40d0f15

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-19

Case

HOW
Goal
verify pkg:golang/go.opentelemetry.io/otel/metric@v1.44.0
Packages
Created
2026-09-19T05:39:45Z

Contract

  1. MeterProvider creates Meter instances with instrumentation configuration
  2. Meter creates Int64Counter and records measurements
  3. Meter creates Float64ObservableGauge and registers observer callback
  4. Meter creates Float64Histogram and records distributions
  5. NewMeterConfig applies instrumentation version and schema URL options
  6. MetricRecorder integrates instruments and records events

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.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/metric@v1.44.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.opentelemetry.io/otel/metric@v1.44.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:6158696aa1c4a87221aef6af95a2b597e7551047cafbdc825479ef417ce10b97","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.44.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/metric@v1.44.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.44.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/metric@v1.44.0","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require go.opentelemetry.io/otel/metric v1.44.0

require (
	github.com/cespare/xxhash/v2 v2.3.0 // indirect
	go.opentelemetry.io/otel v1.44.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/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/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/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/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.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
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.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sample.go
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.44.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
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/go.opentelemetry.io/otel/metric@v1.44.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.opentelemetry.io/otel/metric@v1.44.0"
  ]
}
test/contract.go
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.44.0"),
		metric.WithSchemaURL("https://example.com/schemas/1.44.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.44.0"),
		metric.WithSchemaURL("https://example.com/schemas/1.44.0"),
	)
	if cfg.InstrumentationVersion() != "1.44.0" {
		fmt.Fprintf(os.Stderr, "expected version 1.44.0, got %q\n", cfg.InstrumentationVersion())
		os.Exit(1)
	}
	if cfg.SchemaURL() != "https://example.com/schemas/1.44.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.44.0 contract assertions passed.")
}

Origin Seeder

anonymous