示例
go.opentelemetry.io/proto/otlp v1.9.0: v1.InstrumentationScope
已验证示例 — golang go.opentelemetry.io/proto/otlp v1.9.0: v1.InstrumentationScope. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过.
sha256:017bb59756b43854c3d161a645e8a79f64428939697419260f9effd2404afc8a
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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.InstrumentationScope in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- 符号
-
- go.opentelemetry.io/proto/otlp/common/v1.InstrumentationScope
- 创建时间
- 2026-09-05T15:05:49Z
契约
- InstrumentationScope stores name, version, attributes, and dropped attributes count.
- InstrumentationScope getters safely handle nil receivers and unpopulated instances without panic, returning zero values.
- InstrumentationScope serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.
- InstrumentationScope serializes to and deserializes from protojson format, preserving field names and nested attributes.
- proto.Clone produces an isolated deep copy of InstrumentationScope where mutating attributes 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.InstrumentationScope 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.InstrumentationScope
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:cb7b88942b3013c3d8500cfdc1702ea04afd800efbcc40af28542c7bb2a672b1","contract":["InstrumentationScope stores name, version, attributes, and dropped attributes count.","InstrumentationScope getters safely handle nil receivers and unpopulated instances without panic, returning zero values.","InstrumentationScope serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.","InstrumentationScope serializes to and deserializes from protojson format, preserving field names and nested attributes.","proto.Clone produces an isolated deep copy of InstrumentationScope where mutating attributes does not affect the original."],"goal":"verify go.opentelemetry.io/proto/otlp/common/v1.InstrumentationScope 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.InstrumentationScope"]},"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.InstrumentationScope"],"verifierAdapter":"golang@1"}
module example.com/otlpinstrumentationscope
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/common/v1.InstrumentationScope 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.InstrumentationScope"
]
}
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: InstrumentationScope stores name, version, attributes, and dropped attributes count
{
scope := &commonpb.InstrumentationScope{
Name: "io.opentelemetry.example",
Version: "1.2.3",
Attributes: []*commonpb.KeyValue{
{
Key: "service.name",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "payment-service"},
},
},
{
Key: "library.language",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "go"},
},
},
},
DroppedAttributesCount: 2,
}
assert(scope.GetName() == "io.opentelemetry.example", "expected Name 'io.opentelemetry.example'")
assert(scope.GetVersion() == "1.2.3", "expected Version '1.2.3'")
assert(len(scope.GetAttributes()) == 2, "expected 2 attributes")
assert(scope.GetAttributes()[0].GetKey() == "service.name", "expected first attribute key 'service.name'")
assert(scope.GetAttributes()[0].GetValue().GetStringValue() == "payment-service", "expected first attribute value 'payment-service'")
assert(scope.GetAttributes()[1].GetKey() == "library.language", "expected second attribute key 'library.language'")
assert(scope.GetAttributes()[1].GetValue().GetStringValue() == "go", "expected second attribute value 'go'")
assert(scope.GetDroppedAttributesCount() == 2, "expected DroppedAttributesCount 2")
}
// Assertion 2: InstrumentationScope getters safely handle nil receivers and unpopulated instances without panic, returning zero values
{
var nilScope *commonpb.InstrumentationScope
assert(nilScope.GetName() == "", "nil InstrumentationScope GetName must return empty string")
assert(nilScope.GetVersion() == "", "nil InstrumentationScope GetVersion must return empty string")
assert(nilScope.GetAttributes() == nil, "nil InstrumentationScope GetAttributes must return nil")
assert(nilScope.GetDroppedAttributesCount() == 0, "nil InstrumentationScope GetDroppedAttributesCount must return 0")
emptyScope := &commonpb.InstrumentationScope{}
assert(emptyScope.GetName() == "", "empty InstrumentationScope GetName must return empty string")
assert(emptyScope.GetVersion() == "", "empty InstrumentationScope GetVersion must return empty string")
assert(emptyScope.GetAttributes() == nil, "empty InstrumentationScope GetAttributes must return nil")
assert(emptyScope.GetDroppedAttributesCount() == 0, "empty InstrumentationScope GetDroppedAttributesCount must return 0")
}
// Assertion 3: InstrumentationScope serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal
{
orig := &commonpb.InstrumentationScope{
Name: "net.http.client",
Version: "2.0.0",
Attributes: []*commonpb.KeyValue{
{
Key: "component",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "http"},
},
},
},
DroppedAttributesCount: 1,
}
wire, err := proto.Marshal(orig)
assert(err == nil, "proto.Marshal failed")
assert(len(wire) > 0, "marshaled wire length is 0")
unmarshaled := &commonpb.InstrumentationScope{}
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 4: InstrumentationScope serializes to and deserializes from protojson format, preserving field names and nested attributes
{
orig := &commonpb.InstrumentationScope{
Name: "database.sql",
Version: "0.5.1",
Attributes: []*commonpb.KeyValue{
{
Key: "db.system",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "postgresql"},
},
},
},
DroppedAttributesCount: 5,
}
jsonBytes, err := protojson.Marshal(orig)
assert(err == nil, "protojson.Marshal failed")
assert(bytes.Contains(jsonBytes, []byte(`"name"`)), "json must contain 'name'")
assert(bytes.Contains(jsonBytes, []byte(`"version"`)), "json must contain 'version'")
assert(bytes.Contains(jsonBytes, []byte(`"attributes"`)), "json must contain 'attributes'")
assert(bytes.Contains(jsonBytes, []byte(`"droppedAttributesCount"`)), "json must contain 'droppedAttributesCount'")
jsonUnmarshaled := &commonpb.InstrumentationScope{}
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 5: proto.Clone produces an isolated deep copy of InstrumentationScope where mutating attributes does not affect the original
{
orig := &commonpb.InstrumentationScope{
Name: "cache.redis",
Version: "1.0.0",
Attributes: []*commonpb.KeyValue{
{
Key: "cache.type",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{StringValue: "redis"},
},
},
},
DroppedAttributesCount: 0,
}
cloned := proto.Clone(orig).(*commonpb.InstrumentationScope)
assert(proto.Equal(orig, cloned), "cloned InstrumentationScope must equal original")
cloned.Name = "cache.memcached"
cloned.Attributes[0].Key = "mutated.key"
cloned.DroppedAttributesCount = 10
assert(orig.GetName() == "cache.redis", "original Scope Name was mutated")
assert(orig.GetAttributes()[0].GetKey() == "cache.type", "original Scope Attribute Key was mutated")
assert(orig.GetDroppedAttributesCount() == 0, "original Scope DroppedAttributesCount was mutated")
assert(!proto.Equal(orig, cloned), "orig should not equal mutated clone")
}
fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/common/v1.InstrumentationScope contract assertions verified")
}
原始种子者
匿名