CodeSampleX

샘플

go.opentelemetry.io/proto/otlp v1.9.0: v1.NumberDataPoint_AsDouble

검증된 샘플 — golang go.opentelemetry.io/proto/otlp v1.9.0: v1.NumberDataPoint_AsDouble. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:a2f582110fd6a34989f14a62d81d542945855cc1107b043ef174b91b40d80f23

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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.NumberDataPoint_AsDouble in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
패키지
심벌
  • go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsDouble
생성일
2026-09-05T18:48:53Z

컨트랙트

  1. NumberDataPoint_AsDouble wraps a float64 value as the value oneof variant in NumberDataPoint, accessible via GetAsDouble and type-asserted from GetValue.
  2. NumberDataPoint getters return zero value 0.0 for AsDouble when the receiver is nil or populated with alternative oneof variants such as AsInt.
  3. NumberDataPoint configured with NumberDataPoint_AsDouble serializes to and deserializes from binary Protobuf wire format without precision loss, satisfying proto.Equal.
  4. NumberDataPoint with NumberDataPoint_AsDouble serializes to protojson using the asDouble field name and deserializes back into an identical struct.
  5. proto.Clone creates an independent deep copy of NumberDataPoint containing NumberDataPoint_AsDouble, allowing isolated modifications.
  6. NumberDataPoint with NumberDataPoint_AsDouble integrates into parent metric structures including Gauge and Sum data points within MetricsData.

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/main.go

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.NumberDataPoint_AsDouble 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.NumberDataPoint_AsDouble

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.
csx.json
{"case":{"caseId":"case:sha256:605a169a75418569d499be412d83ce8d1a5d281d88cc14889cfbbc89964bcf83","contract":["NumberDataPoint_AsDouble wraps a float64 value as the value oneof variant in NumberDataPoint, accessible via GetAsDouble and type-asserted from GetValue.","NumberDataPoint getters return zero value 0.0 for AsDouble when the receiver is nil or populated with alternative oneof variants such as AsInt.","NumberDataPoint configured with NumberDataPoint_AsDouble serializes to and deserializes from binary Protobuf wire format without precision loss, satisfying proto.Equal.","NumberDataPoint with NumberDataPoint_AsDouble serializes to protojson using the asDouble field name and deserializes back into an identical struct.","proto.Clone creates an independent deep copy of NumberDataPoint containing NumberDataPoint_AsDouble, allowing isolated modifications.","NumberDataPoint with NumberDataPoint_AsDouble integrates into parent metric structures including Gauge and Sum data points within MetricsData."],"goal":"verify go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsDouble 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.NumberDataPoint_AsDouble"]},"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.NumberDataPoint_AsDouble"],"verifierAdapter":"golang@1"}
go.mod
module example.com/otlpnumberdatapoint

go 1.26.6

require (
	go.opentelemetry.io/proto/otlp v1.9.0
	google.golang.org/protobuf v1.36.10
)
go.sum
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=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsDouble 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.NumberDataPoint_AsDouble"
  ]
}
test/main.go
package main

