mirror of
https://github.com/luxfi/trace.git
synced 2026-07-27 01:48:15 +00:00
The OTLP exporter was already gone from the code: exporter_default.go returns errLegacyOTLPDisabled and nothing imports an exporter package. go.mod still required otlptrace, otlptracegrpc, otlptracehttp, proto/otlp, protobuf and grpc, so every consumer of this module pulled gRPC and protobuf to reach code that cannot run. That is why 131 modules in the workspace list google.golang.org/grpc while none of their own source imports it. Those requires are gone. This module now builds with no OTLP, no protobuf and no gRPC in its graph at all. ExporterType follows: Disabled and ZAP, nothing else. Keeping GRPC and HTTP as values advertised transports that could not be constructed — ExporterTypeFromString would accept "grpc", and the exporter would then fail at use. It now refuses them at parse time, which is where a wrong config should be caught, and the tests assert the rejection rather than the old acceptance.
83 lines
1.7 KiB
Go
83 lines
1.7 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package trace
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Exporters this package can construct. ZAP is the transport; there is no
|
|
// other. gRPC, HTTP/protobuf and OTLP are not options here — a build of this
|
|
// package pulls none of them.
|
|
const (
|
|
Disabled ExporterType = iota
|
|
ZAP
|
|
)
|
|
|
|
var (
|
|
errUnknownExporterType = errors.New("unknown exporter type")
|
|
errMissingQuotes = errors.New("first and last characters should be quotes")
|
|
)
|
|
|
|
func ExporterTypeFromString(exporterTypeStr string) (ExporterType, error) {
|
|
switch strings.ToLower(exporterTypeStr) {
|
|
case "disabled":
|
|
return Disabled, nil
|
|
case "zap":
|
|
return ZAP, nil
|
|
default:
|
|
return 0, fmt.Errorf("%w: %q", errUnknownExporterType, exporterTypeStr)
|
|
}
|
|
}
|
|
|
|
type ExporterType byte
|
|
|
|
func (t ExporterType) MarshalJSON() ([]byte, error) {
|
|
str, ok := t.toString()
|
|
if !ok {
|
|
return nil, fmt.Errorf("%w: %d", errUnknownExporterType, t)
|
|
}
|
|
return []byte(`"` + str + `"`), nil
|
|
}
|
|
|
|
func (t *ExporterType) UnmarshalJSON(b []byte) error {
|
|
str := string(b)
|
|
if str == "null" { // If "null", do nothing
|
|
return nil
|
|
}
|
|
if len(str) < 2 {
|
|
return errMissingQuotes
|
|
}
|
|
|
|
lastIndex := len(str) - 1
|
|
if str[0] != '"' || str[lastIndex] != '"' {
|
|
return errMissingQuotes
|
|
}
|
|
|
|
exporterType, err := ExporterTypeFromString(str[1:lastIndex])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*t = exporterType
|
|
return nil
|
|
}
|
|
|
|
func (t ExporterType) String() string {
|
|
str, _ := t.toString()
|
|
return str
|
|
}
|
|
|
|
func (t ExporterType) toString() (string, bool) {
|
|
switch t {
|
|
case Disabled:
|
|
return "disabled", true
|
|
case ZAP:
|
|
return "zap", true
|
|
default:
|
|
return "unknown", false
|
|
}
|
|
}
|