CodeSampleX

Sample

go.opentelemetry.io/otel/sdk v1.36.0

Verified sample for golang go.opentelemetry.io/otel/sdk v1.36.0. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:482c43e797a8d515a5c32a1d792d3ecf926781191a7ed46708a669a83d65dc01

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0
Packages
Created
2026-10-10T16:09:14Z

Contract

  1. sdktrace.NewTracerProvider creates a valid TracerProvider configured with WithSyncer exporter and WithSampler
  2. Tracer creates a span with specified name and attributes that are recorded upon span.End
  3. ParentBased sampler honors remote unsampled parent contexts by dropping child spans
  4. ParentBased sampler honors remote sampled parent contexts by sampling child spans
  5. TracerProvider.Shutdown flushes recorded spans to the exporter and cleans up resources

Files

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

Download the source artifact (tar.gz)

Source

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 pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0

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:7bc1787b308027e8baf52d2f2fe857d3758d846fc244904e2a5a109138ce150d","contract":["sdktrace.NewTracerProvider creates a valid TracerProvider configured with WithSyncer exporter and WithSampler","Tracer creates a span with specified name and attributes that are recorded upon span.End","ParentBased sampler honors remote unsampled parent contexts by dropping child spans","ParentBased sampler honors remote sampled parent contexts by sampling child spans","TracerProvider.Shutdown flushes recorded spans to the exporter and cleans up resources"],"goal":"verify pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0"],"schemaVersion":1},"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/sdk@v1.36.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	go.opentelemetry.io/otel v1.36.0
	go.opentelemetry.io/otel/sdk v1.36.0
	go.opentelemetry.io/otel/trace v1.36.0
)

require (
	github.com/go-logr/logr v1.4.4 // indirect
	github.com/go-logr/stdr v1.2.2 // indirect
	github.com/google/uuid v1.6.0 // indirect
	go.opentelemetry.io/auto/sdk v1.1.0 // indirect
	go.opentelemetry.io/otel/metric v1.36.0 // indirect
	golang.org/x/sys v0.48.0 // indirect
)
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/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
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/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg=
go.opentelemetry.io/otel v1.36.0/go.mod h1:/TcFMXYjyRNh8khOAO9ybYkqaDBb/70aVwkNML4pP8E=
go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCREuTYufE=
go.opentelemetry.io/otel/metric v1.36.0/go.mod h1:zC7Ks+yeyJt4xig9DEw9kuUFe5C3zLbVjV2PzT6qzbs=
go.opentelemetry.io/otel/sdk v1.36.0 h1:b6SYIuLRs88ztox4EyrvRti80uXIFy+Sqzoh9kFULbs=
go.opentelemetry.io/otel/sdk v1.36.0/go.mod h1:+lC+mTgD+MUWfjJubi2vvXWcVxyr9rmlshZni72pXeY=
go.opentelemetry.io/otel/trace v1.36.0 h1:ahxWNuqZjpdiFAyrIoQ4GIiAIhxAunQR6MUoKrsNd4w=
go.opentelemetry.io/otel/trace v1.36.0/go.mod h1:gQ+OnDZzrybY4k4seLzPAWNwVBBVlF2szhehOBB/tGA=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
main.go
package main

import (
	"context"
	"fmt"
	"log"

	"go.opentelemetry.io/otel/attribute"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	"go.opentelemetry.io/otel/sdk/trace/tracetest"
)

func main() {
	ctx := context.Background()

	exporter := tracetest.NewInMemoryExporter()
	tp := sdktrace.NewTracerProvider(
		sdktrace.WithSyncer(exporter),
		sdktrace.WithSampler(sdktrace.AlwaysSample()),
	)
	defer func() {
		if err := tp.Shutdown(ctx); err != nil {
			log.Fatalf("failed to shut down TracerProvider: %v", err)
		}
	}()

	tr := tp.Tracer("sample-tracer")
	_, span := tr.Start(ctx, "sample-operation")
	span.SetAttributes(attribute.String("app.component", "main"))
	span.AddEvent("processing-started")
	span.End()

	spans := exporter.GetSpans()
	fmt.Printf("TracerProvider recorded and exported %d span(s)\n", len(spans))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.opentelemetry.io/otel/sdk@v1.36.0"
  ]
}
test/contract.go
package main

import (
	"context"
	"fmt"
	"os"

	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/codes"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	"go.opentelemetry.io/otel/sdk/trace/tracetest"
	oteltrace "go.opentelemetry.io/otel/trace"
)