import (
	"bytes"
	"fmt"
	"math"
	"os"

	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: NumberDataPoint_AsDouble wraps a float64 value as the value oneof variant in NumberDataPoint, accessible via GetAsDouble and type-asserted from GetValue
	{
		dp := &metricspb.NumberDataPoint{
			TimeUnixNano: 1700000000000000000,
			Value: &metricspb.NumberDataPoint_AsDouble{
				AsDouble: 3.141592653589793,
			},
		}

		assert(dp.GetAsDouble() == 3.141592653589793, "GetAsDouble must return 3.141592653589793")
		assert(dp.GetAsInt() == 0, "GetAsInt must return 0 when AsDouble is set")

		val := dp.GetValue()
		asDoubleVal, ok := val.(*metricspb.NumberDataPoint_AsDouble)
		assert(ok, "GetValue must be of type *metricspb.NumberDataPoint_AsDouble")
		assert(asDoubleVal.AsDouble == 3.141592653589793, "asDoubleVal.AsDouble must match")
	}

	// Assertion 2: NumberDataPoint getters return zero value 0.0 for AsDouble when the receiver is nil or populated with alternative oneof variants such as AsInt
	{
		var nilDp *metricspb.NumberDataPoint
		assert(nilDp.GetAsDouble() == 0.0, "nil receiver GetAsDouble must return 0.0")
		assert(nilDp.GetValue() == nil, "nil receiver GetValue must return nil")

		emptyDp := &metricspb.NumberDataPoint{}
		assert(emptyDp.GetAsDouble() == 0.0, "empty NumberDataPoint GetAsDouble must return 0.0")
		assert(emptyDp.GetValue() == nil, "empty NumberDataPoint GetValue must return nil")

		intDp := &metricspb.NumberDataPoint{
			Value: &metricspb.NumberDataPoint_AsInt{
				AsInt: 100,
			},
		}
		assert(intDp.GetAsDouble() == 0.0, "NumberDataPoint with AsInt must return 0.0 for GetAsDouble")
		assert(intDp.GetAsInt() == 100, "NumberDataPoint with AsInt must return 100 for GetAsInt")
	}

	// Assertion 3: NumberDataPoint configured with NumberDataPoint_AsDouble serializes to and deserializes from binary Protobuf wire format without precision loss, satisfying proto.Equal
	{
		orig := &metricspb.NumberDataPoint{
			StartTimeUnixNano: 1600000000000000000,
			TimeUnixNano:      1600000060000000000,
			Value: &metricspb.NumberDataPoint_AsDouble{
				AsDouble: 1234567.89012345,
			},
			Flags: uint32(metricspb.DataPointFlags_DATA_POINT_FLAGS_NO_RECORDED_VALUE_MASK),
		}

		wire, err := proto.Marshal(orig)
		assert(err == nil, "proto.Marshal failed")
		assert(len(wire) > 0, "marshaled wire must not be empty")

		unmarshaled := &metricspb.NumberDataPoint{}
		err = proto.Unmarshal(wire, unmarshaled)
		assert(err == nil, "proto.Unmarshal failed")
		assert(proto.Equal(orig, unmarshaled), "unmarshaled message must equal original")
		assert(unmarshaled.GetAsDouble() == 1234567.89012345, "unmarshaled AsDouble value must match")
	}

	// Assertion 4: NumberDataPoint with NumberDataPoint_AsDouble serializes to protojson using the asDouble field name and deserializes back into an identical struct
	{
		orig := &metricspb.NumberDataPoint{
			TimeUnixNano: 1700000000000000000,
			Value: &metricspb.NumberDataPoint_AsDouble{
				AsDouble: 271.828,
			},
		}

		jsonBytes, err := protojson.Marshal(orig)
		assert(err == nil, "protojson.Marshal failed")
		assert(bytes.Contains(jsonBytes, []byte(`"asDouble":271.828`)), "json must contain '\"asDouble\":271.828'")

		jsonUnmarshaled := &metricspb.NumberDataPoint{}
		err = protojson.Unmarshal(jsonBytes, jsonUnmarshaled)
		assert(err == nil, "protojson.Unmarshal failed")
		assert(proto.Equal(orig, jsonUnmarshaled), "protojson round-trip must equal original")
		assert(jsonUnmarshaled.GetAsDouble() == 271.828, "protojson round-trip GetAsDouble must match")
	}

	// Assertion 5: proto.Clone creates an independent deep copy of NumberDataPoint containing NumberDataPoint_AsDouble, allowing isolated modifications
	{
		orig := &metricspb.NumberDataPoint{
			TimeUnixNano: 1700000000000000000,
			Value: &metricspb.NumberDataPoint_AsDouble{
				AsDouble: 42.0,
			},
		}

		cloned := proto.Clone(orig).(*metricspb.NumberDataPoint)
		assert(proto.Equal(orig, cloned), "cloned message must equal original")

		// Mutate the clone's AsDouble value
		cloned.Value = &metricspb.NumberDataPoint_AsDouble{
			AsDouble: 99.9,
		}
		assert(orig.GetAsDouble() == 42.0, "original value must remain unchanged after mutating clone")
		assert(cloned.GetAsDouble() == 99.9, "cloned value must reflect the mutation")
		assert(!proto.Equal(orig, cloned), "mutated clone must not equal original")
	}

	// Assertion 6: NumberDataPoint with NumberDataPoint_AsDouble integrates into parent metric structures including Gauge and Sum data points within MetricsData
	{
		dp1 := &metricspb.NumberDataPoint{
			TimeUnixNano: 1700000000000000000,
			Value: &metricspb.NumberDataPoint_AsDouble{
				AsDouble: 10.5,
			},
		}
		dp2 := &metricspb.NumberDataPoint{
			TimeUnixNano: 1700000001000000000,
			Value: &metricspb.NumberDataPoint_AsDouble{
				AsDouble: math.Pi,
			},
		}

		gaugeMetric := &metricspb.Metric{
			Name:        "cpu_temperature_celsius",
			Description: "Current CPU temperature in Celsius",
			Unit:        "Cel",
			Data: &metricspb.Metric_Gauge{
				Gauge: &metricspb.Gauge{
					DataPoints: []*metricspb.NumberDataPoint{dp1, dp2},
				},
			},
		}

		gauge := gaugeMetric.GetGauge()
		assert(gauge != nil, "GetGauge must not be nil")
		assert(len(gauge.GetDataPoints()) == 2, "Gauge must contain 2 data points")
		assert(gauge.GetDataPoints()[0].GetAsDouble() == 10.5, "First point AsDouble must be 10.5")
		assert(gauge.GetDataPoints()[1].GetAsDouble() == math.Pi, "Second point AsDouble must be math.Pi")

		// Verify binary round-trip of the entire metric message
		wire, err := proto.Marshal(gaugeMetric)
		assert(err == nil, "proto.Marshal on Metric containing NumberDataPoint_AsDouble failed")
		unmarshaledMetric := &metricspb.Metric{}
		err = proto.Unmarshal(wire, unmarshaledMetric)
		assert(err == nil, "proto.Unmarshal on Metric failed")
		assert(proto.Equal(gaugeMetric, unmarshaledMetric), "Metric proto.Equal failed")
	}

	fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsDouble contract assertions verified")
}

오리진 시더

익명