Skip to content

[BUG]: ddtrace/tracer/internal: compile failure on GOARCH=386 (SpanAttributes size assertion) #4984

Description

@puni9869

Tracer Version(s)

v2.9.0

Go Version(s)

1.26.1

Bug Report

Description

Since v2.9.0, dd-trace-go/v2 fails to compile when targeting 32-bit architectures (GOARCH=386). The compile-time size assertion in ddtrace/tracer/internal/span_attributes.go hardcodes 56 bytes, which is only correct on 64-bit platforms.

Error

# github.com/DataDog/dd-trace-go/v2/ddtrace/tracer/internal
../../go/pkg/mod/github.com/!data!dog/dd-trace-go/v2@v2.9.1/ddtrace/tracer/internal/span_attributes.go:55:19: invalid argument: index 28 out of bounds [0:1]
../../go/pkg/mod/github.com/!data!dog/dd-trace-go/v2@v2.9.1/ddtrace/tracer/internal/span_attributes.go:56:19: unsafe.Sizeof(SpanAttributes{}) - 56 (constant -28 of type uintptr) overflows uintptr

Suggested Fix

Replace the hardcoded constant with something architecture-aware:

// Compile-time layout check: ensure no unexpected padding exists.
const expectedSize = unsafe.Offsetof(SpanAttributes{}.vals) + unsafe.Sizeof([numAttrs]string{})
var _ = [1]byte{}[expectedSize-unsafe.Sizeof(SpanAttributes{})]
var _ = [1]byte{}[unsafe.Sizeof(SpanAttributes{})-expectedSize]

Or simply remove the assertion since the struct layout doesn't have correctness implications that depend on an exact byte count.

Environment

  • Go: 1.26.1
  • dd-trace-go: v2.9.1
  • GOOS: windows
  • GOARCH: 386

Notes

The [README states](https://github.com/DataDog/dd-trace-go#go-support-policy): "This library only officially supports first class ports of Go." windows/386 and linux/386 are both first-class Go ports. The v2.9.0 release notes (PR #4538) do not mention dropping 32-bit support.

Reproduction Code

Reproduction

GOOS=windows GOARCH=386 CGO_ENABLED=0 go build ./...

Any project that imports dd-trace-go/v2 (directly or transitively) will fail to compile for 32-bit targets.

Error Logs

Root Cause

In span_attributes.go lines 55-56:

var _ = [1]byte{}[56-unsafe.Sizeof(SpanAttributes{})]
var _ = [1]byte{}[unsafe.Sizeof(SpanAttributes{})-56]

The struct layout comment says:

1B setMask + 1B readOnly + 6B padding + [3]string (48B) = 56B

On 64-bit, string = 16 bytes → [3]string = 48B → total = 56B ✓
On 32-bit, string = 8 bytes → [3]string = 24B → total = 28B ✗

The assertion should either:

  • Use a platform-aware expected size (e.g., unsafe.Sizeof(SpanAttributes{}) compared against a computed value), or
  • Be guarded with a build constraint (//go:build !386 && !arm)

Go Env Output

GOOS=windows GOARCH=386 CGO_ENABLED=0 go build ./...

Metadata

Metadata

Assignees

Labels

bugunintended behavior that has to be fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions