サンプル
go.opentelemetry.io/otel/trace v1.37.0: EventOption
検証済みサンプル — golang go.opentelemetry.io/otel/trace v1.37.0: EventOption. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.
sha256:8b9fc38c5ffac1f0a6c90c596f3d55eb5d1bb0f867299ae74c92b49f116b4f0b
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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-19 |
ケース
HOW- ゴール
- verify go.opentelemetry.io/otel/trace.EventOption in pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0
- シンボル
-
- go.opentelemetry.io/otel/trace.EventOption
- 作成日
- 2026-09-17T22:02:31Z
コントラクト
- NewEventConfig without options assigns a non-zero call timestamp, empty attributes, and false stack trace flag
- WithAttributes option applies attributes to EventConfig and multiple calls append in order without overwriting
- WithTimestamp option sets explicit timestamp on EventConfig
- WithStackTrace option sets stack trace capture flag on EventConfig
- Span AddEvent and RecordError accept EventOption options including WithAttributes, WithTimestamp, and WithStackTrace
ファイル
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.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/otel/trace.EventOption in pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0
Demonstrate these symbols/APIs:
- go.opentelemetry.io/otel/trace.EventOption
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:10f7465a36273e1ccdbf13f84822580efc2116acb73bc7b22b0efe863c4dcfca","contract":["NewEventConfig without options assigns a non-zero call timestamp, empty attributes, and false stack trace flag","WithAttributes option applies attributes to EventConfig and multiple calls append in order without overwriting","WithTimestamp option sets explicit timestamp on EventConfig","WithStackTrace option sets stack trace capture flag on EventConfig","Span AddEvent and RecordError accept EventOption options including WithAttributes, WithTimestamp, and WithStackTrace"],"goal":"verify go.opentelemetry.io/otel/trace.EventOption in pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/otel/trace.EventOption"]},"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/otel/trace@v1.37.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0","symbols":["go.opentelemetry.io/otel/trace.EventOption"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require (
go.opentelemetry.io/otel v1.37.0
go.opentelemetry.io/otel/trace v1.37.0
)
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=
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package main
import (
"context"
"fmt"
"time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func main() {
tp := trace.NewNoopTracerProvider()
tracer := tp.Tracer("event-sample")
_, span := tracer.Start(context.Background(), "sample-operation")
defer span.End()
eventTime := time.Now()
span.AddEvent("cache_lookup",
trace.WithTimestamp(eventTime),
trace.WithAttributes(
attribute.String("cache.key", "user:123"),
attribute.Bool("cache.hit", false),
),
)
sampleErr := fmt.Errorf("simulated failure")
span.RecordError(sampleErr,
trace.WithStackTrace(true),
trace.WithTimestamp(time.Now()),
trace.WithAttributes(attribute.String("error.severity", "warning")),
)
opts := []trace.EventOption{
trace.WithTimestamp(eventTime),
trace.WithAttributes(attribute.String("status", "ready")),
trace.WithStackTrace(false),
}
cfg := trace.NewEventConfig(opts...)
fmt.Printf("EventConfig timestamp: %v, stackTrace: %v, attributes: %d\n",
cfg.Timestamp(), cfg.StackTrace(), len(cfg.Attributes()))
}
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/otel/trace.EventOption in pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/otel/trace@v1.37.0"
],
"symbols": [
"go.opentelemetry.io/otel/trace.EventOption"
]
}
package main
import (
"context"
"fmt"
"os"
"time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func main() {
// Assertion 1: NewEventConfig without options assigns a non-zero call timestamp, empty attributes, and false stack trace flag
{
cfg := trace.NewEventConfig()
if cfg.Timestamp().IsZero() {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected non-zero timestamp\n")
os.Exit(1)
}
if len(cfg.Attributes()) != 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected 0 attributes, got %d\n", len(cfg.Attributes()))
os.Exit(1)
}
if cfg.StackTrace() {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected stackTrace to be false\n")
os.Exit(1)
}
}
// Assertion 2: WithAttributes option applies attributes to EventConfig and multiple calls append in order without overwriting
{
attr1 := attribute.String("env", "production")
attr2 := attribute.Int("code", 200)
attr3 := attribute.Bool("retryable", false)
cfg := trace.NewEventConfig(
trace.WithAttributes(attr1, attr2),
trace.WithAttributes(attr3),
)
attrs := cfg.Attributes()
if len(attrs) != 3 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 3 attributes, got %d\n", len(attrs))
os.Exit(1)
}
if attrs[0] != attr1 || attrs[1] != attr2 || attrs[2] != attr3 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: attributes mismatch: %+v\n", attrs)
os.Exit(1)
}
}
// Assertion 3: WithTimestamp option sets explicit timestamp on EventConfig
{
t1 := time.Date(2026, time.September, 17, 10, 0, 0, 0, time.UTC)
t2 := time.Date(2026, time.September, 17, 10, 5, 0, 0, time.UTC)
cfg1 := trace.NewEventConfig(trace.WithTimestamp(t1))
if !cfg1.Timestamp().Equal(t1) {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected %v, got %v\n", t1, cfg1.Timestamp())
os.Exit(1)
}
// Multiple calls overwrite with last-one-wins
cfg2 := trace.NewEventConfig(trace.WithTimestamp(t1), trace.WithTimestamp(t2))
if !cfg2.Timestamp().Equal(t2) {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected last timestamp %v, got %v\n", t2, cfg2.Timestamp())
os.Exit(1)
}
}
// Assertion 4: WithStackTrace option sets stack trace capture flag on EventConfig
{
cfgFalse := trace.NewEventConfig(trace.WithStackTrace(false))
if cfgFalse.StackTrace() {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected stackTrace false\n")
os.Exit(1)
}
cfgTrue := trace.NewEventConfig(trace.WithStackTrace(true))
if !cfgTrue.StackTrace() {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected stackTrace true\n")
os.Exit(1)
}
// Multiple calls overwrite with last-one-wins
cfgOverride := trace.NewEventConfig(trace.WithStackTrace(true), trace.WithStackTrace(false))
if cfgOverride.StackTrace() {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected stackTrace false after overwrite\n")
os.Exit(1)
}
}
// Assertion 5: Span AddEvent and RecordError accept EventOption options including WithAttributes, WithTimestamp, and WithStackTrace
{
tp := trace.NewNoopTracerProvider()
tracer := tp.Tracer("contract-tracer")
_, span := tracer.Start(context.Background(), "test-span")
defer span.End()
eventTime := time.Date(2026, time.September, 17, 11, 0, 0, 0, time.UTC)
eventOpts := []trace.EventOption{
trace.WithTimestamp(eventTime),
trace.WithAttributes(attribute.String("event.name", "checkpoint")),
}
span.AddEvent("checkpoint", eventOpts...)
errOpts := []trace.EventOption{
trace.WithTimestamp(eventTime),
trace.WithStackTrace(true),
trace.WithAttributes(attribute.String("error.type", "test_error")),
}
span.RecordError(fmt.Errorf("simulated contract error"), errOpts...)
}
fmt.Println("All EventOption contract assertions passed successfully.")
}
オリジンシーダー
匿名