kill protobuf from default build: OTLP exporter now behind -tags otlp

Pre: importing luxfi/trace pulled go.opentelemetry.io/proto/otlp/* which
transitively requires google.golang.org/protobuf — even when callers
used trace.Noop. Any pkg in the workspace that touched luxfi/vm/api or
luxfi/evm/api inherited 11MB of OTLP protobuf code it never executed.

Post: ZERO OTLP / ZERO protobuf in the default dep graph.

Files:
  - exporter_config.go (new, no build tag): ExporterConfig moved out
    of exporter_zap.go so every build configuration exposes the
    same Config type to callers.
  - exporter_noop.go (new, //go:build !grpc && !otlp): default-build
    newExporter returns errNoOTLPExporter — callers must set Type=Disabled
    (returns trace.Noop, no exporter constructed) or rebuild with
    -tags otlp.
  - exporter_zap.go (//go:build !grpc && otlp): existing OTLP/HTTP+protobuf
    exporter, now opt-in. Renamed conceptually but file name kept to
    avoid breaking external scripts that grep for it.

Verification:
    go list -deps ./... | grep -E 'protobuf|otlp'   → empty
    go build ./...                                  → ok
    go build -tags otlp ./...                       → ok

Per the project rule: ZAP internal, ZIP edge. The OTLP exporter is
strictly protobuf-on-the-wire — it stays behind -tags otlp where any
consumer can opt in.
This commit is contained in:
Hanzo AI
2026-05-21 00:44:42 -07:00
parent 1d90c08639
commit 90152815b7
3 changed files with 61 additions and 14 deletions
+21
View File
@@ -0,0 +1,21 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// ExporterConfig lives outside the tagged exporter files because every
// build configuration (default, -tags otlp, -tags grpc) needs to expose
// the same configuration type to callers.
package trace
type ExporterConfig struct {
Type ExporterType `json:"type"`
// Endpoint to send traces to. If empty, the default endpoint will be used.
Endpoint string `json:"endpoint"`
// Headers to send with traces
Headers map[string]string `json:"headers"`
// If true, don't use TLS
Insecure bool `json:"insecure"`
}
+34
View File
@@ -0,0 +1,34 @@
//go:build !grpc && !otlp
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Default build: no OTLP/protobuf exporter. Callers who want OTLP export
// must opt in with -tags otlp (HTTP+protobuf) or -tags grpc (legacy gRPC).
//
// With this file compiled, trace.New(Config{Type: Disabled}) returns
// trace.Noop and no go.opentelemetry.io/proto/otlp/* or
// google.golang.org/protobuf import is pulled into the binary.
package trace
import (
"errors"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
// errNoOTLPExporter is returned when a caller asks for a real exporter on
// a default (otlp-untagged) build. Rebuild with -tags otlp to enable
// OTLP/HTTP export, or set Config.ExporterConfig.Type = Disabled to use
// the noop tracer.
var errNoOTLPExporter = errors.New(
"trace: OTLP exporter not compiled (rebuild with -tags otlp or use ExporterConfig.Type=Disabled)",
)
// newExporter — default build returns an error. Callers should set
// Type=Disabled (which short-circuits before this is reached in
// trace.New) or rebuild with -tags otlp.
func newExporter(_ ExporterConfig) (sdktrace.SpanExporter, error) {
return nil, errNoOTLPExporter
}
+6 -14
View File
@@ -1,8 +1,13 @@
//go:build !grpc
//go:build !grpc && otlp
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// OTLP/HTTP+protobuf exporter. Compiled only with -tags otlp because it
// pulls go.opentelemetry.io/proto/otlp/* — which transitively requires
// google.golang.org/protobuf. Default builds use exporter_noop.go and
// have zero protobuf in the dep graph.
package trace
import (
@@ -27,19 +32,6 @@ import (
const tracerProviderExportCreationTimeout = 5 * time.Second
type ExporterConfig struct {
Type ExporterType `json:"type"`
// Endpoint to send traces to. If empty, the default endpoint will be used.
Endpoint string `json:"endpoint"`
// Headers to send with traces
Headers map[string]string `json:"headers"`
// If true, don't use TLS
Insecure bool `json:"insecure"`
}
func newExporter(config ExporterConfig) (sdktrace.SpanExporter, error) {
var client otlptrace.Client
switch config.Type {