サンプル
go.opentelemetry.io/proto/otlp v1.9.0: v1.AnyValue
検証済みサンプル — golang go.opentelemetry.io/proto/otlp v1.9.0: v1.AnyValue. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.
sha256:fd38d0014751e9334f65aeea754675ab22081fd63bbf623aa22f3dd84fb69e1e
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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/common/v1.AnyValue in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- シンボル
-
- go.opentelemetry.io/proto/otlp/common/v1.AnyValue
- 作成日
- 2026-09-05T10:16:56Z
コントラクト
- AnyValue represents primitive attribute values including string, integer, double, boolean, and raw byte slices via its oneof Value field and typed getters.
- AnyValue supports nested structured collections including ArrayValue and KeyValueList with arbitrary levels of hierarchy.
- AnyValue getters safely handle nil receivers, unpopulated instances, and mismatched variants without panic by returning default zero values.
- AnyValue serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.
- AnyValue serializes to and deserializes from protojson format, preserving field names and nested attribute structures.
- proto.Clone produces an isolated deep copy of AnyValue where mutating nested collections does not affect the original.
ファイル
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/main.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/common/v1.AnyValue 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/common/v1.AnyValue
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:5f3781bc773d92f399cc30199c4e80a64b7a087e7d4b6befd2c5b84cadde6a5d","contract":["AnyValue represents primitive attribute values including string, integer, double, boolean, and raw byte slices via its oneof Value field and typed getters.","AnyValue supports nested structured collections including ArrayValue and KeyValueList with arbitrary levels of hierarchy.","AnyValue getters safely handle nil receivers, unpopulated instances, and mismatched variants without panic by returning default zero values.","AnyValue serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.","AnyValue serializes to and deserializes from protojson format, preserving field names and nested attribute structures.","proto.Clone produces an isolated deep copy of AnyValue where mutating nested collections does not affect the original."],"goal":"verify go.opentelemetry.io/proto/otlp/common/v1.AnyValue 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/common/v1.AnyValue"]},"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/common/v1.AnyValue"],"verifierAdapter":"golang@1"}
module example.com/otlpanyvalue
go 1.26.6
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=
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/proto/otlp/common/v1.AnyValue 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/common/v1.AnyValue"
]
}
package main
import (
"bytes"
"fmt"
"os"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
func assert(condition bool, message string) {
if !condition {
fmt.Fprintf(os.Stderr, "assertion failed: %s\n", message)
os.Exit(1)
}
}
func main() {
// Assertion 1: AnyValue represents primitive attribute values (string, bool, int, double, bytes) through oneof Value field and typed getters
{
strVal := &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "production-cluster"},
}
assert(strVal.GetStringValue() == "production-cluster", "expected StringValue 'production-cluster'")
assert(strVal.GetIntValue() == 0, "expected default 0 IntValue on StringValue")
assert(strVal.GetBoolValue() == false, "expected default false BoolValue on StringValue")
assert(strVal.GetDoubleValue() == 0.0, "expected default 0.0 DoubleValue on StringValue")
assert(strVal.GetBytesValue() == nil, "expected nil BytesValue on StringValue")
intVal := &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{IntValue: 4242},
}
assert(intVal.GetIntValue() == 4242, "expected IntValue 4242")
assert(intVal.GetStringValue() == "", "expected empty string on IntValue")
doubleVal := &commonpb.AnyValue{
Value: &commonpb.AnyValue_DoubleValue{DoubleValue: 99.95},
}
assert(doubleVal.GetDoubleValue() == 99.95, "expected DoubleValue 99.95")
boolVal := &commonpb.AnyValue{
Value: &commonpb.AnyValue_BoolValue{BoolValue: true},
}
assert(boolVal.GetBoolValue() == true, "expected BoolValue true")
rawBytes := []byte{0x01, 0x02, 0x03, 0x04}
bytesVal := &commonpb.AnyValue{
Value: &commonpb.AnyValue_BytesValue{BytesValue: rawBytes},
}
assert(bytes.Equal(bytesVal.GetBytesValue(), rawBytes), "expected matching BytesValue")
}
// Assertion 2: AnyValue supports nested complex collections including ArrayValue and KeyValueList
{
elem1 := &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "web"}}
elem2 := &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "api"}}
arrVal := &commonpb.AnyValue{
Value: &commonpb.AnyValue_ArrayValue{
ArrayValue: &commonpb.ArrayValue{
Values: []*commonpb.AnyValue{elem1, elem2},
},
},
}
assert(len(arrVal.GetArrayValue().GetValues()) == 2, "expected 2 array values")
assert(arrVal.GetArrayValue().GetValues()[0].GetStringValue() == "web", "expected first element 'web'")
assert(arrVal.GetArrayValue().GetValues()[1].GetStringValue() == "api", "expected second element 'api'")
kvVal := &commonpb.AnyValue{
Value: &commonpb.AnyValue_KvlistValue{
KvlistValue: &commonpb.KeyValueList{
Values: []*commonpb.KeyValue{
{
Key: "service.name",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "auth-svc"}},
},
{
Key: "service.tags",
Value: arrVal,
},
},
},
},
}
kvList := kvVal.GetKvlistValue().GetValues()
assert(len(kvList) == 2, "expected 2 key-value pairs")
assert(kvList[0].GetKey() == "service.name", "expected key 'service.name'")
assert(kvList[0].GetValue().GetStringValue() == "auth-svc", "expected value 'auth-svc'")
assert(kvList[1].GetKey() == "service.tags", "expected key 'service.tags'")
assert(len(kvList[1].GetValue().GetArrayValue().GetValues()) == 2, "expected nested array with 2 values")
}
// Assertion 3: AnyValue getters safely handle nil receivers, unpopulated instances, and mismatched variants without panic
{
var nilVal *commonpb.AnyValue
assert(nilVal.GetStringValue() == "", "nil AnyValue GetStringValue must return empty string")
assert(nilVal.GetIntValue() == 0, "nil AnyValue GetIntValue must return 0")
assert(nilVal.GetBoolValue() == false, "nil AnyValue GetBoolValue must return false")
assert(nilVal.GetDoubleValue() == 0.0, "nil AnyValue GetDoubleValue must return 0.0")
assert(nilVal.GetBytesValue() == nil, "nil AnyValue GetBytesValue must return nil")
assert(nilVal.GetArrayValue() == nil, "nil AnyValue GetArrayValue must return nil")
assert(nilVal.GetKvlistValue() == nil, "nil AnyValue GetKvlistValue must return nil")
assert(nilVal.GetValue() == nil, "nil AnyValue GetValue must return nil")
emptyVal := &commonpb.AnyValue{}
assert(emptyVal.GetValue() == nil, "empty AnyValue GetValue must return nil")
assert(emptyVal.GetStringValue() == "", "empty AnyValue GetStringValue must return empty string")
assert(emptyVal.GetArrayValue() == nil, "empty AnyValue GetArrayValue must return nil")
}
// Assertion 4: AnyValue serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal
{
orig := &commonpb.AnyValue{
Value: &commonpb.AnyValue_KvlistValue{
KvlistValue: &commonpb.KeyValueList{
Values: []*commonpb.KeyValue{
{
Key: "env",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "prod"}},
},
{
Key: "retries",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_IntValue{IntValue: 3}},
},
},
},
},
}
wire, err := proto.Marshal(orig)
assert(err == nil, "proto.Marshal failed")
assert(len(wire) > 0, "marshaled wire length is 0")
unmarshaled := &commonpb.AnyValue{}
err = proto.Unmarshal(wire, unmarshaled)
assert(err == nil, "proto.Unmarshal failed")
assert(proto.Equal(orig, unmarshaled), "proto.Equal returned false for protobuf round-trip")
}
// Assertion 5: AnyValue serializes to and deserializes from protojson format, preserving field names and nested structures
{
orig := &commonpb.AnyValue{
Value: &commonpb.AnyValue_KvlistValue{
KvlistValue: &commonpb.KeyValueList{
Values: []*commonpb.KeyValue{
{
Key: "component",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "router"}},
},
{
Key: "port",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_IntValue{IntValue: 8443}},
},
},
},
},
}
jsonBytes, err := protojson.Marshal(orig)
assert(err == nil, "protojson.Marshal failed")
assert(bytes.Contains(jsonBytes, []byte(`"kvlistValue"`)), "json must contain 'kvlistValue'")
assert(bytes.Contains(jsonBytes, []byte(`"stringValue"`)), "json must contain 'stringValue'")
assert(bytes.Contains(jsonBytes, []byte(`"intValue"`)), "json must contain 'intValue'")
jsonUnmarshaled := &commonpb.AnyValue{}
err = protojson.Unmarshal(jsonBytes, jsonUnmarshaled)
assert(err == nil, "protojson.Unmarshal failed")
assert(proto.Equal(orig, jsonUnmarshaled), "proto.Equal returned false for protojson round-trip")
}
// Assertion 6: proto.Clone produces an isolated deep copy of AnyValue where mutating nested collections does not affect the original
{
orig := &commonpb.AnyValue{
Value: &commonpb.AnyValue_ArrayValue{
ArrayValue: &commonpb.ArrayValue{
Values: []*commonpb.AnyValue{
{Value: &commonpb.AnyValue_StringValue{StringValue: "original-tag"}},
},
},
},
}
cloned := proto.Clone(orig).(*commonpb.AnyValue)
assert(proto.Equal(orig, cloned), "cloned AnyValue must equal original")
// Mutate cloned nested values
cloned.GetArrayValue().GetValues()[0].Value = &commonpb.AnyValue_StringValue{StringValue: "mutated-tag"}
cloned.GetArrayValue().Values = append(cloned.GetArrayValue().Values, &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "added-tag"},
})
// Verify original remains untouched
assert(orig.GetArrayValue().GetValues()[0].GetStringValue() == "original-tag", "original AnyValue was mutated")
assert(len(orig.GetArrayValue().GetValues()) == 1, "original AnyValue array length was modified")
}
fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/common/v1.AnyValue contract assertions verified")
}
オリジンシーダー
匿名