Beispiel
go.opentelemetry.io/otel/sdk/metric v1.44.0: Instrument
Verifiziertes Beispiel für golang go.opentelemetry.io/otel/sdk/metric v1.44.0: Instrument. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und…
sha256:da610992350012d65bc82c6b6a6cc171f5767580758a2b470d48d2abd1763cd8
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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 |
Fall
HOW- Ziel
- verify go.opentelemetry.io/otel/sdk/metric.Instrument in pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0
- Symbole
-
- go.opentelemetry.io/otel/sdk/metric.Instrument
- Umgebung
- go 1.26.6
- Erstellt
- 2026-10-10T22:13:38Z
Contract
- Instrument.IsEmpty returns true for a zero-value Instrument and false when any property is populated
- NewView with populated Instrument criteria matches instruments having identical non-zero properties and returns configured stream
- NewView with empty Instrument criteria returns a view matching no instruments
- View receives populated Instrument with correct Name, Kind, Unit, Description, and Scope during Meter instrument registration
Dateien
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Quelltext
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/sdk/metric.Instrument in pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0
Demonstrate these symbols/APIs:
- go.opentelemetry.io/otel/sdk/metric.Instrument
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:bf2f319e4330910b2bfca11df14b7de5c0a0a77f0f9cc1c5717b2a9f92733776","contract":["Instrument.IsEmpty returns true for a zero-value Instrument and false when any property is populated","NewView with populated Instrument criteria matches instruments having identical non-zero properties and returns configured stream","NewView with empty Instrument criteria returns a view matching no instruments","View receives populated Instrument with correct Name, Kind, Unit, Description, and Scope during Meter instrument registration"],"goal":"verify go.opentelemetry.io/otel/sdk/metric.Instrument in pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/otel/sdk/metric.Instrument"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0","symbols":["go.opentelemetry.io/otel/sdk/metric.Instrument"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require (
go.opentelemetry.io/otel/metric v1.44.0
go.opentelemetry.io/otel/sdk/metric v1.44.0
)
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/go-logr/logr v1.4.3 // 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 v1.44.0 // indirect
go.opentelemetry.io/otel/sdk v1.44.0 // indirect
go.opentelemetry.io/otel/trace v1.44.0 // indirect
golang.org/x/sys v0.45.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/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.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
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/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/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/metric/x v0.66.0 h1:YkCrx1zLOChi9ZcZ6euupOcsgzbVlec7D/xoEU1+cTA=
go.opentelemetry.io/otel/metric/x v0.66.0/go.mod h1:d1+BDj9t96do0/1LoU1ayfCv79ZgNE41qbhBvnMOBZk=
go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
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=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package main
import (
"context"
"fmt"
"go.opentelemetry.io/otel/metric"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)
func main() {
ctx := context.Background()
// 1. Inspect a zero-value Instrument
var zeroInst sdkmetric.Instrument
fmt.Printf("zero-value Instrument IsEmpty: %t\n", zeroInst.IsEmpty())
// 2. Define criteria using sdkmetric.Instrument
criteria := sdkmetric.Instrument{
Name: "requests_total",
Kind: sdkmetric.InstrumentKindCounter,
}
// 3. Define a Stream mask to rename the metric stream
mask := sdkmetric.Stream{
Name: "http_server_requests_total",
Description: "Renamed total HTTP requests stream",
}
// 4. Create a View matching the criteria
view := sdkmetric.NewView(criteria, mask)
// 5. Configure MeterProvider with the View
reader := sdkmetric.NewManualReader()
provider := sdkmetric.NewMeterProvider(
sdkmetric.WithReader(reader),
sdkmetric.WithView(view),
)
defer func() {
_ = provider.Shutdown(ctx)
}()
meter := provider.Meter("sample-telemetry")
counter, err := meter.Int64Counter(
"requests_total",
metric.WithDescription("Original requests counter"),
metric.WithUnit("requests"),
)
if err != nil {
panic(err)
}
counter.Add(ctx, 1)
var rm metricdata.ResourceMetrics
if err := reader.Collect(ctx, &rm); err != nil {
panic(err)
}
for _, sm := range rm.ScopeMetrics {
for _, m := range sm.Metrics {
fmt.Printf("Collected metric stream: %s (%s)\n", m.Name, m.Description)
}
}
}
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/otel/sdk/metric.Instrument in pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/otel/sdk/metric@v1.44.0"
],
"symbols": [
"go.opentelemetry.io/otel/sdk/metric.Instrument"
]
}
package main
import (
"context"
"fmt"
"os"
"go.opentelemetry.io/otel/metric"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
)
func main() {
if err := runContract(); err != nil {
fmt.Fprintf(os.Stderr, "Contract verification failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All go.opentelemetry.io/otel/sdk/metric.Instrument contract assertions passed.")
}
func runContract() error {
// Assertion 1: Instrument.IsEmpty returns true for a zero-value Instrument and false when any property is populated
var zeroInst sdkmetric.Instrument
if !zeroInst.IsEmpty() {
return fmt.Errorf("assertion 1 failed: expected zero-value Instrument.IsEmpty() to be true, got false")
}
populatedInst := sdkmetric.Instrument{
Name: "active_tasks",
}
if populatedInst.IsEmpty() {
return fmt.Errorf("assertion 1 failed: expected populated Instrument.IsEmpty() to be false, got true")
}
// Assertion 2: NewView with populated Instrument criteria matches instruments having identical non-zero properties and returns configured stream
criteria := sdkmetric.Instrument{
Name: "requests_total",
Kind: sdkmetric.InstrumentKindCounter,
}
mask := sdkmetric.Stream{
Name: "custom_requests_total",
Description: "Custom description for total requests",
}
view := sdkmetric.NewView(criteria, mask)
matchingCandidate := sdkmetric.Instrument{
Name: "requests_total",
Kind: sdkmetric.InstrumentKindCounter,
Unit: "requests",
}
stream, matched := view(matchingCandidate)
if !matched {
return fmt.Errorf("assertion 2 failed: expected view to match instrument with matching name and kind")
}
if stream.Name != "custom_requests_total" {
return fmt.Errorf("assertion 2 failed: expected stream name %q, got %q", "custom_requests_total", stream.Name)
}
if stream.Description != "Custom description for total requests" {
return fmt.Errorf("assertion 2 failed: expected stream description %q, got %q", "Custom description for total requests", stream.Description)
}
nonMatchingCandidate := sdkmetric.Instrument{
Name: "requests_latency",
Kind: sdkmetric.InstrumentKindHistogram,
}
_, matchedNon := view(nonMatchingCandidate)
if matchedNon {
return fmt.Errorf("assertion 2 failed: expected view not to match instrument with different name and kind")
}
// Assertion 3: NewView with empty Instrument criteria returns a view matching no instruments
var emptyCriteria sdkmetric.Instrument
emptyView := sdkmetric.NewView(emptyCriteria, sdkmetric.Stream{Name: "dropped_stream"})
_, matchedEmpty := emptyView(matchingCandidate)
if matchedEmpty {
return fmt.Errorf("assertion 3 failed: expected empty criteria view not to match any instrument")
}
// Assertion 4: View receives populated Instrument with correct Name, Kind, Unit, Description, and Scope during Meter instrument registration
var capturedInst sdkmetric.Instrument
captureView := func(i sdkmetric.Instrument) (sdkmetric.Stream, bool) {
if i.Name == "payload_bytes" {
capturedInst = i
}
return sdkmetric.Stream{}, false
}
reader := sdkmetric.NewManualReader()
provider := sdkmetric.NewMeterProvider(
sdkmetric.WithReader(reader),
sdkmetric.WithView(captureView),
)
defer func() {
_ = provider.Shutdown(context.Background())
}()
meter := provider.Meter(
"contract-meter",
metric.WithInstrumentationVersion("v1.2.3"),
)
_, err := meter.Int64UpDownCounter(
"payload_bytes",
metric.WithDescription("Size of in-flight payload in bytes"),
metric.WithUnit("By"),
)
if err != nil {
return fmt.Errorf("assertion 4 failed: meter.Int64UpDownCounter error: %w", err)
}
if capturedInst.IsEmpty() {
return fmt.Errorf("assertion 4 failed: expected captured Instrument to be populated")
}
if capturedInst.Name != "payload_bytes" {
return fmt.Errorf("assertion 4 failed: expected Instrument Name %q, got %q", "payload_bytes", capturedInst.Name)
}
if capturedInst.Kind != sdkmetric.InstrumentKindUpDownCounter {
return fmt.Errorf("assertion 4 failed: expected Instrument Kind %v, got %v", sdkmetric.InstrumentKindUpDownCounter, capturedInst.Kind)
}
if capturedInst.Unit != "By" {
return fmt.Errorf("assertion 4 failed: expected Instrument Unit %q, got %q", "By", capturedInst.Unit)
}
if capturedInst.Description != "Size of in-flight payload in bytes" {
return fmt.Errorf("assertion 4 failed: expected Instrument Description %q, got %q", "Size of in-flight payload in bytes", capturedInst.Description)
}
if capturedInst.Scope.Name != "contract-meter" || capturedInst.Scope.Version != "v1.2.3" {
return fmt.Errorf("assertion 4 failed: expected Scope name 'contract-meter' and version 'v1.2.3', got %v", capturedInst.Scope)
}
return nil
}
Ursprungs-Seeder
anonym