CodeSampleX

Sample

go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0: WithWriter

Verified sample for golang go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0: WithWriter. The contract ran on go 1.26 · linux debian/x64 · docker…

sha256:3424768850be72b658b77160bcbc78735655248d26a823b919982a11c2d9e081

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
4
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 FAIL compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-08
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-08
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-08
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-08

Case

HOW
Goal
verify WithWriter in pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0
Packages
Symbols
  • WithWriter
Created
2026-09-07T14:13:10Z

Contract

  1. WithWriter returns an Option that configures the export stream destination for stdoutlog Exporter
  2. Exporter configured with WithWriter writes emitted log records to the designated io.Writer
  3. Exporter configured with WithWriter captures log attributes and body in JSON output format
  4. Exporter configured with WithWriter can be combined with other options such as WithoutTimestamps

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 WithWriter in pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0
Demonstrate these symbols/APIs:
  - WithWriter

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:72833144d8daf6550373858f3c775d4f18c648a23f37d0f0f34d2a202e35a267","contract":["WithWriter returns an Option that configures the export stream destination for stdoutlog Exporter","Exporter configured with WithWriter writes emitted log records to the designated io.Writer","Exporter configured with WithWriter captures log attributes and body in JSON output format","Exporter configured with WithWriter can be combined with other options such as WithoutTimestamps"],"goal":"verify WithWriter in pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0"],"schemaVersion":1,"symbols":["WithWriter"]},"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/exporters/stdout/stdoutlog@v0.19.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0","symbols":["WithWriter"],"verifierAdapter":"golang@1"}
go.mod
module example.com/stdoutlog-withwriter

go 1.26.6

require (
	github.com/cespare/xxhash/v2 v2.3.0 // indirect
	github.com/go-logr/logr v1.4.3 // indirect
	github.com/go-logr/stdr v1.2.2 // indirect
	github.com/google/uuid v1.6.0 // indirect
	go.opentelemetry.io/auto/sdk v1.2.1 // indirect
	go.opentelemetry.io/otel v1.43.0 // indirect
	go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0 // indirect
	go.opentelemetry.io/otel/log v0.19.0 // indirect
	go.opentelemetry.io/otel/metric v1.43.0 // indirect
	go.opentelemetry.io/otel/sdk v1.43.0 // indirect
	go.opentelemetry.io/otel/sdk/log v0.19.0 // indirect
	go.opentelemetry.io/otel/trace v1.43.0 // indirect
	golang.org/x/sys v0.42.0 // indirect
)
go.sum
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/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/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/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0 h1:GJkybS+crDMdExT/BUNCEgfrmfboztcS6PhvSo88HKM=
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.19.0/go.mod h1:NuAyxRYIG2lKX3YQkB+83StTxM7s52PUUkRRiC0wnYI=
go.opentelemetry.io/otel/log v0.19.0 h1:KUZs/GOsw79TBBMfDWsXS+KZ4g2Ckzksd1ymzsIEbo4=
go.opentelemetry.io/otel/log v0.19.0/go.mod h1:5DQYeGmxVIr4n0/BcJvF4upsraHjg6vudJJpnkL6Ipk=
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
go.opentelemetry.io/otel/sdk/log v0.19.0 h1:scYVLqT22D2gqXItnWiocLUKGH9yvkkeql5dBDiXyko=
go.opentelemetry.io/otel/sdk/log v0.19.0/go.mod h1:vFBowwXGLlW9AvpuF7bMgnNI95LiW10szrOdvzBHlAg=
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
main.go
package main

import (
	"bytes"
	"context"
	"fmt"

	"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
	otellog "go.opentelemetry.io/otel/log"
	sdklog "go.opentelemetry.io/otel/sdk/log"
)

func main() {
	var buf bytes.Buffer

	// Configure stdoutlog exporter with a custom writer destination
	exporter, err := stdoutlog.New(stdoutlog.WithWriter(&buf))
	if err != nil {
		panic(fmt.Sprintf("failed to create stdoutlog exporter: %v", err))
	}

	ctx := context.Background()
	processor := sdklog.NewSimpleProcessor(exporter)
	provider := sdklog.NewLoggerProvider(sdklog.WithProcessor(processor))
	defer func() {
		if err := provider.Shutdown(ctx); err != nil {
			panic(fmt.Sprintf("failed to shutdown provider: %v", err))
		}
	}()

	logger := provider.Logger("example-logger")

	var record otellog.Record
	record.SetBody(otellog.StringValue("hello from stdoutlog exporter"))
	record.SetSeverity(otellog.SeverityInfo)
	record.SetSeverityText("INFO")
	record.AddAttributes(otellog.String("app.name", "demo-service"))

	logger.Emit(ctx, record)

	fmt.Print(buf.String())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify WithWriter in pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.opentelemetry.io/otel/exporters/stdout/stdoutlog@v0.19.0"
  ],
  "symbols": [
    "WithWriter"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"os"
	"strings"

	"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
	otellog "go.opentelemetry.io/otel/log"
	sdklog "go.opentelemetry.io/otel/sdk/log"
)

