CodeSampleX

샘플

go.opentelemetry.io/otel v1.37.0: attribute.Int

검증된 샘플 — golang go.opentelemetry.io/otel v1.37.0: attribute.Int. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: attribute.Int constructs a…

sha256:41a0ce718f9eb1a90ecb967f987c9038c6e332f007ece7e453aa78beb53ba938

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-16

케이스

HOW
목표
verify go.opentelemetry.io/otel/attribute.Int in pkg:golang/go.opentelemetry.io/otel@v1.37.0
패키지
심벌
  • go.opentelemetry.io/otel/attribute.Int
생성일
2026-09-16T16:28:36Z

컨트랙트

  1. attribute.Int constructs a KeyValue with specified Key and INT64 Value type
  2. attribute.Int with positive, zero, or negative integer values preserves the int64 representation
  3. attribute.IntValue creates an INT64 Value type emitting the integer string representation
  4. attribute.Int with empty key produces a KeyValue where key.Defined() and Valid() are false
  5. attribute.IntSlice constructs an INT64SLICE Value type containing converted int64 slice elements
  6. attribute.NewSet with attribute.Int KeyValues allows key lookup and value retrieval via HasValue and Value

파일

  • NOTES.md
  • PROMPT.md
  • attribute_int_test.go
  • csx.json
  • go.mod
  • go.sum
  • spec.json

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

소스

NOTES.md
# go.opentelemetry.io/otel - attribute.Int

## Search Result
`search_known_solution` answered `COMPATIBLE` for `go.opentelemetry.io/otel` and symbol `go.opentelemetry.io/otel/attribute.Int` (adapted and verified against v1.37.0).

## Release Pinned
- Package: `go.opentelemetry.io/otel`
- Version: `v1.37.0`

## Observed Behaviour
`attribute.Int` is a constructor in `go.opentelemetry.io/otel/attribute` that returns a `KeyValue` pairing a string key with an integer value represented as `INT64`:

1. **Type & Value Representation**:
   - `attribute.Int(k, v)` constructs a `KeyValue` where `kv.Key == attribute.Key(k)` and `kv.Value.Type() == attribute.INT64`.
   - The underlying integer value is cast to `int64` and retrieved via `kv.Value.AsInt64()`.
   - `attribute.IntValue(v)` returns a standalone `Value` of type `INT64` with string representation emitted via `.Emit()`.

2. **Validation**:
   - For valid non-empty keys, `kv.Valid()` returns `true` and `kv.Key.Defined()` returns `true`.
   - When given an empty key `""`, `kv.Key.Defined()` returns `false` and `kv.Valid()` returns `false`.

3. **Collections & Set Membership**:
   - `attribute.IntSlice(k, []int{...})` creates an `INT64SLICE` KeyValue with `AsInt64Slice()`.
   - `attribute.NewSet(...)` accepts `attribute.Int` KeyValues and supports membership querying via `set.HasValue(key)` and retrieval via `set.Value(key)`.
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/otel/attribute.Int in pkg:golang/go.opentelemetry.io/otel@v1.37.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.opentelemetry.io/otel@v1.37.0
Demonstrate these symbols/APIs:
  - go.opentelemetry.io/otel/attribute.Int

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.
attribute_int_test.go
package sample

import (
	"reflect"
	"testing"

	"go.opentelemetry.io/otel/attribute"
)

func TestAttributeInt(t *testing.T) {
	// 1. attribute.Int constructs a KeyValue with INT64 Value type and expected int64 value
	statusCodeKV := attribute.Int("http.status_code", 200)
	if statusCodeKV.Key != attribute.Key("http.status_code") {
		t.Fatalf("expected Key to be 'http.status_code', got %q", statusCodeKV.Key)
	}
	if statusCodeKV.Value.Type() != attribute.INT64 {
		t.Fatalf("expected Value.Type() to be INT64, got %v", statusCodeKV.Value.Type())
	}
	if statusCodeKV.Value.AsInt64() != 200 {
		t.Fatalf("expected Value.AsInt64() to be 200, got %d", statusCodeKV.Value.AsInt64())
	}
	if !statusCodeKV.Valid() {
		t.Fatalf("expected statusCodeKV.Valid() to be true")
	}

	// 2. Negative and zero int values are preserved as INT64
	zeroKV := attribute.Int("counter.zero", 0)
	if zeroKV.Value.AsInt64() != 0 {
		t.Fatalf("expected 0, got %d", zeroKV.Value.AsInt64())
	}
	negKV := attribute.Int("offset", -15)
	if negKV.Value.AsInt64() != -15 {
		t.Fatalf("expected -15, got %d", negKV.Value.AsInt64())
	}

	// 3. attribute.IntValue creates a standalone Value with INT64 type
	intValue := attribute.IntValue(42)
	if intValue.Type() != attribute.INT64 {
		t.Fatalf("expected intValue.Type() to be INT64, got %v", intValue.Type())
	}
	if intValue.AsInt64() != 42 {
		t.Fatalf("expected intValue.AsInt64() to be 42, got %d", intValue.AsInt64())
	}
	if intValue.Emit() != "42" {
		t.Fatalf("expected intValue.Emit() to be '42', got %q", intValue.Emit())
	}

	// 4. attribute.Int with empty key produces an invalid KeyValue
	emptyKeyKV := attribute.Int("", 500)
	if emptyKeyKV.Key.Defined() {
		t.Fatalf("expected empty key Defined() to be false")
	}
	if emptyKeyKV.Valid() {
		t.Fatalf("expected empty key KeyValue.Valid() to be false")
	}

	// 5. attribute.IntSlice converts []int into INT64SLICE Value type
	sliceKV := attribute.IntSlice("retry.delays", []int{10, 20, 30})
	if sliceKV.Value.Type() != attribute.INT64SLICE {
		t.Fatalf("expected sliceKV.Value.Type() to be INT64SLICE, got %v", sliceKV.Value.Type())
	}
	expectedSlice := []int64{10, 20, 30}
	if !reflect.DeepEqual(sliceKV.Value.AsInt64Slice(), expectedSlice) {
		t.Fatalf("expected %v, got %v", expectedSlice, sliceKV.Value.AsInt64Slice())
	}

	// 6. attribute.NewSet integration with attribute.Int KeyValues
	set := attribute.NewSet(
		statusCodeKV,
		attribute.Int("retry.attempts", 3),
	)
	if !set.HasValue(attribute.Key("http.status_code")) {
		t.Fatalf("expected set to have 'http.status_code'")
	}
	if val, ok := set.Value(attribute.Key("http.status_code")); !ok || val.AsInt64() != 200 {
		t.Fatalf("expected set.Value('http.status_code') to be 200, got %v (ok=%v)", val.AsInt64(), ok)
	}
	if val, ok := set.Value(attribute.Key("retry.attempts")); !ok || val.AsInt64() != 3 {
		t.Fatalf("expected set.Value('retry.attempts') to be 3, got %v (ok=%v)", val.AsInt64(), ok)
	}
	if set.HasValue(attribute.Key("nonexistent")) {
		t.Fatalf("expected set.HasValue('nonexistent') to be false")
	}
}
csx.json
{"case":{"caseId":"case:sha256:9d048f0da66cdfc500178459fa11dfc2940401b5ab9ee101c91f2b0d888ec53c","contract":["attribute.Int constructs a KeyValue with specified Key and INT64 Value type","attribute.Int with positive, zero, or negative integer values preserves the int64 representation","attribute.IntValue creates an INT64 Value type emitting the integer string representation","attribute.Int with empty key produces a KeyValue where key.Defined() and Valid() are false","attribute.IntSlice constructs an INT64SLICE Value type containing converted int64 slice elements","attribute.NewSet with attribute.Int KeyValues allows key lookup and value retrieval via HasValue and Value"],"goal":"verify go.opentelemetry.io/otel/attribute.Int in pkg:golang/go.opentelemetry.io/otel@v1.37.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel@v1.37.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/otel/attribute.Int"]},"contractCommand":["go","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/otel@v1.37.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel@v1.37.0","symbols":["go.opentelemetry.io/otel/attribute.Int"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.23.0

require go.opentelemetry.io/otel v1.37.0
go.sum
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify go.opentelemetry.io/otel/attribute.Int in pkg:golang/go.opentelemetry.io/otel@v1.37.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.opentelemetry.io/otel@v1.37.0"
  ],
  "symbols": [
    "go.opentelemetry.io/otel/attribute.Int"
  ]
}

오리진 시더

익명