示例
go.opentelemetry.io/otel/trace v1.39.0: Link
已验证示例 — golang go.opentelemetry.io/otel/trace v1.39.0: Link. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: Link struct encapsulates a SpanContext…
sha256:032895cfa138bc57a9b1a71c2606a798b7bbd8ce3e6b0f19ce4790a4c0e6f0cd
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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-10-10 |
案例
HOW- 目标
- verify go.opentelemetry.io/otel/trace.Link in pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0
- 符号
-
- go.opentelemetry.io/otel/trace.Link
- 创建时间
- 2026-10-10T23:23:47Z
契约
- Link struct encapsulates a SpanContext and optional key-value Attributes identifying related spans
- LinkFromContext extracts the SpanContext from a valid context and attaches provided attributes to the resulting Link
- LinkFromContext with an empty or untraced context produces a Link with an invalid SpanContext
- WithLinks creates a SpanStartOption that configures links on a SpanConfig retrievable via Links()
- WithLinks options accumulate cumulatively when multiple WithLinks options are provided to NewSpanStartConfig
文件
- 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.Link in pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0
Demonstrate these symbols/APIs:
- go.opentelemetry.io/otel/trace.Link
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:0035516f5c8b299fe8b4671e37a286b26ec719c3154082bd725dc56ddf2f5840","contract":["Link struct encapsulates a SpanContext and optional key-value Attributes identifying related spans","LinkFromContext extracts the SpanContext from a valid context and attaches provided attributes to the resulting Link","LinkFromContext with an empty or untraced context produces a Link with an invalid SpanContext","WithLinks creates a SpanStartOption that configures links on a SpanConfig retrievable via Links()","WithLinks options accumulate cumulatively when multiple WithLinks options are provided to NewSpanStartConfig"],"goal":"verify go.opentelemetry.io/otel/trace.Link in pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/otel/trace.Link"]},"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.39.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0","symbols":["go.opentelemetry.io/otel/trace.Link"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require (
go.opentelemetry.io/otel v1.39.0
go.opentelemetry.io/otel/trace v1.39.0
)
require github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
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.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48=
go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
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"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func main() {
traceID, err := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
if err != nil {
panic(err)
}
spanID, err := trace.SpanIDFromHex("00f067aa0ba902b7")
if err != nil {
panic(err)
}
sc := trace.NewSpanContext(trace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.FlagsSampled,
Remote: true,
})
// Create Link directly
link := trace.Link{
SpanContext: sc,
Attributes: []attribute.KeyValue{
attribute.String("link.role", "batch-parent"),
},
}
fmt.Printf("Link: valid=%v, traceID=%s, attrs=%d\n",
link.SpanContext.IsValid(), link.SpanContext.TraceID(), len(link.Attributes))
// Create Link from context
ctx := trace.ContextWithRemoteSpanContext(context.Background(), sc)
linkFromCtx := trace.LinkFromContext(ctx, attribute.String("rpc.system", "grpc"))
fmt.Printf("LinkFromContext: valid=%v, traceID=%s, attrs=%d\n",
linkFromCtx.SpanContext.IsValid(), linkFromCtx.SpanContext.TraceID(), len(linkFromCtx.Attributes))
// Configure Span with links using WithLinks
cfg := trace.NewSpanStartConfig(trace.WithLinks(link, linkFromCtx))
fmt.Printf("SpanConfig links count: %d\n", len(cfg.Links()))
}
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/otel/trace.Link in pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/otel/trace@v1.39.0"
],
"symbols": [
"go.opentelemetry.io/otel/trace.Link"
]
}
package main
import (
"context"
"fmt"
"os"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func main() {
traceID, err := trace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: TraceIDFromHex failed: %v\n", err)
os.Exit(1)
}
spanID, err := trace.SpanIDFromHex("00f067aa0ba902b7")
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: SpanIDFromHex failed: %v\n", err)
os.Exit(1)
}
sc := trace.NewSpanContext(trace.SpanContextConfig{
TraceID: traceID,
SpanID: spanID,
TraceFlags: trace.FlagsSampled,
Remote: true,
})
// Assertion 1: Link struct encapsulates a SpanContext and optional key-value Attributes identifying related spans
attr := attribute.String("link.role", "batch-parent")
link := trace.Link{
SpanContext: sc,
Attributes: []attribute.KeyValue{attr},
}
if !link.SpanContext.IsValid() {
fmt.Fprintf(os.Stderr, "FAIL: link.SpanContext must be valid\n")
os.Exit(1)
}
if link.SpanContext.TraceID() != traceID {
fmt.Fprintf(os.Stderr, "FAIL: link TraceID mismatch: expected %v, got %v\n", traceID, link.SpanContext.TraceID())
os.Exit(1)
}
if link.SpanContext.SpanID() != spanID {
fmt.Fprintf(os.Stderr, "FAIL: link SpanID mismatch: expected %v, got %v\n", spanID, link.SpanContext.SpanID())
os.Exit(1)
}
if len(link.Attributes) != 1 {
fmt.Fprintf(os.Stderr, "FAIL: expected 1 attribute, got %d\n", len(link.Attributes))
os.Exit(1)
}
if link.Attributes[0].Key != attribute.Key("link.role") || link.Attributes[0].Value.AsString() != "batch-parent" {
fmt.Fprintf(os.Stderr, "FAIL: attribute key/value mismatch\n")
os.Exit(1)
}
// Assertion 2: LinkFromContext extracts the SpanContext from a valid context and attaches provided attributes to the resulting Link
ctx := trace.ContextWithRemoteSpanContext(context.Background(), sc)
linkFromCtx := trace.LinkFromContext(ctx, attribute.String("rpc.system", "grpc"), attribute.Int("batch.index", 3))
if !linkFromCtx.SpanContext.IsValid() {
fmt.Fprintf(os.Stderr, "FAIL: linkFromCtx.SpanContext must be valid\n")
os.Exit(1)
}
if !linkFromCtx.SpanContext.Equal(sc) {
fmt.Fprintf(os.Stderr, "FAIL: linkFromCtx.SpanContext must equal injected SpanContext\n")
os.Exit(1)
}
if len(linkFromCtx.Attributes) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected 2 attributes on linkFromCtx, got %d\n", len(linkFromCtx.Attributes))
os.Exit(1)
}
if linkFromCtx.Attributes[0].Key != attribute.Key("rpc.system") || linkFromCtx.Attributes[0].Value.AsString() != "grpc" {
fmt.Fprintf(os.Stderr, "FAIL: first attribute mismatch\n")
os.Exit(1)
}
if linkFromCtx.Attributes[1].Key != attribute.Key("batch.index") || linkFromCtx.Attributes[1].Value.AsInt64() != 3 {
fmt.Fprintf(os.Stderr, "FAIL: second attribute mismatch\n")
os.Exit(1)
}
// Assertion 3: LinkFromContext with an empty or untraced context produces a Link with an invalid SpanContext
emptyLink := trace.LinkFromContext(context.Background())
if emptyLink.SpanContext.IsValid() {
fmt.Fprintf(os.Stderr, "FAIL: emptyLink SpanContext must be invalid\n")
os.Exit(1)
}
if emptyLink.SpanContext.HasTraceID() || emptyLink.SpanContext.HasSpanID() {
fmt.Fprintf(os.Stderr, "FAIL: emptyLink SpanContext must not have TraceID or SpanID\n")
os.Exit(1)
}
if len(emptyLink.Attributes) != 0 {
fmt.Fprintf(os.Stderr, "FAIL: emptyLink must have 0 attributes\n")
os.Exit(1)
}
// Assertion 4: WithLinks creates a SpanStartOption that configures links on a SpanConfig retrievable via Links()
cfg := trace.NewSpanStartConfig(trace.WithLinks(link, linkFromCtx))
links := cfg.Links()
if len(links) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected 2 links in SpanConfig, got %d\n", len(links))
os.Exit(1)
}
if !links[0].SpanContext.Equal(link.SpanContext) {
fmt.Fprintf(os.Stderr, "FAIL: links[0] SpanContext mismatch\n")
os.Exit(1)
}
if !links[1].SpanContext.Equal(linkFromCtx.SpanContext) {
fmt.Fprintf(os.Stderr, "FAIL: links[1] SpanContext mismatch\n")
os.Exit(1)
}
// Assertion 5: WithLinks options accumulate cumulatively when multiple WithLinks options are provided to NewSpanStartConfig
cfgAppended := trace.NewSpanStartConfig(trace.WithLinks(link), trace.WithLinks(linkFromCtx))
appendedLinks := cfgAppended.Links()
if len(appendedLinks) != 2 {
fmt.Fprintf(os.Stderr, "FAIL: expected 2 accumulated links, got %d\n", len(appendedLinks))
os.Exit(1)
}
if !appendedLinks[0].SpanContext.Equal(link.SpanContext) || !appendedLinks[1].SpanContext.Equal(linkFromCtx.SpanContext) {
fmt.Fprintf(os.Stderr, "FAIL: accumulated links order or SpanContext mismatch\n")
os.Exit(1)
}
fmt.Println("PASS: all trace.Link contract assertions passed.")
}
原始种子者
匿名