샘플
go.opentelemetry.io/proto/otlp v1.9.0: v1.KeyValue
검증된 샘플 — golang go.opentelemetry.io/proto/otlp v1.9.0: v1.KeyValue. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:725bd769057624e86c9e0ba888fe939e229c31cd705b2b766805aa3465fd52c1
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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.KeyValue in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- 심벌
-
- go.opentelemetry.io/proto/otlp/common/v1.KeyValue
- 생성일
- 2026-09-05T12:21:50Z
컨트랙트
- KeyValue associates a string key with an AnyValue representing primitive values including string, integer, boolean, double, and bytes.
- KeyValue supports complex and nested attribute values including ArrayValue and KeyValueList.
- KeyValue getters safely handle nil receivers and unpopulated instances without panic, returning zero values.
- KeyValue serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.
- KeyValue serializes to and deserializes from protojson format, preserving field names key and value and nested structures.
- proto.Clone produces an isolated deep copy of KeyValue where mutating key or the cloned nested AnyValue 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.KeyValue 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.KeyValue
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:3590a2a66e1381c26c933cd6b549e486ff17c7a96b663392a91bcf471c107644","contract":["KeyValue associates a string key with an AnyValue representing primitive values including string, integer, boolean, double, and bytes.","KeyValue supports complex and nested attribute values including ArrayValue and KeyValueList.","KeyValue getters safely handle nil receivers and unpopulated instances without panic, returning zero values.","KeyValue serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.","KeyValue serializes to and deserializes from protojson format, preserving field names key and value and nested structures.","proto.Clone produces an isolated deep copy of KeyValue where mutating key or the cloned nested AnyValue does not affect the original."],"goal":"verify go.opentelemetry.io/proto/otlp/common/v1.KeyValue 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.KeyValue"]},"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.KeyValue"],"verifierAdapter":"golang@1"}
module example.com/otlpkeyvalue
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.KeyValue 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.KeyValue"
]
}
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: KeyValue associates a string key with an AnyValue representing primitive values including string, integer, boolean, double, and bytes
{
strKV := &commonpb.KeyValue{
Key: "http.method",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "GET"},
},
}
assert(strKV.GetKey() == "http.method", "expected Key 'http.method'")
assert(strKV.GetValue().GetStringValue() == "GET", "expected Value 'GET'")
intKV := &commonpb.KeyValue{
Key: "http.status_code",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{IntValue: 200},
},
}
assert(intKV.GetKey() == "http.status_code", "expected Key 'http.status_code'")
assert(intKV.GetValue().GetIntValue() == 200, "expected Value 200")
doubleKV := &commonpb.KeyValue{
Key: "http.duration_ms",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_DoubleValue{DoubleValue: 12.5},
},
}
assert(doubleKV.GetKey() == "http.duration_ms", "expected Key 'http.duration_ms'")
assert(doubleKV.GetValue().GetDoubleValue() == 12.5, "expected Value 12.5")
boolKV := &commonpb.KeyValue{
Key: "http.is_tls",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_BoolValue{BoolValue: true},
},
}
assert(boolKV.GetKey() == "http.is_tls", "expected Key 'http.is_tls'")
assert(boolKV.GetValue().GetBoolValue() == true, "expected Value true")
rawBytes := []byte{0xde, 0xad, 0xbe, 0xef}
bytesKV := &commonpb.KeyValue{
Key: "payload.digest",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_BytesValue{BytesValue: rawBytes},
},
}
assert(bytesKV.GetKey() == "payload.digest", "expected Key 'payload.digest'")
assert(bytes.Equal(bytesKV.GetValue().GetBytesValue(), rawBytes), "expected matching byte slice")
}
// Assertion 2: KeyValue supports complex and nested attribute values including ArrayValue and KeyValueList
{
arrKV := &commonpb.KeyValue{
Key: "service.tags",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_ArrayValue{
ArrayValue: &commonpb.ArrayValue{
Values: []*commonpb.AnyValue{
{Value: &commonpb.AnyValue_StringValue{StringValue: "auth"}},
{Value: &commonpb.AnyValue_StringValue{StringValue: "oauth2"}},
},
},
},
},
}
assert(arrKV.GetKey() == "service.tags", "expected Key 'service.tags'")
arrVals := arrKV.GetValue().GetArrayValue().GetValues()
assert(len(arrVals) == 2, "expected 2 array values")
assert(arrVals[0].GetStringValue() == "auth", "expected first element 'auth'")
assert(arrVals[1].GetStringValue() == "oauth2", "expected second element 'oauth2'")
nestedKVList := &commonpb.KeyValue{
Key: "service.meta",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_KvlistValue{
KvlistValue: &commonpb.KeyValueList{
Values: []*commonpb.KeyValue{
{
Key: "cluster",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "us-east-1"},
},
},
},
},
},
},
}
assert(nestedKVList.GetKey() == "service.meta", "expected Key 'service.meta'")
subList := nestedKVList.GetValue().GetKvlistValue().GetValues()
assert(len(subList) == 1, "expected 1 nested KeyValue element")
assert(subList[0].GetKey() == "cluster", "expected nested key 'cluster'")
assert(subList[0].GetValue().GetStringValue() == "us-east-1", "expected nested value 'us-east-1'")
}
// Assertion 3: KeyValue getters safely handle nil receivers and unpopulated instances without panic, returning zero values
{
var nilKV *commonpb.KeyValue
assert(nilKV.GetKey() == "", "nil KeyValue GetKey must return empty string")
assert(nilKV.GetValue() == nil, "nil KeyValue GetValue must return nil")
emptyKV := &commonpb.KeyValue{}
assert(emptyKV.GetKey() == "", "empty KeyValue GetKey must return empty string")
assert(emptyKV.GetValue() == nil, "empty KeyValue GetValue must return nil")
}
// Assertion 4: KeyValue serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal
{
orig := &commonpb.KeyValue{
Key: "session.id",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "sess-12345"},
},
}
wire, err := proto.Marshal(orig)
assert(err == nil, "proto.Marshal failed")
assert(len(wire) > 0, "marshaled wire length is 0")
unmarshaled := &commonpb.KeyValue{}
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: KeyValue serializes to and deserializes from protojson format, preserving field names key and value and nested structures
{
orig := &commonpb.KeyValue{
Key: "endpoint",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "/api/v1/resource"},
},
}
jsonBytes, err := protojson.Marshal(orig)
assert(err == nil, "protojson.Marshal failed")
assert(bytes.Contains(jsonBytes, []byte(`"key"`)), "json must contain 'key'")
assert(bytes.Contains(jsonBytes, []byte(`"value"`)), "json must contain 'value'")
jsonUnmarshaled := &commonpb.KeyValue{}
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 KeyValue where mutating key or the cloned nested AnyValue does not affect the original
{
orig := &commonpb.KeyValue{
Key: "original.key",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "original.val"},
},
}
cloned := proto.Clone(orig).(*commonpb.KeyValue)
assert(proto.Equal(orig, cloned), "cloned KeyValue must equal original")
cloned.Key = "mutated.key"
cloned.Value = &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "mutated.val"},
}
assert(orig.GetKey() == "original.key", "original KeyValue Key was mutated")
assert(orig.GetValue().GetStringValue() == "original.val", "original KeyValue Value was mutated")
assert(!proto.Equal(orig, cloned), "orig should not equal mutated clone")
}
fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/common/v1.KeyValue contract assertions verified")
}
오리진 시더
익명