CodeSampleX

샘플

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

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

sha256:c5cc726388ffc7aac08d5452c2219828f063e1033a71a8c0692a5d0cedc1ab69

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

컨트랙트

  1. TracesData represents OTLP trace payloads containing nested ResourceSpans, ScopeSpans, and Spans with associated attributes and status.
  2. TracesData serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.
  3. TracesData serializes to and deserializes from protojson format, preserving field mappings such as resourceSpans.
  4. TracesData GetResourceSpans returns nil safely when called on nil or unpopulated instances.
  5. proto.Clone produces an isolated deep copy of TracesData where mutating repeated spans or nested attributes does not affect the original.

파일

  • 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 trace/v1.TracesData 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:
  - trace/v1.TracesData

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:41415b53b695caac5e83d579e58375edc64ec1ac9511a1fa785c9ef1badf61a5","contract":["TracesData represents OTLP trace payloads containing nested ResourceSpans, ScopeSpans, and Spans with associated attributes and status.","TracesData serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.","TracesData serializes to and deserializes from protojson format, preserving field mappings such as resourceSpans.","TracesData GetResourceSpans returns nil safely when called on nil or unpopulated instances.","proto.Clone produces an isolated deep copy of TracesData where mutating repeated spans or nested attributes does not affect the original."],"goal":"verify trace/v1.TracesData 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":["trace/v1.TracesData"]},"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":["trace/v1.TracesData"],"verifierAdapter":"golang@1"}
go.mod
module example.com/otlptrace

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 trace/v1.TracesData 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": [
    "trace/v1.TracesData"
  ]
}
test/main.go
package main