func main() {
	ctx := context.Background()

	// Assertion 1: sdktrace.NewTracerProvider creates a valid TracerProvider configured with WithSyncer exporter and WithSampler.
	exporter := tracetest.NewInMemoryExporter()
	tp := sdktrace.NewTracerProvider(
		sdktrace.WithSyncer(exporter),
		sdktrace.WithSampler(sdktrace.AlwaysSample()),
	)
	if tp == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 1: expected non-nil TracerProvider\n")
		os.Exit(1)
	}

	tr := tp.Tracer("contract-tracer")
	if tr == nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 1: expected non-nil Tracer\n")
		os.Exit(1)
	}

	// Assertion 2: Tracer creates a span with specified name and attributes that are recorded upon span.End.
	_, span := tr.Start(ctx, "test-span", oteltrace.WithAttributes(attribute.String("env", "test")))
	span.SetStatus(codes.Ok, "success")
	span.AddEvent("event-marker")
	span.End()

	spans := exporter.GetSpans()
	if len(spans) != 1 {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2: expected 1 recorded span, got %d\n", len(spans))
		os.Exit(1)
	}
	if spans[0].Name != "test-span" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2: expected span name 'test-span', got %q\n", spans[0].Name)
		os.Exit(1)
	}
	hasEnvAttr := false
	for _, attr := range spans[0].Attributes {
		if attr.Key == "env" && attr.Value.AsString() == "test" {
			hasEnvAttr = true
			break
		}
	}
	if !hasEnvAttr {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2: expected span attribute env=test not found\n")
		os.Exit(1)
	}
	if len(spans[0].Events) != 1 || spans[0].Events[0].Name != "event-marker" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2: expected event 'event-marker' not recorded\n")
		os.Exit(1)
	}

	// Assertion 3: ParentBased sampler honors remote unsampled parent contexts by dropping child spans.
	parentExp := tracetest.NewInMemoryExporter()
	parentTP := sdktrace.NewTracerProvider(
		sdktrace.WithSyncer(parentExp),
		sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.AlwaysSample())),
	)
	parentTracer := parentTP.Tracer("parent-based-tracer")

	traceID, _ := oteltrace.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
	spanID, _ := oteltrace.SpanIDFromHex("00f067aa0ba902b7")
	remoteUnsampledCtx := oteltrace.NewSpanContext(oteltrace.SpanContextConfig{
		TraceID:    traceID,
		SpanID:     spanID,
		TraceFlags: 0,
		Remote:     true,
	})
	ctxWithRemoteUnsampled := oteltrace.ContextWithSpanContext(ctx, remoteUnsampledCtx)
	_, remoteChildSpan := parentTracer.Start(ctxWithRemoteUnsampled, "remote-unsampled-child")
	if remoteChildSpan.SpanContext().IsSampled() {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 3: remote unsampled child span was sampled, expected false\n")
		os.Exit(1)
	}
	remoteChildSpan.End()

	// Child span should not be exported because it was not sampled
	if len(parentExp.GetSpans()) != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 3: unsampled span was exported, expected 0 spans, got %d\n", len(parentExp.GetSpans()))
		os.Exit(1)
	}

	// Assertion 4: ParentBased sampler honors remote sampled parent contexts by sampling child spans.
	remoteSampledCtx := oteltrace.NewSpanContext(oteltrace.SpanContextConfig{
		TraceID:    traceID,
		SpanID:     spanID,
		TraceFlags: oteltrace.FlagsSampled,
		Remote:     true,
	})
	ctxWithRemoteSampled := oteltrace.ContextWithSpanContext(ctx, remoteSampledCtx)
	_, remoteSampledChild := parentTracer.Start(ctxWithRemoteSampled, "remote-sampled-child")
	if !remoteSampledChild.SpanContext().IsSampled() {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4: remote sampled child span was not sampled, expected true\n")
		os.Exit(1)
	}
	remoteSampledChild.End()

	parentSpans := parentExp.GetSpans()
	if len(parentSpans) != 1 || parentSpans[0].Name != "remote-sampled-child" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4: remote sampled child span was not exported\n")
		os.Exit(1)
	}

	// Assertion 5: TracerProvider.Shutdown flushes recorded spans to the exporter and cleans up resources.
	if err := parentTP.Shutdown(ctx); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 5: parentTP.Shutdown failed: %v\n", err)
		os.Exit(1)
	}
	if err := tp.Shutdown(ctx); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 5: tp.Shutdown failed: %v\n", err)
		os.Exit(1)
	}

	fmt.Println("PASS: all sdktrace contract assertions passed successfully.")
}

Origin Seeder

anonymous