Skip to content
  •  
  •  
  •  
1 change: 0 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use_repo(
"com_github_go_sql_driver_mysql",
"com_github_google_go_containerregistry",
"com_github_google_go_containerregistry_pkg_authn_k8schain",
"com_github_lmittmann_tint",
"com_github_maypok86_otter",
"com_github_moby_buildkit",
"com_github_oapi_codegen_nullable",
Expand Down
10 changes: 10 additions & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"context"
"time"

"github.com/unkeyed/unkey/pkg/cli"
"github.com/unkeyed/unkey/pkg/clock"
Expand Down Expand Up @@ -111,6 +112,12 @@ var Cmd = &cli.Command{
cli.Int64("max-request-body-size", "Maximum allowed request body size in bytes. Set to 0 or negative to disable limit. Default: 10485760 (10MB)",
cli.Default(int64(10485760)), cli.EnvVar("UNKEY_MAX_REQUEST_BODY_SIZE")),

// Logging Sampler Configuration
cli.Float("log-sample-rate", "Baseline probability (0.0-1.0) of emitting log events. Default: 1.0",
cli.Default(1.0), cli.EnvVar("UNKEY_LOG_SAMPLE_RATE")),
cli.Duration("log-slow-threshold", "Duration threshold for slow event sampling. Default: 1s",
cli.Default(time.Second), cli.EnvVar("UNKEY_LOG_SLOW_THRESHOLD")),

// CTRL Service Configuration
cli.String("ctrl-url", "CTRL service connection URL for deployment management. Example: http://ctrl:7091",
cli.EnvVar("UNKEY_CTRL_URL")),
Expand Down Expand Up @@ -203,6 +210,9 @@ func action(ctx context.Context, cmd *cli.Command) error {
// Request body configuration
MaxRequestBodySize: cmd.Int64("max-request-body-size"),

// Logging sampler configuration
LogSampleRate: cmd.Float("log-sample-rate"),
LogSlowThreshold: cmd.Duration("log-slow-threshold"),
}

err := config.Validate()
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go_library(
"//cmd/deploy/internal/ui",
"//pkg/cli",
"//pkg/git",
"//pkg/otel/logging",
"//pkg/logger",
"@com_github_unkeyed_sdks_api_go_v2//:go",
"@com_github_unkeyed_sdks_api_go_v2//models/components",
"@org_golang_x_text//cases",
Expand Down
3 changes: 1 addition & 2 deletions cmd/deploy/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
unkey "github.com/unkeyed/sdks/api/go/v2"
"github.com/unkeyed/sdks/api/go/v2/models/components"
"github.com/unkeyed/unkey/pkg/git"
"github.com/unkeyed/unkey/pkg/otel/logging"
"github.com/unkeyed/unkey/pkg/logger"
)

// DeploymentStatusEvent represents a status change event
Expand Down Expand Up @@ -117,7 +117,6 @@ func (c *ControlPlaneClient) GetDeployment(ctx context.Context, deploymentID str
// PollDeploymentStatus polls for deployment changes and calls event handlers
func (c *ControlPlaneClient) PollDeploymentStatus(
ctx context.Context,
logger logging.Logger,
deploymentID string,
onStatusChange func(DeploymentStatusEvent) error,
) error {
Expand Down
4 changes: 1 addition & 3 deletions cmd/deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/unkeyed/unkey/cmd/deploy/internal/ui"
"github.com/unkeyed/unkey/pkg/cli"
"github.com/unkeyed/unkey/pkg/git"
"github.com/unkeyed/unkey/pkg/otel/logging"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down Expand Up @@ -103,7 +102,6 @@ func DeployAction(ctx context.Context, cmd *cli.Command) error {

func executeDeploy(ctx context.Context, opts DeployOptions) error {
terminal := ui.NewUI()
logger := logging.New()
gitInfo := git.GetInfo()

// Auto-detect branch and commit from git if not specified
Expand Down Expand Up @@ -151,7 +149,7 @@ func executeDeploy(ctx context.Context, opts DeployOptions) error {
}

// Poll for deployment completion
err = controlPlane.PollDeploymentStatus(ctx, logger, deploymentID, onStatusChange)
err = controlPlane.PollDeploymentStatus(ctx, deploymentID, onStatusChange)
if err != nil {
terminal.StopSpinner("Deployment failed", false)
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/dev/seed/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ go_library(
"//pkg/clickhouse/schema",
"//pkg/db",
"//pkg/db/types",
"//pkg/otel/logging",
"//pkg/logger",
"//pkg/uid",
],
)
6 changes: 1 addition & 5 deletions cmd/dev/seed/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/unkeyed/unkey/pkg/cli"
"github.com/unkeyed/unkey/pkg/db"
dbtype "github.com/unkeyed/unkey/pkg/db/types"
"github.com/unkeyed/unkey/pkg/otel/logging"
"github.com/unkeyed/unkey/pkg/logger"
"github.com/unkeyed/unkey/pkg/uid"
)

Expand All @@ -33,19 +33,15 @@ var localCmd = &cli.Command{
}

func seedLocal(ctx context.Context, cmd *cli.Command) error {
logger := logging.New()

database, err := db.New(db.Config{
PrimaryDSN: cmd.RequireString("database-primary"),
ReadOnlyDSN: "",
Logger: logger,
})
if err != nil {
return fmt.Errorf("failed to connect to MySQL: %w", err)
}

keyService, err := keys.New(keys.Config{
Logger: logger,
DB: database,
RateLimiter: nil,
RBAC: nil,
Expand Down
9 changes: 1 addition & 8 deletions cmd/dev/seed/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/unkeyed/unkey/pkg/clickhouse"
"github.com/unkeyed/unkey/pkg/clickhouse/schema"
"github.com/unkeyed/unkey/pkg/db"
"github.com/unkeyed/unkey/pkg/otel/logging"
"github.com/unkeyed/unkey/pkg/uid"
)

Expand All @@ -30,22 +29,18 @@ var sentinelCmd = &cli.Command{
}

func seedSentinel(ctx context.Context, cmd *cli.Command) error {
logger := logging.New()

// Connect to MySQL
database, err := db.New(db.Config{
PrimaryDSN: cmd.RequireString("database-primary"),
ReadOnlyDSN: "",
Logger: logger,
})
if err != nil {
return fmt.Errorf("failed to connect to MySQL: %w", err)
}

// Connect to ClickHouse
ch, err := clickhouse.New(clickhouse.Config{
URL: cmd.String("clickhouse-url"),
Logger: logger,
URL: cmd.String("clickhouse-url"),
})
if err != nil {
return fmt.Errorf("failed to connect to ClickHouse: %w", err)
Expand All @@ -67,7 +62,6 @@ func seedSentinel(ctx context.Context, cmd *cli.Command) error {
numRequests: cmd.RequireInt("num-requests"),
db: database,
clickhouse: ch,
logger: logger,
}

return seeder.Seed(ctx)
Expand All @@ -78,7 +72,6 @@ type SentinelSeeder struct {
numRequests int
db db.Database
clickhouse clickhouse.ClickHouse
logger logging.Logger
}

func (s *SentinelSeeder) Seed(ctx context.Context) error {
Expand Down
8 changes: 1 addition & 7 deletions cmd/dev/seed/verifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/unkeyed/unkey/pkg/clickhouse"
"github.com/unkeyed/unkey/pkg/clickhouse/schema"
"github.com/unkeyed/unkey/pkg/db"
"github.com/unkeyed/unkey/pkg/otel/logging"
"github.com/unkeyed/unkey/pkg/uid"
)

Expand All @@ -40,30 +39,25 @@ var verificationsCmd = &cli.Command{
const chunkSize = 50_000

func seedVerifications(ctx context.Context, cmd *cli.Command) error {
logger := logging.New()

// Connect to MySQL
database, err := db.New(db.Config{
PrimaryDSN: cmd.RequireString("database-primary"),
ReadOnlyDSN: "",
Logger: logger,
})
if err != nil {
return fmt.Errorf("failed to connect to MySQL: %w", err)
}

// Connect to ClickHouse
ch, err := clickhouse.New(clickhouse.Config{
URL: cmd.String("clickhouse-url"),
Logger: logger,
URL: cmd.String("clickhouse-url"),
})
if err != nil {
return fmt.Errorf("failed to connect to ClickHouse: %w", err)
}

// Create key service for proper key generation
keyService, err := keys.New(keys.Config{
Logger: logger,
DB: database,
RateLimiter: nil,
RBAC: nil,
Expand Down
11 changes: 11 additions & 0 deletions cmd/frontline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package frontline

import (
"context"
"time"

"github.com/unkeyed/unkey/pkg/cli"
"github.com/unkeyed/unkey/pkg/uid"
Expand Down Expand Up @@ -73,6 +74,12 @@ var Cmd = &cli.Command{

cli.String("ctrl-addr", "Address of the control plane",
cli.Default("localhost:8080"), cli.EnvVar("UNKEY_CTRL_ADDR")),

// Logging Sampler Configuration
cli.Float("log-sample-rate", "Baseline probability (0.0-1.0) of emitting log events. Default: 1.0",
cli.Default(1.0), cli.EnvVar("UNKEY_LOG_SAMPLE_RATE")),
cli.Duration("log-slow-threshold", "Duration threshold for slow event sampling. Default: 1s",
cli.Default(time.Second), cli.EnvVar("UNKEY_LOG_SLOW_THRESHOLD")),
},
Action: action,
}
Expand Down Expand Up @@ -110,6 +117,10 @@ func action(ctx context.Context, cmd *cli.Command) error {
// Vault configuration
VaultURL: cmd.String("vault-url"),
VaultToken: cmd.String("vault-token"),

// Logging sampler configuration
LogSampleRate: cmd.Float("log-sample-rate"),
LogSlowThreshold: cmd.Duration("log-slow-threshold"),
}

err := config.Validate()
Expand Down
2 changes: 1 addition & 1 deletion cmd/inject/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ go_library(
deps = [
"//pkg/assert",
"//pkg/cli",
"//pkg/otel/logging",
"//pkg/logger",
"//pkg/secrets/provider",
],
)
Expand Down
8 changes: 3 additions & 5 deletions cmd/inject/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"syscall"
"time"

"github.com/unkeyed/unkey/pkg/otel/logging"
"github.com/unkeyed/unkey/pkg/logger"
"github.com/unkeyed/unkey/pkg/secrets/provider"
)

Expand All @@ -19,8 +19,6 @@ func run(ctx context.Context, cfg config) error {
return fmt.Errorf("no command specified")
}

logger := logging.New()

// Clear sensitive UNKEY_* env vars first, before setting user secrets.
// This prevents leaking config like UNKEY_TOKEN to the child process,
// while allowing users to have secrets named UNKEY_* if they want.
Expand All @@ -46,7 +44,7 @@ func run(ctx context.Context, cfg config) error {
}
}

return execCommand(cfg.Args, logger)
return execCommand(cfg.Args)
}

func fetchSecrets(ctx context.Context, cfg config) (map[string]string, error) {
Expand Down Expand Up @@ -101,7 +99,7 @@ func clearSensitiveEnvVars() error {
return nil
}

func execCommand(args []string, logger logging.Logger) error {
func execCommand(args []string) error {
binary, err := exec.LookPath(args[0])
if err != nil {
return fmt.Errorf("command not found: %s: %w", args[0], err)
Expand Down
11 changes: 11 additions & 0 deletions cmd/krane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package krane

import (
"context"
"time"

"github.com/unkeyed/unkey/pkg/cli"
"github.com/unkeyed/unkey/pkg/uid"
Expand Down Expand Up @@ -88,6 +89,12 @@ unkey run krane # Run with default configurati
cli.Float("otel-trace-sampling-rate", "Sampling rate for traces (0.0 to 1.0)",
cli.Default(0.01),
cli.EnvVar("UNKEY_OTEL_TRACE_SAMPLING_RATE")),

// Logging Sampler Configuration
cli.Float("log-sample-rate", "Baseline probability (0.0-1.0) of emitting log events. Default: 1.0",
cli.Default(1.0), cli.EnvVar("UNKEY_LOG_SAMPLE_RATE")),
cli.Duration("log-slow-threshold", "Duration threshold for slow event sampling. Default: 1s",
cli.Default(time.Second), cli.EnvVar("UNKEY_LOG_SLOW_THRESHOLD")),
},
Action: action,
}
Expand All @@ -109,6 +116,10 @@ func action(ctx context.Context, cmd *cli.Command) error {
ControlPlaneBearer: cmd.RequireString("control-plane-bearer"),
OtelEnabled: cmd.Bool("otel-enabled"),
OtelTraceSamplingRate: cmd.Float("otel-trace-sampling-rate"),

// Logging sampler configuration
LogSampleRate: cmd.Float("log-sample-rate"),
LogSlowThreshold: cmd.Duration("log-slow-threshold"),
}

// Validate configuration
Expand Down
9 changes: 9 additions & 0 deletions cmd/preflight/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package preflight

import (
"context"
"time"

"github.com/unkeyed/unkey/pkg/cli"
"github.com/unkeyed/unkey/svc/preflight"
Expand Down Expand Up @@ -31,6 +32,11 @@ var Cmd = &cli.Command{
cli.EnvVar("UNKEY_INSECURE_REGISTRIES")),
cli.StringSlice("registry-aliases", "Comma-separated list of registry aliases (from=to)",
cli.EnvVar("UNKEY_REGISTRY_ALIASES")),
// Logging Sampler Configuration
cli.Float("log-sample-rate", "Baseline probability (0.0-1.0) of emitting log events. Default: 1.0",
cli.Default(1.0), cli.EnvVar("UNKEY_LOG_SAMPLE_RATE")),
cli.Duration("log-slow-threshold", "Duration threshold for slow event sampling. Default: 1s",
cli.Default(time.Second), cli.EnvVar("UNKEY_LOG_SLOW_THRESHOLD")),
},
Action: action,
}
Expand All @@ -46,6 +52,9 @@ func action(ctx context.Context, cmd *cli.Command) error {
DepotToken: cmd.String("depot-token"),
InsecureRegistries: cmd.StringSlice("insecure-registries"),
RegistryAliases: cmd.StringSlice("registry-aliases"),
// Logging sampler configuration
LogSampleRate: cmd.Float("log-sample-rate"),
LogSlowThreshold: cmd.Duration("log-slow-threshold"),
}

if err := config.Validate(); err != nil {
Expand Down
11 changes: 11 additions & 0 deletions cmd/sentinel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sentinel

import (
"context"
"time"

"github.com/unkeyed/unkey/pkg/cli"
"github.com/unkeyed/unkey/pkg/uid"
Expand Down Expand Up @@ -51,6 +52,12 @@ var Cmd = &cli.Command{
cli.Float("otel-trace-sampling-rate", "Sampling rate for OpenTelemetry traces (0.0-1.0). Default: 0.25",
cli.Default(0.25), cli.EnvVar("UNKEY_OTEL_TRACE_SAMPLING_RATE")),
cli.Int("prometheus-port", "Enable Prometheus /metrics endpoint on specified port. Set to 0 to disable.", cli.EnvVar("UNKEY_PROMETHEUS_PORT")),

// Logging Sampler Configuration
cli.Float("log-sample-rate", "Baseline probability (0.0-1.0) of emitting log events. Default: 1.0",
cli.Default(1.0), cli.EnvVar("UNKEY_LOG_SAMPLE_RATE")),
cli.Duration("log-slow-threshold", "Duration threshold for slow event sampling. Default: 1s",
cli.Default(time.Second), cli.EnvVar("UNKEY_LOG_SLOW_THRESHOLD")),
},
Action: action,
}
Expand All @@ -75,5 +82,9 @@ func action(ctx context.Context, cmd *cli.Command) error {
OtelEnabled: cmd.Bool("otel"),
OtelTraceSamplingRate: cmd.Float("otel-trace-sampling-rate"),
PrometheusPort: cmd.Int("prometheus-port"),

// Logging sampler configuration
LogSampleRate: cmd.Float("log-sample-rate"),
LogSlowThreshold: cmd.Duration("log-slow-threshold"),
})
}
Loading
Loading