示例
go.opentelemetry.io/proto/otlp v1.9.0: v1.Sum
已验证示例 — golang go.opentelemetry.io/proto/otlp v1.9.0: v1.Sum. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: Sum represents a scalar metric…
sha256:e71e1d74c5de66f8bf587f4db87e8c6fe43d3c1afab9ddec41808048c5d3690f
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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/metrics/v1.Sum in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- 符号
-
- go.opentelemetry.io/proto/otlp/metrics/v1.Sum
- 创建时间
- 2026-09-05T20:39:04Z
契约
- Sum represents a scalar metric calculated as a sum over a time interval with configurable aggregation temporality and monotonicity.
- Sum holds multiple NumberDataPoints supporting both integer and double scalar values with timestamps and attributes.
- Sum getters safely handle nil receivers and unpopulated instances without panic by returning default zero values.
- Sum serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.
- Sum serializes to and deserializes from protojson format, preserving field names and enum string mappings.
- proto.Clone produces an isolated deep copy of Sum where mutating cloned data points 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/metrics/v1.Sum 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.Sum
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:40dd191fc8f29689d21d33d50940147d770dc4ded753b4d7cd005c198c11f67f","contract":["Sum represents a scalar metric calculated as a sum over a time interval with configurable aggregation temporality and monotonicity.","Sum holds multiple NumberDataPoints supporting both integer and double scalar values with timestamps and attributes.","Sum getters safely handle nil receivers and unpopulated instances without panic by returning default zero values.","Sum serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.","Sum serializes to and deserializes from protojson format, preserving field names and enum string mappings.","proto.Clone produces an isolated deep copy of Sum where mutating cloned data points does not affect the original."],"goal":"verify go.opentelemetry.io/proto/otlp/metrics/v1.Sum 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.Sum"]},"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.Sum"],"verifierAdapter":"golang@1"}
module example.com/otlpsum
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/metrics/v1.Sum 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.Sum"
]
}
package main
import (
"bytes"
"fmt"
"os"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
metricspb "go.opentelemetry.io/proto/otlp/metrics/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: Sum represents a scalar metric calculated as a sum over a time interval with configurable aggregation temporality and monotonicity.
{
sCumulative := &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
}
assert(sCumulative.GetAggregationTemporality() == metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, "expected CUMULATIVE temporality")
assert(sCumulative.GetIsMonotonic() == true, "expected IsMonotonic true")
sDelta := &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA,
IsMonotonic: false,
}
assert(sDelta.GetAggregationTemporality() == metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, "expected DELTA temporality")
assert(sDelta.GetIsMonotonic() == false, "expected IsMonotonic false")
}
// Assertion 2: Sum holds multiple NumberDataPoints supporting both integer and double scalar values with timestamps and attributes.
{
dpInt := &metricspb.NumberDataPoint{
StartTimeUnixNano: 1000000000,
TimeUnixNano: 2000000000,
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 1042},
Attributes: []*commonpb.KeyValue{
{
Key: "http.status_code",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_IntValue{IntValue: 200}},
},
},
}
dpDouble := &metricspb.NumberDataPoint{
StartTimeUnixNano: 1000000000,
TimeUnixNano: 2000000000,
Value: &metricspb.NumberDataPoint_AsDouble{AsDouble: 3.14159},
Attributes: []*commonpb.KeyValue{
{
Key: "http.route",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "/api/v1/resource"}},
},
},
}
s := &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*metricspb.NumberDataPoint{dpInt, dpDouble},
}
points := s.GetDataPoints()
assert(len(points) == 2, "expected 2 data points")
assert(points[0].GetAsInt() == 1042, "expected int value 1042")
assert(points[0].GetStartTimeUnixNano() == 1000000000, "expected start time 1000000000")
assert(points[0].GetTimeUnixNano() == 2000000000, "expected time 2000000000")
assert(len(points[0].GetAttributes()) == 1, "expected 1 attribute on first point")
assert(points[0].GetAttributes()[0].GetKey() == "http.status_code", "expected key http.status_code")
assert(points[0].GetAttributes()[0].GetValue().GetIntValue() == 200, "expected value 200")
assert(points[1].GetAsDouble() == 3.14159, "expected double value 3.14159")
assert(len(points[1].GetAttributes()) == 1, "expected 1 attribute on second point")
assert(points[1].GetAttributes()[0].GetKey() == "http.route", "expected key http.route")
assert(points[1].GetAttributes()[0].GetValue().GetStringValue() == "/api/v1/resource", "expected route string")
}
// Assertion 3: Sum getters safely handle nil receivers and unpopulated instances without panic by returning default zero values.
{
var nilSum *metricspb.Sum
assert(nilSum.GetDataPoints() == nil, "nil Sum GetDataPoints must return nil")
assert(nilSum.GetAggregationTemporality() == metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED, "nil Sum GetAggregationTemporality must return UNSPECIFIED")
assert(nilSum.GetIsMonotonic() == false, "nil Sum GetIsMonotonic must return false")
emptySum := &metricspb.Sum{}
assert(emptySum.GetDataPoints() == nil, "empty Sum GetDataPoints must return nil")
assert(emptySum.GetAggregationTemporality() == metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED, "empty Sum GetAggregationTemporality must return UNSPECIFIED")
assert(emptySum.GetIsMonotonic() == false, "empty Sum GetIsMonotonic must return false")
}
// Assertion 4: Sum serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.
{
orig := &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*metricspb.NumberDataPoint{
{
StartTimeUnixNano: 1609459200000000000,
TimeUnixNano: 1609459260000000000,
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 100},
Attributes: []*commonpb.KeyValue{
{
Key: "service",
Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: "payment"}},
},
},
},
},
}
wire, err := proto.Marshal(orig)
assert(err == nil, "proto.Marshal failed")
assert(len(wire) > 0, "marshaled wire length is 0")
unmarshaled := &metricspb.Sum{}
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: Sum serializes to and deserializes from protojson format, preserving field names and enum string mappings.
{
orig := &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA,
IsMonotonic: true,
DataPoints: []*metricspb.NumberDataPoint{
{
StartTimeUnixNano: 1000,
TimeUnixNano: 2000,
Value: &metricspb.NumberDataPoint_AsDouble{AsDouble: 2.718},
},
},
}
jsonBytes, err := protojson.Marshal(orig)
assert(err == nil, "protojson.Marshal failed")
assert(bytes.Contains(jsonBytes, []byte(`"aggregationTemporality"`)), "json must contain 'aggregationTemporality'")
assert(bytes.Contains(jsonBytes, []byte(`"AGGREGATION_TEMPORALITY_DELTA"`)), "json must contain enum string 'AGGREGATION_TEMPORALITY_DELTA'")
assert(bytes.Contains(jsonBytes, []byte(`"isMonotonic":true`)) || bytes.Contains(jsonBytes, []byte(`"isMonotonic": true`)), "json must contain 'isMonotonic'")
assert(bytes.Contains(jsonBytes, []byte(`"dataPoints"`)), "json must contain 'dataPoints'")
jsonUnmarshaled := &metricspb.Sum{}
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 Sum where mutating cloned data points does not affect the original.
{
orig := &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*metricspb.NumberDataPoint{
{
TimeUnixNano: 1000,
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 50},
},
},
}
cloned := proto.Clone(orig).(*metricspb.Sum)
assert(proto.Equal(orig, cloned), "cloned Sum must equal original")
// Mutate cloned fields and data point
cloned.IsMonotonic = false
cloned.GetDataPoints()[0].Value = &metricspb.NumberDataPoint_AsInt{AsInt: 999}
cloned.DataPoints = append(cloned.DataPoints, &metricspb.NumberDataPoint{
TimeUnixNano: 2000,
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 200},
})
// Verify original remains untouched
assert(orig.GetIsMonotonic() == true, "original Sum IsMonotonic was mutated")
assert(orig.GetDataPoints()[0].GetAsInt() == 50, "original Sum data point was mutated")
assert(len(orig.GetDataPoints()) == 1, "original Sum data point count was modified")
}
fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/metrics/v1.Sum contract assertions verified")
}
原始种子者
匿名