샘플
go.opentelemetry.io/proto/otlp v1.9.0: v1.Resource
검증된 샘플 — golang go.opentelemetry.io/proto/otlp v1.9.0: v1.Resource. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:184e0b5b37634736dd026ca27806fe4da9513c13af333323087e0fed00aba2ac
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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/resource/v1.Resource in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- 심벌
-
- go.opentelemetry.io/proto/otlp/resource/v1.Resource
- 생성일
- 2026-09-05T15:37:00Z
컨트랙트
- Resource encapsulates key-value attributes, dropped attributes count, and entity references with typed field getters.
- Resource getters safely handle nil receiver instances and unpopulated messages by returning default zero values without panicking.
- Resource serializes to and deserializes from standard binary Protobuf wire format without data loss, satisfying proto.Equal.
- Resource serializes to and deserializes from protojson format, preserving camelCase field names and attribute structures.
- proto.Clone creates an isolated deep copy of Resource where mutating attributes on the clone does not modify the original.
- Resource.Reset clears all fields restoring the message to its empty zero state.
파일
- 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/resource/v1.Resource 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/resource/v1.Resource
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:114476be4f3f15e14f4366a17206d0db79b60835459deb9aa45f4a7ff5234384","contract":["Resource encapsulates key-value attributes, dropped attributes count, and entity references with typed field getters.","Resource getters safely handle nil receiver instances and unpopulated messages by returning default zero values without panicking.","Resource serializes to and deserializes from standard binary Protobuf wire format without data loss, satisfying proto.Equal.","Resource serializes to and deserializes from protojson format, preserving camelCase field names and attribute structures.","proto.Clone creates an isolated deep copy of Resource where mutating attributes on the clone does not modify the original.","Resource.Reset clears all fields restoring the message to its empty zero state."],"goal":"verify go.opentelemetry.io/proto/otlp/resource/v1.Resource 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/resource/v1.Resource"]},"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/resource/v1.Resource"],"verifierAdapter":"golang@1"}
module example.com/otlpresource
go 1.26.6
require (
go.opentelemetry.io/proto/otlp v1.9.0
google.golang.org/protobuf v1.36.12
)
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.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/proto/otlp/resource/v1.Resource 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/resource/v1.Resource"
]
}
package main
import (
"bytes"
"fmt"
"os"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
resourcepb "go.opentelemetry.io/proto/otlp/resource/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: Resource encapsulates key-value attributes, dropped attributes count, and entity references with typed field getters
{
attr1 := &commonpb.KeyValue{
Key: "service.name",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "order-processor"},
},
}
attr2 := &commonpb.KeyValue{
Key: "service.version",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "1.2.3"},
},
}
res := &resourcepb.Resource{
Attributes: []*commonpb.KeyValue{attr1, attr2},
DroppedAttributesCount: 4,
}
attrs := res.GetAttributes()
assert(len(attrs) == 2, "expected 2 attributes")
assert(attrs[0].GetKey() == "service.name", "expected key 'service.name'")
assert(attrs[0].GetValue().GetStringValue() == "order-processor", "expected value 'order-processor'")
assert(attrs[1].GetKey() == "service.version", "expected key 'service.version'")
assert(attrs[1].GetValue().GetStringValue() == "1.2.3", "expected value '1.2.3'")
assert(res.GetDroppedAttributesCount() == 4, "expected dropped attributes count 4")
assert(res.GetEntityRefs() == nil, "expected nil entity refs when omitted")
}
// Assertion 2: Resource getters safely handle nil receiver instances and unpopulated messages by returning default zero values without panicking
{
var nilRes *resourcepb.Resource
assert(nilRes.GetAttributes() == nil, "nil Resource GetAttributes must return nil")
assert(nilRes.GetDroppedAttributesCount() == 0, "nil Resource GetDroppedAttributesCount must return 0")
assert(nilRes.GetEntityRefs() == nil, "nil Resource GetEntityRefs must return nil")
emptyRes := &resourcepb.Resource{}
assert(emptyRes.GetAttributes() == nil, "empty Resource GetAttributes must return nil")
assert(emptyRes.GetDroppedAttributesCount() == 0, "empty Resource GetDroppedAttributesCount must return 0")
assert(emptyRes.GetEntityRefs() == nil, "empty Resource GetEntityRefs must return nil")
}
// Assertion 3: Resource serializes to and deserializes from standard binary Protobuf wire format without data loss, satisfying proto.Equal
{
orig := &resourcepb.Resource{
Attributes: []*commonpb.KeyValue{
{
Key: "host.id",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "node-42"}},
},
{
Key: "host.arch",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "amd64"}},
},
},
DroppedAttributesCount: 2,
}
wire, err := proto.Marshal(orig)
assert(err == nil, "proto.Marshal failed")
assert(len(wire) > 0, "marshaled wire length must be > 0")
unmarshaled := &resourcepb.Resource{}
err = proto.Unmarshal(wire, unmarshaled)
assert(err == nil, "proto.Unmarshal failed")
assert(proto.Equal(orig, unmarshaled), "proto.Equal failed after wire round-trip")
assert(unmarshaled.GetDroppedAttributesCount() == 2, "unmarshaled dropped attributes count mismatch")
assert(len(unmarshaled.GetAttributes()) == 2, "unmarshaled attributes length mismatch")
}
// Assertion 4: Resource serializes to and deserializes from protojson format, preserving camelCase field names and attribute structures
{
orig := &resourcepb.Resource{
Attributes: []*commonpb.KeyValue{
{
Key: "cloud.provider",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "gcp"}},
},
},
DroppedAttributesCount: 1,
}
jsonBytes, err := protojson.Marshal(orig)
assert(err == nil, "protojson.Marshal failed")
assert(bytes.Contains(jsonBytes, []byte(`"droppedAttributesCount":1`)), "json must contain 'droppedAttributesCount':1")
assert(bytes.Contains(jsonBytes, []byte(`"attributes"`)), "json must contain 'attributes'")
assert(bytes.Contains(jsonBytes, []byte(`"cloud.provider"`)), "json must contain 'cloud.provider'")
jsonUnmarshaled := &resourcepb.Resource{}
err = protojson.Unmarshal(jsonBytes, jsonUnmarshaled)
assert(err == nil, "protojson.Unmarshal failed")
assert(proto.Equal(orig, jsonUnmarshaled), "proto.Equal failed after protojson round-trip")
}
// Assertion 5: proto.Clone creates an isolated deep copy of Resource where mutating attributes on the clone does not modify the original
{
orig := &resourcepb.Resource{
Attributes: []*commonpb.KeyValue{
{
Key: "region",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "us-central1"}},
},
},
DroppedAttributesCount: 5,
}
cloned := proto.Clone(orig).(*resourcepb.Resource)
assert(proto.Equal(orig, cloned), "cloned Resource must equal original")
cloned.DroppedAttributesCount = 10
cloned.Attributes[0].Key = "mutated-key"
cloned.Attributes = append(cloned.Attributes, &commonpb.KeyValue{
Key: "new.key",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "new.value"}},
})
assert(orig.GetDroppedAttributesCount() == 5, "original DroppedAttributesCount mutated")
assert(len(orig.GetAttributes()) == 1, "original Attributes length mutated")
assert(orig.GetAttributes()[0].GetKey() == "region", "original attribute key mutated")
}
// Assertion 6: Resource.Reset clears all fields restoring the message to its empty zero state
{
res := &resourcepb.Resource{
Attributes: []*commonpb.KeyValue{
{
Key: "k",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "v"}},
},
},
DroppedAttributesCount: 3,
}
res.Reset()
assert(res.GetDroppedAttributesCount() == 0, "Reset did not clear DroppedAttributesCount")
assert(len(res.GetAttributes()) == 0, "Reset did not clear Attributes")
assert(proto.Equal(res, &resourcepb.Resource{}), "Reset did not restore to empty Resource")
}
fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/resource/v1.Resource contract assertions verified")
}
오리진 시더
익명