feat: add well known for user lookup
This commit is contained in:
@@ -3,6 +3,7 @@ package logz
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
@@ -31,3 +32,11 @@ func Init(ctx context.Context, name string) (context.Context, func() error) {
|
||||
return multierr.Combine(errs...)
|
||||
}
|
||||
}
|
||||
|
||||
func env(name, defaultValue string) string {
|
||||
if v := os.Getenv(name); v != "" {
|
||||
log.Println("# ", name, " = ", v)
|
||||
return v
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ import (
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
// metricsExporter "github.com/logzio/go-metrics-sdk"
|
||||
"go.opentelemetry.io/contrib/instrumentation/runtime"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/exporters/prometheus"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/global"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/basic"
|
||||
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
|
||||
"go.opentelemetry.io/otel/sdk/metric/export/aggregation"
|
||||
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||
@@ -61,7 +59,7 @@ func initMetrics(ctx context.Context, name string) (context.Context, func() erro
|
||||
aggregation.CumulativeTemporalitySelector(),
|
||||
processor.WithMemory(true),
|
||||
),
|
||||
basic.WithResource(
|
||||
controller.WithResource(
|
||||
resource.NewWithAttributes(
|
||||
semconv.SchemaURL,
|
||||
attribute.String("app", name),
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -54,6 +53,13 @@ func Span(ctx context.Context, opts ...trace.SpanStartOption) (context.Context,
|
||||
return ctx, span
|
||||
}
|
||||
|
||||
type SampleRate string
|
||||
|
||||
const (
|
||||
SampleAlways SampleRate = "always"
|
||||
SampleNever SampleRate = "never"
|
||||
)
|
||||
|
||||
func initTracing(ctx context.Context, name string) (context.Context, func() error) {
|
||||
res, err := resource.New(ctx,
|
||||
resource.WithAttributes(
|
||||
@@ -76,15 +82,15 @@ func initTracing(ctx context.Context, name string) (context.Context, func() erro
|
||||
bsp := sdktrace.NewBatchSpanProcessor(traceExporter)
|
||||
|
||||
var sample sdktrace.TracerProviderOption
|
||||
sampleRate := env("LOGZIO_TRACE_SAMPLE", "always")
|
||||
sampleRate := SampleRate(env("EV_TRACE_SAMPLE", string(SampleNever)))
|
||||
switch sampleRate {
|
||||
case "always":
|
||||
sample = sdktrace.WithSampler(sdktrace.AlwaysSample())
|
||||
case "never":
|
||||
sample = sdktrace.WithSampler(sdktrace.NeverSample())
|
||||
default:
|
||||
if v, err := strconv.Atoi(sampleRate); err != nil {
|
||||
sample = sdktrace.WithSampler(sdktrace.AlwaysSample())
|
||||
if v, err := strconv.Atoi(string(sampleRate)); err != nil {
|
||||
sample = sdktrace.WithSampler(sdktrace.NeverSample())
|
||||
} else {
|
||||
sample = sdktrace.WithSampler(sdktrace.TraceIDRatioBased(float64(v) * 0.01))
|
||||
}
|
||||
@@ -122,13 +128,6 @@ func reverse[T any](s []T) {
|
||||
last--
|
||||
}
|
||||
}
|
||||
func env(name, defaultValue string) string {
|
||||
if v := os.Getenv(name); v != "" {
|
||||
log.Println("# ", name, " = ", v)
|
||||
return v
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func Htrace(h http.Handler, name string) http.Handler {
|
||||
return otelhttp.NewHandler(h, name)
|
||||
|
||||
Reference in New Issue
Block a user