샘플
go.opentelemetry.io/proto/otlp v1.9.0: v1.Gauge
검증된 샘플 — golang go.opentelemetry.io/proto/otlp v1.9.0: v1.Gauge. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Gauge GetDataPoints returns…
sha256:7d417186ae5650d5debb77321139784268c6fa5602b14870c7dbb3b9113f4af3
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-05 |
케이스
HOW- 목표
- verify go.opentelemetry.io/proto/otlp/metrics/v1.Gauge in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- 심벌
-
- go.opentelemetry.io/proto/otlp/metrics/v1.Gauge
- 생성일
- 2026-09-05T19:23:54Z
컨트랙트
- Gauge GetDataPoints returns empty slice when initialized without data points
- Gauge holds NumberDataPoints recording floating point measurements with timestamps
- Gauge holds NumberDataPoints recording integer measurements with key-value attributes
- Metric GetData returns Metric_Gauge wrapper and GetGauge provides underlying Gauge
- Metric GetGauge returns nil when metric contains non-gauge data
- Gauge Reset clears all recorded data points
- Gauge marshals and unmarshals with protobuf binary wire format preserving data points
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
소스
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/proto/otlp/metrics/v1.Gauge in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
Demonstrate these symbols/APIs:
- go.opentelemetry.io/proto/otlp/metrics/v1.Gauge
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:36a925b22ffb2588dd3bcd714dec361d4bb787f60c64d267f45c22879aee26f7","contract":["Gauge GetDataPoints returns empty slice when initialized without data points","Gauge holds NumberDataPoints recording floating point measurements with timestamps","Gauge holds NumberDataPoints recording integer measurements with key-value attributes","Metric GetData returns Metric_Gauge wrapper and GetGauge provides underlying Gauge","Metric GetGauge returns nil when metric contains non-gauge data","Gauge Reset clears all recorded data points","Gauge marshals and unmarshals with protobuf binary wire format preserving data points"],"goal":"verify go.opentelemetry.io/proto/otlp/metrics/v1.Gauge in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/proto/otlp/metrics/v1.Gauge"]},"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/proto/otlp@v1.9.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0","symbols":["go.opentelemetry.io/proto/otlp/metrics/v1.Gauge"],"verifierAdapter":"golang@1"}
module sample
go 1.23.0
require (
go.opentelemetry.io/proto/otlp v1.9.0
google.golang.org/protobuf v1.36.10
)
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
package main
import (
"fmt"
"time"
v1 "go.opentelemetry.io/proto/otlp/common/v1"
metricspb "go.opentelemetry.io/proto/otlp/metrics/v1"
)
func main() {
// Create a NumberDataPoint representing a gauge observation
point := &metricspb.NumberDataPoint{
TimeUnixNano: uint64(time.Now().UnixNano()),
Value: &metricspb.NumberDataPoint_AsDouble{
AsDouble: 42.5,
},
Attributes: []*v1.KeyValue{
{
Key: "device_id",
Value: &v1.AnyValue{
Value: &v1.AnyValue_StringValue{StringValue: "sensor-01"},
},
},
},
}
// Construct Gauge with data points
gauge := &metricspb.Gauge{
DataPoints: []*metricspb.NumberDataPoint{point},
}
// Wrap Gauge in Metric
metric := &metricspb.Metric{
Name: "temperature_celsius",
Description: "Current temperature reading in Celsius",
Unit: "Cel",
Data: &metricspb.Metric_Gauge{
Gauge: gauge,
},
}
fmt.Printf("Metric: %s, DataPoints count: %d\n", metric.GetName(), len(metric.GetGauge().GetDataPoints()))
}
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/proto/otlp/metrics/v1.Gauge in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0"
],
"symbols": [
"go.opentelemetry.io/proto/otlp/metrics/v1.Gauge"
]
}
package main
import (
"fmt"
"os"
v1 "go.opentelemetry.io/proto/otlp/common/v1"
metricspb "go.opentelemetry.io/proto/otlp/metrics/v1"
"google.golang.org/protobuf/proto"
)
func main() {
// 1. Gauge GetDataPoints returns empty slice when initialized without data points
emptyGauge := &metricspb.Gauge{}
if pts := emptyGauge.GetDataPoints(); len(pts) != 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected 0 points, got %d\n", len(pts))
os.Exit(1)
}
// 2. Gauge holds NumberDataPoints recording floating point measurements with timestamps
dpDouble := &metricspb.NumberDataPoint{
TimeUnixNano: 1725540000000000000,
Value: &metricspb.NumberDataPoint_AsDouble{
AsDouble: 73.5,
},
}
gaugeWithDouble := &metricspb.Gauge{
DataPoints: []*metricspb.NumberDataPoint{dpDouble},
}
if len(gaugeWithDouble.GetDataPoints()) != 1 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 1 point\n")
os.Exit(1)
}
if gaugeWithDouble.GetDataPoints()[0].GetAsDouble() != 73.5 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 73.5, got %f\n", gaugeWithDouble.GetDataPoints()[0].GetAsDouble())
os.Exit(1)
}
if gaugeWithDouble.GetDataPoints()[0].GetTimeUnixNano() != 1725540000000000000 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: timestamp mismatch\n")
os.Exit(1)
}
// 3. Gauge holds NumberDataPoints recording integer measurements with key-value attributes
dpInt := &metricspb.NumberDataPoint{
TimeUnixNano: 1725540001000000000,
Value: &metricspb.NumberDataPoint_AsInt{
AsInt: 42,
},
Attributes: []*v1.KeyValue{
{
Key: "host",
Value: &v1.AnyValue{
Value: &v1.AnyValue_StringValue{StringValue: "server-01"},
},
},
},
}
gaugeWithInt := &metricspb.Gauge{
DataPoints: []*metricspb.NumberDataPoint{dpInt},
}
if gaugeWithInt.GetDataPoints()[0].GetAsInt() != 42 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected int 42, got %d\n", gaugeWithInt.GetDataPoints()[0].GetAsInt())
os.Exit(1)
}
if len(gaugeWithInt.GetDataPoints()[0].GetAttributes()) != 1 || gaugeWithInt.GetDataPoints()[0].GetAttributes()[0].GetKey() != "host" {
fmt.Fprintf(os.Stderr, "assertion 3 failed: attribute mismatch\n")
os.Exit(1)
}
// 4. Metric GetData returns Metric_Gauge wrapper and GetGauge provides underlying Gauge
metric := &metricspb.Metric{
Name: "memory_usage_bytes",
Description: "Current memory usage in bytes",
Unit: "By",
Data: &metricspb.Metric_Gauge{
Gauge: gaugeWithDouble,
},
}
if metric.GetGauge() == nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: Metric.GetGauge returned nil\n")
os.Exit(1)
}
if metric.GetGauge().GetDataPoints()[0].GetAsDouble() != 73.5 {
fmt.Fprintf(os.Stderr, "assertion 4 failed: metric gauge data point mismatch\n")
os.Exit(1)
}
if _, ok := metric.GetData().(*metricspb.Metric_Gauge); !ok {
fmt.Fprintf(os.Stderr, "assertion 4 failed: Metric.GetData is not *Metric_Gauge\n")
os.Exit(1)
}
// 5. Metric GetGauge returns nil when metric contains non-gauge data
sumMetric := &metricspb.Metric{
Name: "requests_total",
Data: &metricspb.Metric_Sum{
Sum: &metricspb.Sum{},
},
}
if sumMetric.GetGauge() != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: Metric.GetGauge should return nil for Sum data\n")
os.Exit(1)
}
// 6. Gauge Reset clears all recorded data points
gaugeToReset := &metricspb.Gauge{
DataPoints: []*metricspb.NumberDataPoint{dpDouble, dpInt},
}
gaugeToReset.Reset()
if len(gaugeToReset.GetDataPoints()) != 0 {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Reset did not clear data points\n")
os.Exit(1)
}
// 7. Gauge marshals and unmarshals with protobuf binary wire format preserving data points
origGauge := &metricspb.Gauge{
DataPoints: []*metricspb.NumberDataPoint{dpDouble, dpInt},
}
data, err := proto.Marshal(origGauge)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 7 failed: proto.Marshal error: %v\n", err)
os.Exit(1)
}
deserializedGauge := &metricspb.Gauge{}
if err := proto.Unmarshal(data, deserializedGauge); err != nil {
fmt.Fprintf(os.Stderr, "assertion 7 failed: proto.Unmarshal error: %v\n", err)
os.Exit(1)
}
if len(deserializedGauge.GetDataPoints()) != 2 {
fmt.Fprintf(os.Stderr, "assertion 7 failed: expected 2 points, got %d\n", len(deserializedGauge.GetDataPoints()))
os.Exit(1)
}
if deserializedGauge.GetDataPoints()[0].GetAsDouble() != 73.5 {
fmt.Fprintf(os.Stderr, "assertion 7 failed: double value mismatch after roundtrip\n")
os.Exit(1)
}
if deserializedGauge.GetDataPoints()[1].GetAsInt() != 42 {
fmt.Fprintf(os.Stderr, "assertion 7 failed: int value mismatch after roundtrip\n")
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
오리진 시더
익명