Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ opinionated, batteries-included service SDK.
Run your application with [`cloudrunner.Run`](./run.go), and you get:

- Logging integrated with [Cloud Logging](https://cloud.google.com/logging)
using [Zap](https://go.uber.org/zap).
using [slog](https://pkg.go.dev/log/slog).
- Tracing integrated with [Cloud Trace](https://cloud.google.com/trace)
using[OpenTelemetry Go](https://go.opentelemetry.io/otel).
- Metrics integrated with
Expand Down Expand Up @@ -41,6 +41,7 @@ package main
import (
"context"
"log"
"log/slog"

"go.einride.tech/cloudrunner"
"google.golang.org/grpc/health"
Expand All @@ -49,7 +50,7 @@ import (

func main() {
if err := cloudrunner.Run(func(ctx context.Context) error {
cloudrunner.Logger(ctx).Info("hello world")
slog.InfoContext(ctx, "hello world")
grpcServer := cloudrunner.NewGRPCServer(ctx)
healthServer := health.NewServer()
grpc_health_v1.RegisterHealthServer(grpcServer, healthServer)
Expand Down Expand Up @@ -100,8 +101,10 @@ cloudrunner GOOGLE_CLOUD_PROJECT string
cloudrunner RUNTIME_SERVICEACCOUNT string
cloudrunner SERVICE_VERSION string
cloudrunner ENABLE_PUBSUB_TRACING bool
cloudrunner LOGGER_PROJECTID string
cloudrunner LOGGER_DEVELOPMENT bool true false
cloudrunner LOGGER_LEVEL zapcore.Level debug info
cloudrunner LOGGER_LEVEL slog.Level debug info
cloudrunner LOGGER_PROTOMESSAGESIZELIMIT int 1024
cloudrunner LOGGER_REPORTERRORS bool true
cloudrunner PROFILER_ENABLED bool true
cloudrunner PROFILER_MUTEXPROFILING bool
Expand Down
9 changes: 0 additions & 9 deletions cloudotel/errorhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ import (
"log/slog"

"go.opentelemetry.io/otel"
"go.uber.org/zap" //nolint:gomodguard // legacy zap dependency for backwards compatibility
"go.uber.org/zap/zapcore" //nolint:gomodguard // legacy zap dependency for backwards compatibility
)

// NewErrorLogger returns a new otel.ErrorHandler that logs errors using the provided logger, level and message.
//
// Deprecated: This is a no-op as part of the migration from zap to slog.
func NewErrorLogger(*zap.Logger, zapcore.Level, string) otel.ErrorHandler {
return otel.ErrorHandlerFunc(func(error) {})
}

// RegisterErrorHandler registers a global OpenTelemetry error handler.
func RegisterErrorHandler(ctx context.Context) {
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
Expand Down
17 changes: 2 additions & 15 deletions cloudotel/tracemiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
gcppropagator "github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator"
"go.einride.tech/cloudrunner/cloudpubsub"
"go.einride.tech/cloudrunner/cloudstream"
"go.einride.tech/cloudrunner/cloudzap" //nolint:staticcheck // SA1019: internal use of deprecated package pending removal
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap" //nolint:gomodguard // legacy zap dependency for trace middleware
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
Expand Down Expand Up @@ -131,19 +129,8 @@ func (i *TraceMiddleware) withLogTracing(ctx context.Context, spanCtx trace.Span
if i.TraceHook != nil {
ctx = i.TraceHook(ctx, spanCtx)
}
fields := make([]zap.Field, 0, 3)
//nolint:staticcheck // SA1019: deprecated, pending removal
fields = append(fields, cloudzap.Trace(spanCtx.TraceID().String()))
if spanCtx.SpanID().String() != "" {
//nolint:staticcheck // SA1019: deprecated, pending removal
fields = append(fields, cloudzap.SpanID(spanCtx.SpanID().String()))
}
if spanCtx.IsSampled() {
//nolint:staticcheck // SA1019: deprecated, pending removal
fields = append(fields, cloudzap.TraceSampled(spanCtx.IsSampled()))
}
//nolint:staticcheck // SA1019: deprecated, pending removal
return cloudzap.WithLoggerFields(ctx, fields...)
// Trace fields are automatically added by the slog handler from the span context
return ctx
}

func propagatePubsubTracing(ctx context.Context, r *http.Request) context.Context {
Expand Down
4 changes: 0 additions & 4 deletions cloudrequestlog/additionalfields.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"log/slog"
"sync"

"go.uber.org/zap/zapcore" //nolint:gomodguard // cloudrequestlog uses zap for legacy request logging
)

type additionalFieldsKey struct{}
Expand Down Expand Up @@ -88,8 +86,6 @@ func argsToAttr(args []any) (slog.Attr, []any) {
return slog.String(badKey, x), nil
}
return slog.Any(x, args[1]), args[2:]
case zapcore.Field:
return fieldToAttr(x), args[1:]
case slog.Attr:
return x, args[1:]
default:
Expand Down
35 changes: 10 additions & 25 deletions cloudrequestlog/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,31 @@ package cloudrequestlog

import (
"encoding/json"
"log/slog"

"go.uber.org/zap" //nolint:gomodguard // cloudrequestlog uses zap for legacy request logging
"go.uber.org/zap/zapcore" //nolint:gomodguard // cloudrequestlog uses zap for legacy request logging
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

// ErrorDetails creates a zap.Field that logs the gRPC error details of the provided error.
//
// Deprecated: Returns a zap.Field which ties consumers to the deprecated zap dependency.
// There is no drop-in slog replacement yet. This function will be removed in a future version.
func ErrorDetails(err error) zap.Field {
// ErrorDetails creates a slog.Attr that logs the gRPC error details of the provided error.
func ErrorDetails(err error) slog.Attr {
if err == nil {
return zap.Skip()
return slog.Attr{}
}
s, ok := status.FromError(err)
if !ok {
return zap.Skip()
return slog.Attr{}
}
protoDetails := s.Proto().GetDetails()
if len(protoDetails) == 0 {
return zap.Skip()
return slog.Attr{}
}
return zap.Array("errorDetails", errorDetailsMarshaler(protoDetails))
}

type errorDetailsMarshaler []*anypb.Any

var _ zapcore.ArrayMarshaler = errorDetailsMarshaler{}

// MarshalLogArray implements zapcore.ArrayMarshaler.
func (d errorDetailsMarshaler) MarshalLogArray(encoder zapcore.ArrayEncoder) error {
for _, detail := range d {
if err := encoder.AppendReflected(reflectProtoMessage{message: detail}); err != nil {
return err
}
details := make([]reflectProtoMessage, len(protoDetails))
for i, detail := range protoDetails {
details[i] = reflectProtoMessage{message: detail}
}
return nil
return slog.Any("errorDetails", details)
}

type reflectProtoMessage struct {
Expand Down
38 changes: 0 additions & 38 deletions cloudrequestlog/migration.go

This file was deleted.

17 changes: 2 additions & 15 deletions cloudtrace/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"net/http"

"go.einride.tech/cloudrunner/cloudstream"
"go.einride.tech/cloudrunner/cloudzap" //nolint:staticcheck // SA1019: internal use of deprecated package pending removal
"go.uber.org/zap" //nolint:gomodguard // legacy zap dependency for trace middleware
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
Expand Down Expand Up @@ -106,17 +104,6 @@ func (i *Middleware) withLogTracing(ctx context.Context, header string) context.
if i.TraceHook != nil {
ctx = i.TraceHook(ctx, traceContext)
}
fields := make([]zap.Field, 0, 3)
//nolint:staticcheck // SA1019: deprecated, pending removal
fields = append(fields, cloudzap.Trace(traceContext.TraceID))
if traceContext.SpanID != "" {
//nolint:staticcheck // SA1019: deprecated, pending removal
fields = append(fields, cloudzap.SpanID(traceContext.SpanID))
}
if traceContext.Sampled {
//nolint:staticcheck // SA1019: deprecated, pending removal
fields = append(fields, cloudzap.TraceSampled(traceContext.Sampled))
}
//nolint:staticcheck // SA1019: deprecated, pending removal
return cloudzap.WithLoggerFields(ctx, fields...)
// Trace fields are automatically added by the slog handler from the span context
return ctx
}
36 changes: 0 additions & 36 deletions cloudzap/context.go

This file was deleted.

6 changes: 0 additions & 6 deletions cloudzap/doc.go

This file was deleted.

33 changes: 0 additions & 33 deletions cloudzap/encoderconfig.go

This file was deleted.

77 changes: 0 additions & 77 deletions cloudzap/errorreport.go

This file was deleted.

Loading