Exemple
go.opentelemetry.io/proto/otlp v1.9.0: v1.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE
Échantillon vérifié pour golang go.opentelemetry.io/proto/otlp v1.9.0: v1.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE. Le contrat s'est exécuté…
sha256:83ea8b54cfe37b0522f931f25c8609f3ea64948416562c8518df223c43e83af4
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 go
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify go.opentelemetry.io/proto/otlp/metrics/v1.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- Symboles
-
- go.opentelemetry.io/proto/otlp/metrics/v1.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE
- Créé
- 2026-09-05T21:22:08Z
Contrat
- AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE has constant int32 value 2, protoreflect Number 2, string representation AGGREGATION_TEMPORALITY_CUMULATIVE, and consistent name/value map lookups.
- Sum, Histogram, and ExponentialHistogram metric structs configure AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE and retrieve it via GetAggregationTemporality, defaulting to UNSPECIFIED when nil.
- AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE persists across protobuf binary marshaling and unmarshaling in Metric messages containing Sum and Histogram payloads.
- AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE serializes to JSON as enum string and enum number formats and round-trips correctly via protojson.
Fichiers
- NOTES.md
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Code source
# OpenTelemetry OTLP AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE Semantics
A search for `go.opentelemetry.io/proto/otlp/metrics/v1.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE` in `pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0` returned `NO_SAFE_MATCH`.
This sample verifies the enum constant, string mapping, metric container integration, binary protobuf serialization, and protojson serialization for `AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE`.
## Observed Behavior
1. **Enum Value and String Mapping**:
- `AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE` has integer value 2 and protoreflect enum number 2.
- Calling `.String()` yields `"AGGREGATION_TEMPORALITY_CUMULATIVE"`.
- `AggregationTemporality_name[2]` returns `"AGGREGATION_TEMPORALITY_CUMULATIVE"`.
- `AggregationTemporality_value["AGGREGATION_TEMPORALITY_CUMULATIVE"]` returns 2.
- `Enum()` returns a pointer referencing the enum constant.
2. **Metric Type Integration (`Sum`, `Histogram`, `ExponentialHistogram`)**:
- `Sum.AggregationTemporality`, `Histogram.AggregationTemporality`, and `ExponentialHistogram.AggregationTemporality` store how metric values aggregate over time.
- `GetAggregationTemporality()` returns `AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE` when set, and defaults safely to `AGGREGATION_TEMPORALITY_UNSPECIFIED` (0) on nil or uninitialized structs.
3. **Protobuf Binary Wire Format**:
- Serializing a `Metric` containing a `Sum` or `Histogram` with cumulative temporality preserves the enum value across `proto.Marshal` and `proto.Unmarshal`.
4. **JSON Serialization (`protojson`)**:
- Standard serialization renders the enum as the string `"AGGREGATION_TEMPORALITY_CUMULATIVE"`.
- With `protojson.MarshalOptions{UseEnumNumbers: true}`, the enum is serialized numerically (`2`).
- Both formats round-trip cleanly back to `AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE`.
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.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE 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.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE
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:1095233a6d8f8ed4c5cb0ed6024a37089d3588e57f6914093247c72d994c989e","contract":["AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE has constant int32 value 2, protoreflect Number 2, string representation AGGREGATION_TEMPORALITY_CUMULATIVE, and consistent name/value map lookups.","Sum, Histogram, and ExponentialHistogram metric structs configure AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE and retrieve it via GetAggregationTemporality, defaulting to UNSPECIFIED when nil.","AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE persists across protobuf binary marshaling and unmarshaling in Metric messages containing Sum and Histogram payloads.","AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE serializes to JSON as enum string and enum number formats and round-trips correctly via protojson."],"goal":"verify go.opentelemetry.io/proto/otlp/metrics/v1.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE 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.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE"]},"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.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE"],"verifierAdapter":"golang@1"}
module example.com/otlp-cumulative
go 1.23.0
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=
package main
import (
"fmt"
metricspb "go.opentelemetry.io/proto/otlp/metrics/v1"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
// BuildCumulativeSumMetric creates a Metric containing a Sum with CUMULATIVE temporality.
func BuildCumulativeSumMetric(name string, value int64) *metricspb.Metric {
return &metricspb.Metric{
Name: name,
Data: &metricspb.Metric_Sum{
Sum: &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*metricspb.NumberDataPoint{
{
Value: &metricspb.NumberDataPoint_AsInt{
AsInt: value,
},
},
},
},
},
}
}
// BuildCumulativeHistogramMetric creates a Metric containing a Histogram with CUMULATIVE temporality.
func BuildCumulativeHistogramMetric(name string, count uint64, sum float64) *metricspb.Metric {
return &metricspb.Metric{
Name: name,
Data: &metricspb.Metric_Histogram{
Histogram: &metricspb.Histogram{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
DataPoints: []*metricspb.HistogramDataPoint{
{
Count: count,
Sum: &sum,
},
},
},
},
}
}
// EncodeMetricBinary serializes an OTLP Metric into protobuf binary format.
func EncodeMetricBinary(m *metricspb.Metric) ([]byte, error) {
return proto.Marshal(m)
}
// DecodeMetricBinary deserializes an OTLP Metric from protobuf binary format.
func DecodeMetricBinary(data []byte) (*metricspb.Metric, error) {
var m metricspb.Metric
if err := proto.Unmarshal(data, &m); err != nil {
return nil, err
}
return &m, nil
}
// EncodeMetricJSON serializes an OTLP Metric into protojson format.
func EncodeMetricJSON(m *metricspb.Metric, useEnumNumbers bool) ([]byte, error) {
opts := protojson.MarshalOptions{
UseEnumNumbers: useEnumNumbers,
}
return opts.Marshal(m)
}
// DecodeMetricJSON deserializes an OTLP Metric from protojson format.
func DecodeMetricJSON(data []byte) (*metricspb.Metric, error) {
var m metricspb.Metric
if err := protojson.Unmarshal(data, &m); err != nil {
return nil, err
}
return &m, nil
}
func main() {
m := BuildCumulativeSumMetric("http_requests_total", 1024)
temporality := m.GetSum().GetAggregationTemporality()
fmt.Printf("Metric: %s, Temporality: %s (value=%d)\n", m.GetName(), temporality.String(), int32(temporality))
}
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/proto/otlp/metrics/v1.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE 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.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE"
]
}
package main
import (
"fmt"
"os"
"strings"
metricspb "go.opentelemetry.io/proto/otlp/metrics/v1"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
func main() {
// Assertion 1: AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE has constant int32 value 2, protoreflect Number 2, string representation "AGGREGATION_TEMPORALITY_CUMULATIVE", and consistent name/value map lookups.
{
cum := metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE
if int32(cum) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected int32 value 2 for CUMULATIVE, got %d\n", int32(cum))
os.Exit(1)
}
if cum.Number() != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected protoreflect Number 2 for CUMULATIVE, got %d\n", cum.Number())
os.Exit(1)
}
if cum.String() != "AGGREGATION_TEMPORALITY_CUMULATIVE" {
fmt.Fprintf(os.Stderr, "FAIL: expected String() 'AGGREGATION_TEMPORALITY_CUMULATIVE', got %s\n", cum.String())
os.Exit(1)
}
if name, ok := metricspb.AggregationTemporality_name[2]; !ok || name != "AGGREGATION_TEMPORALITY_CUMULATIVE" {
fmt.Fprintf(os.Stderr, "FAIL: name map lookup failed: ok=%v name=%s\n", ok, name)
os.Exit(1)
}
if val, ok := metricspb.AggregationTemporality_value["AGGREGATION_TEMPORALITY_CUMULATIVE"]; !ok || val != 2 {
fmt.Fprintf(os.Stderr, "FAIL: value map lookup failed: ok=%v val=%d\n", ok, val)
os.Exit(1)
}
if enumPtr := cum.Enum(); enumPtr == nil || *enumPtr != cum {
fmt.Fprintf(os.Stderr, "FAIL: Enum() pointer value invalid\n")
os.Exit(1)
}
}
// Assertion 2: Sum, Histogram, and ExponentialHistogram metric structs configure AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE and retrieve it via GetAggregationTemporality, defaulting to UNSPECIFIED when nil.
{
var nilSum *metricspb.Sum
if nilSum.GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED {
fmt.Fprintf(os.Stderr, "FAIL: nil Sum should return UNSPECIFIED, got %v\n", nilSum.GetAggregationTemporality())
os.Exit(1)
}
var nilHist *metricspb.Histogram
if nilHist.GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED {
fmt.Fprintf(os.Stderr, "FAIL: nil Histogram should return UNSPECIFIED, got %v\n", nilHist.GetAggregationTemporality())
os.Exit(1)
}
var nilExpHist *metricspb.ExponentialHistogram
if nilExpHist.GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED {
fmt.Fprintf(os.Stderr, "FAIL: nil ExponentialHistogram should return UNSPECIFIED, got %v\n", nilExpHist.GetAggregationTemporality())
os.Exit(1)
}
sum := &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
}
if sum.GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE {
fmt.Fprintf(os.Stderr, "FAIL: sum.GetAggregationTemporality() expected CUMULATIVE, got %v\n", sum.GetAggregationTemporality())
os.Exit(1)
}
hist := &metricspb.Histogram{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
}
if hist.GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE {
fmt.Fprintf(os.Stderr, "FAIL: hist.GetAggregationTemporality() expected CUMULATIVE, got %v\n", hist.GetAggregationTemporality())
os.Exit(1)
}
expHist := &metricspb.ExponentialHistogram{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
}
if expHist.GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE {
fmt.Fprintf(os.Stderr, "FAIL: expHist.GetAggregationTemporality() expected CUMULATIVE, got %v\n", expHist.GetAggregationTemporality())
os.Exit(1)
}
}
// Assertion 3: AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE persists across protobuf binary marshaling and unmarshaling in Metric messages containing Sum and Histogram payloads.
{
sumMetric := &metricspb.Metric{
Name: "system_cpu_time",
Data: &metricspb.Metric_Sum{
Sum: &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*metricspb.NumberDataPoint{
{
Value: &metricspb.NumberDataPoint_AsInt{
AsInt: 4096,
},
},
},
},
},
}
sumData, err := proto.Marshal(sumMetric)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: proto.Marshal sumMetric failed: %v\n", err)
os.Exit(1)
}
var decodedSumMetric metricspb.Metric
if err := proto.Unmarshal(sumData, &decodedSumMetric); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: proto.Unmarshal sumMetric failed: %v\n", err)
os.Exit(1)
}
if decodedSumMetric.GetSum().GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE {
fmt.Fprintf(os.Stderr, "FAIL: decoded sum temporality mismatch: expected CUMULATIVE, got %s\n", decodedSumMetric.GetSum().GetAggregationTemporality())
os.Exit(1)
}
histSum := 55.5
histMetric := &metricspb.Metric{
Name: "http_server_duration_seconds",
Data: &metricspb.Metric_Histogram{
Histogram: &metricspb.Histogram{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
DataPoints: []*metricspb.HistogramDataPoint{
{
Count: 10,
Sum: &histSum,
},
},
},
},
}
histData, err := proto.Marshal(histMetric)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: proto.Marshal histMetric failed: %v\n", err)
os.Exit(1)
}
var decodedHistMetric metricspb.Metric
if err := proto.Unmarshal(histData, &decodedHistMetric); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: proto.Unmarshal histMetric failed: %v\n", err)
os.Exit(1)
}
if decodedHistMetric.GetHistogram().GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE {
fmt.Fprintf(os.Stderr, "FAIL: decoded hist temporality mismatch: expected CUMULATIVE, got %s\n", decodedHistMetric.GetHistogram().GetAggregationTemporality())
os.Exit(1)
}
}
// Assertion 4: AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE serializes to JSON as enum string and enum number formats and round-trips correctly via protojson.
{
metric := &metricspb.Metric{
Name: "requests_processed_total",
Data: &metricspb.Metric_Sum{
Sum: &metricspb.Sum{
AggregationTemporality: metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
},
},
}
// String format JSON
jsonDefault, err := protojson.Marshal(metric)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: protojson.Marshal failed: %v\n", err)
os.Exit(1)
}
if !strings.Contains(string(jsonDefault), `"AGGREGATION_TEMPORALITY_CUMULATIVE"`) {
fmt.Fprintf(os.Stderr, "FAIL: expected string enum 'AGGREGATION_TEMPORALITY_CUMULATIVE' in JSON, got: %s\n", string(jsonDefault))
os.Exit(1)
}
var roundTripDefault metricspb.Metric
if err := protojson.Unmarshal(jsonDefault, &roundTripDefault); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: protojson.Unmarshal default failed: %v\n", err)
os.Exit(1)
}
if roundTripDefault.GetSum().GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE {
fmt.Fprintf(os.Stderr, "FAIL: round-trip default temporality expected CUMULATIVE, got %v\n", roundTripDefault.GetSum().GetAggregationTemporality())
os.Exit(1)
}
// Numeric format JSON
optsNumeric := protojson.MarshalOptions{UseEnumNumbers: true}
jsonNumeric, err := optsNumeric.Marshal(metric)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: protojson.Marshal with UseEnumNumbers failed: %v\n", err)
os.Exit(1)
}
if !strings.Contains(string(jsonNumeric), `"aggregationTemporality":2`) && !strings.Contains(string(jsonNumeric), `"aggregation_temporality":2`) {
fmt.Fprintf(os.Stderr, "FAIL: expected numeric enum 2 in JSON, got: %s\n", string(jsonNumeric))
os.Exit(1)
}
var roundTripNumeric metricspb.Metric
if err := protojson.Unmarshal(jsonNumeric, &roundTripNumeric); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: protojson.Unmarshal numeric failed: %v\n", err)
os.Exit(1)
}
if roundTripNumeric.GetSum().GetAggregationTemporality() != metricspb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE {
fmt.Fprintf(os.Stderr, "FAIL: round-trip numeric temporality expected CUMULATIVE, got %v\n", roundTripNumeric.GetSum().GetAggregationTemporality())
os.Exit(1)
}
}
fmt.Println("PASS: all AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE contract assertions passed")
}
Seeder d'origine
anonyme