import (
	"bytes"
	"fmt"
	"os"

	commonpb "go.opentelemetry.io/proto/otlp/common/v1"
	resourcepb "go.opentelemetry.io/proto/otlp/resource/v1"
	tracepb "go.opentelemetry.io/proto/otlp/trace/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() {
	traceID := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
	spanID := []byte{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22}

	span := &tracepb.Span{
		TraceId:           traceID,
		SpanId:            spanID,
		Name:              "execute-query",
		Kind:              tracepb.Span_SPAN_KIND_SERVER,
		StartTimeUnixNano: 1700000000000000000,
		EndTimeUnixNano:   1700000000500000000,
		Attributes: []*commonpb.KeyValue{
			{
				Key: "db.system",
				Value: &commonpb.AnyValue{
					Value: &commonpb.AnyValue_StringValue{StringValue: "postgresql"},
				},
			},
			{
				Key: "db.statement",
				Value: &commonpb.AnyValue{
					Value: &commonpb.AnyValue_StringValue{StringValue: "SELECT 1"},
				},
			},
		},
		Status: &tracepb.Status{
			Code:    tracepb.Status_STATUS_CODE_OK,
			Message: "query executed successfully",
		},
	}

	scopeSpans := &tracepb.ScopeSpans{
		Scope: &commonpb.InstrumentationScope{
			Name:    "db-instrumentation",
			Version: "1.0.0",
		},
		Spans: []*tracepb.Span{span},
	}

	resource := &resourcepb.Resource{
		Attributes: []*commonpb.KeyValue{
			{
				Key: "service.name",
				Value: &commonpb.AnyValue{
					Value: &commonpb.AnyValue_StringValue{StringValue: "query-service"},
				},
			},
		},
	}

	resourceSpans := &tracepb.ResourceSpans{
		Resource:   resource,
		ScopeSpans: []*tracepb.ScopeSpans{scopeSpans},
		SchemaUrl:  "https://opentelemetry.io/schemas/1.24.0",
	}

	tracesData := &tracepb.TracesData{
		ResourceSpans: []*tracepb.ResourceSpans{resourceSpans},
	}

	// Assertion 1: TracesData represents OTLP trace payloads containing nested ResourceSpans, ScopeSpans, and Spans with associated attributes and status.
	{
		assert(len(tracesData.GetResourceSpans()) == 1, "expected 1 ResourceSpans")
		rs := tracesData.GetResourceSpans()[0]
		assert(rs.GetSchemaUrl() == "https://opentelemetry.io/schemas/1.24.0", "schema URL mismatch")
		assert(rs.GetResource() != nil, "expected non-nil resource")
		assert(len(rs.GetScopeSpans()) == 1, "expected 1 ScopeSpans")
		ss := rs.GetScopeSpans()[0]
		assert(ss.GetScope() != nil && ss.GetScope().GetName() == "db-instrumentation", "scope name mismatch")
		assert(len(ss.GetSpans()) == 1, "expected 1 Span")
		sp := ss.GetSpans()[0]
		assert(sp.GetName() == "execute-query", "span name mismatch")
		assert(sp.GetKind() == tracepb.Span_SPAN_KIND_SERVER, "span kind mismatch")
		assert(bytes.Equal(sp.GetTraceId(), traceID), "trace ID mismatch")
		assert(bytes.Equal(sp.GetSpanId(), spanID), "span ID mismatch")
		assert(sp.GetStatus() != nil && sp.GetStatus().GetCode() == tracepb.Status_STATUS_CODE_OK, "status code mismatch")
	}

	// Assertion 2: TracesData serializes to and deserializes from binary Protobuf wire format without data loss, satisfying proto.Equal.
	{
		wire, err := proto.Marshal(tracesData)
		assert(err == nil, "proto.Marshal failed")
		assert(len(wire) > 0, "marshaled wire length is 0")

		unmarshaled := &tracepb.TracesData{}
		err = proto.Unmarshal(wire, unmarshaled)
		assert(err == nil, "proto.Unmarshal failed")
		assert(proto.Equal(tracesData, unmarshaled), "proto.Equal returned false for protobuf round-trip")
	}

	// Assertion 3: TracesData serializes to and deserializes from protojson format, preserving field mappings such as resourceSpans.
	{
		jsonBytes, err := protojson.Marshal(tracesData)
		assert(err == nil, "protojson.Marshal failed")
		assert(bytes.Contains(jsonBytes, []byte(`"resourceSpans"`)), "expected json to contain 'resourceSpans' key")

		jsonUnmarshaled := &tracepb.TracesData{}
		err = protojson.Unmarshal(jsonBytes, jsonUnmarshaled)
		assert(err == nil, "protojson.Unmarshal failed")
		assert(proto.Equal(tracesData, jsonUnmarshaled), "proto.Equal returned false for protojson round-trip")
	}

	// Assertion 4: TracesData GetResourceSpans returns nil safely when called on nil or unpopulated instances.
	{
		var nilTraces *tracepb.TracesData
		assert(nilTraces.GetResourceSpans() == nil, "expected nil from typed-nil TracesData")

		emptyTraces := &tracepb.TracesData{}
		assert(emptyTraces.GetResourceSpans() == nil, "expected nil from empty TracesData")

		emptyWire, err := proto.Marshal(emptyTraces)
		assert(err == nil, "proto.Marshal failed on empty TracesData")
		assert(len(emptyWire) == 0, "expected 0 wire bytes for empty TracesData")
	}

	// Assertion 5: proto.Clone produces an isolated deep copy of TracesData where mutating repeated spans or nested attributes does not affect the original.
	{
		cloned := proto.Clone(tracesData).(*tracepb.TracesData)
		assert(proto.Equal(tracesData, cloned), "cloned message must equal original")

		// Mutate cloned fields
		cloned.ResourceSpans[0].Resource.Attributes[0].Value = &commonpb.AnyValue{
			Value: &commonpb.AnyValue_StringValue{StringValue: "mutated-service"},
		}
		cloned.ResourceSpans[0].ScopeSpans[0].Spans[0].Name = "mutated-span"
		cloned.ResourceSpans = append(cloned.ResourceSpans, &tracepb.ResourceSpans{})

		// Verify original remains untouched
		assert(tracesData.ResourceSpans[0].Resource.Attributes[0].Value.GetStringValue() == "query-service", "original resource attribute was mutated")
		assert(tracesData.ResourceSpans[0].ScopeSpans[0].Spans[0].GetName() == "execute-query", "original span name was mutated")
		assert(len(tracesData.ResourceSpans) == 1, "original resource spans length was modified")
	}

	fmt.Println("PASS: all trace/v1.TracesData contract assertions verified")
}

오리진 시더

익명