func main() {
	// Assertion 1: WithWriter returns an Option that configures the export stream destination for stdoutlog Exporter
	{
		var buf bytes.Buffer
		opt := stdoutlog.WithWriter(&buf)
		if opt == nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected non-nil Option from WithWriter\n")
			os.Exit(1)
		}

		exp, err := stdoutlog.New(opt)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected no error creating exporter with WithWriter, got: %v\n", err)
			os.Exit(1)
		}
		if exp == nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected non-nil exporter\n")
			os.Exit(1)
		}
	}

	// Assertion 2: Exporter configured with WithWriter writes emitted log records to the designated io.Writer
	{
		var buf bytes.Buffer
		exp, err := stdoutlog.New(stdoutlog.WithWriter(&buf))
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: %v\n", err)
			os.Exit(1)
		}

		ctx := context.Background()
		proc := sdklog.NewSimpleProcessor(exp)
		lp := sdklog.NewLoggerProvider(sdklog.WithProcessor(proc))

		logger := lp.Logger("contract-logger")
		var rec otellog.Record
		rec.SetBody(otellog.StringValue("contract verification event"))
		logger.Emit(ctx, rec)

		if err := lp.Shutdown(ctx); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed on shutdown: %v\n", err)
			os.Exit(1)
		}

		output := buf.String()
		if len(output) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected non-empty output in writer\n")
			os.Exit(1)
		}
		if !strings.Contains(output, "contract verification event") {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: output did not contain emitted body\n")
			os.Exit(1)
		}
	}

	// Assertion 3: Exporter configured with WithWriter captures log attributes and body in JSON output format
	{
		var buf bytes.Buffer
		exp, err := stdoutlog.New(stdoutlog.WithWriter(&buf))
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: %v\n", err)
			os.Exit(1)
		}

		ctx := context.Background()
		proc := sdklog.NewSimpleProcessor(exp)
		lp := sdklog.NewLoggerProvider(sdklog.WithProcessor(proc))

		logger := lp.Logger("contract-json-logger")
		var rec otellog.Record
		rec.SetSeverity(otellog.SeverityWarn)
		rec.SetSeverityText("WARN")
		rec.SetBody(otellog.StringValue("payload-content"))
		rec.AddAttributes(otellog.String("custom.key", "custom.value"))
		logger.Emit(ctx, rec)
		_ = lp.Shutdown(ctx)

		var parsed map[string]any
		if err := json.Unmarshal(buf.Bytes(), &parsed); err != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: output is not valid JSON: %v, raw: %s\n", err, buf.String())
			os.Exit(1)
		}

		rawJSON := buf.String()
		if !strings.Contains(rawJSON, "custom.key") || !strings.Contains(rawJSON, "custom.value") {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: output missing custom attribute: %s\n", rawJSON)
			os.Exit(1)
		}
		if !strings.Contains(rawJSON, "payload-content") {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: output missing body: %s\n", rawJSON)
			os.Exit(1)
		}
	}

	// Assertion 4: Exporter configured with WithWriter can be combined with other options such as WithoutTimestamps
	{
		var buf bytes.Buffer
		exp, err := stdoutlog.New(
			stdoutlog.WithWriter(&buf),
			stdoutlog.WithoutTimestamps(),
		)
		if err != nil {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: %v\n", err)
			os.Exit(1)
		}

		ctx := context.Background()
		proc := sdklog.NewSimpleProcessor(exp)
		lp := sdklog.NewLoggerProvider(sdklog.WithProcessor(proc))

		logger := lp.Logger("contract-options-logger")
		var rec otellog.Record
		rec.SetBody(otellog.StringValue("no timestamps check"))
		logger.Emit(ctx, rec)
		_ = lp.Shutdown(ctx)

		out := buf.String()
		if !strings.Contains(out, "no timestamps check") {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: output missing body\n")
			os.Exit(1)
		}
		if strings.Contains(out, `"Timestamp"`) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: output should not contain Timestamp field when WithoutTimestamps is used, got: %s\n", out)
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

Origin Seeder

anonymous