Add tracing manifests and docs; clean up branch lint findings
Manager env block (downward-API resource attrs, commented OTLP examples), architecture §10 + Decisions entries, README section. Lint: goconst constants, gofmt, logcheck (Setup now takes its logger from ctx via logf.FromContext). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,24 +5,25 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"go.opentelemetry.io/otel"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace/noop"
|
||||
)
|
||||
|
||||
const testOTLPEndpoint = "http://localhost:4318"
|
||||
|
||||
// clearOTelEnv pins every env var Setup reads, so developer shells with
|
||||
// OTEL_* set can't change test outcomes. Not parallel-safe by design
|
||||
// (t.Setenv forbids t.Parallel).
|
||||
func clearOTelEnv(t *testing.T) {
|
||||
t.Helper()
|
||||
for _, k := range []string{
|
||||
"OTEL_SDK_DISABLED",
|
||||
"OTEL_TRACES_EXPORTER",
|
||||
"OTEL_EXPORTER_OTLP_ENDPOINT",
|
||||
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
||||
"OTEL_EXPORTER_OTLP_PROTOCOL",
|
||||
"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
|
||||
envSDKDisabled,
|
||||
envTracesExporter,
|
||||
envOTLPEndpoint,
|
||||
envOTLPTracesEndpoint,
|
||||
envOTLPProtocol,
|
||||
envOTLPTracesProtocol,
|
||||
} {
|
||||
t.Setenv(k, "")
|
||||
}
|
||||
@@ -38,50 +39,50 @@ func TestSetup_envGating(t *testing.T) {
|
||||
{name: "no env means disabled", env: nil, wantEnabled: false},
|
||||
{
|
||||
name: "endpoint enables otlp",
|
||||
env: map[string]string{"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4318"},
|
||||
env: map[string]string{envOTLPEndpoint: testOTLPEndpoint},
|
||||
wantEnabled: true,
|
||||
},
|
||||
{
|
||||
name: "traces endpoint enables otlp",
|
||||
env: map[string]string{"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "http://localhost:4318"},
|
||||
env: map[string]string{envOTLPTracesEndpoint: testOTLPEndpoint},
|
||||
wantEnabled: true,
|
||||
},
|
||||
{
|
||||
name: "explicit console exporter",
|
||||
env: map[string]string{"OTEL_TRACES_EXPORTER": "console"},
|
||||
env: map[string]string{envTracesExporter: exporterConsole},
|
||||
wantEnabled: true,
|
||||
},
|
||||
{
|
||||
name: "grpc protocol",
|
||||
env: map[string]string{"OTEL_TRACES_EXPORTER": "otlp", "OTEL_EXPORTER_OTLP_PROTOCOL": "grpc"},
|
||||
env: map[string]string{envTracesExporter: exporterOTLP, envOTLPProtocol: "grpc"},
|
||||
wantEnabled: true,
|
||||
},
|
||||
{
|
||||
name: "exporter none wins over endpoint",
|
||||
env: map[string]string{
|
||||
"OTEL_TRACES_EXPORTER": "none",
|
||||
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4318",
|
||||
envTracesExporter: exporterNone,
|
||||
envOTLPEndpoint: testOTLPEndpoint,
|
||||
},
|
||||
wantEnabled: false,
|
||||
},
|
||||
{
|
||||
name: "OTEL_SDK_DISABLED wins over everything",
|
||||
env: map[string]string{
|
||||
"OTEL_SDK_DISABLED": "true",
|
||||
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4318",
|
||||
envSDKDisabled: "true",
|
||||
envOTLPEndpoint: testOTLPEndpoint,
|
||||
},
|
||||
wantEnabled: false,
|
||||
},
|
||||
{
|
||||
name: "unsupported exporter errors",
|
||||
env: map[string]string{"OTEL_TRACES_EXPORTER": "jaeger"},
|
||||
env: map[string]string{envTracesExporter: "jaeger"},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "unsupported protocol errors",
|
||||
env: map[string]string{
|
||||
"OTEL_TRACES_EXPORTER": "otlp",
|
||||
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
|
||||
envTracesExporter: exporterOTLP,
|
||||
envOTLPProtocol: "http/json",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
@@ -100,7 +101,7 @@ func TestSetup_envGating(t *testing.T) {
|
||||
before := noop.NewTracerProvider()
|
||||
otel.SetTracerProvider(before)
|
||||
|
||||
shutdown, err := Setup(context.Background(), logr.Discard(), "test-svc", "abc123")
|
||||
shutdown, err := Setup(context.Background(), "test-svc", "abc123")
|
||||
if tc.wantErr {
|
||||
if err == nil {
|
||||
t.Fatal("want error, got nil")
|
||||
|
||||
Reference in New Issue
Block a user