Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM golangci/golangci-lint:v2.8.0@sha256:bebcfa63db7df53e417845ed61e4540519cf74fcba22793cdd174b3415a9e4e2 AS golangci-lint
FROM golangci/golangci-lint:v2.10.1@sha256:ea84d14c2fef724411be7dc45e09e6ef721d748315252b02df19a7e3113ee763 AS golangci-lint
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
VERSION ?= $(shell git rev-list -1 HEAD)
GOENV = CGO_ENABLED=0 GOOS=linux GOARCH=amd64
GOFLAGS = -ldflags "-X 'moseisleycantina/internal/logger.Version=$(VERSION)'"
GOLANGCI_LINT_VERSION := v2.10.1

build:
$(GOENV) go build $(GOFLAGS) -o bin/logger ./cmd/...
Expand All @@ -22,9 +23,13 @@ cov:
-go tool cover -html=coverage.txt -o coverage.html
-go tool cover -func=coverage.txt

lint:
docker build --quiet --target golangci-lint -t golangci-lint:latest .
docker run --rm -v $(shell pwd):/app -w /app golangci-lint golangci-lint run ./...
lint: lint-go

lint-go:
@if ! command -v golangci-lint >/dev/null 2>&1 || ! golangci-lint version 2>/dev/null | grep -q "$(patsubst v%,%,$(GOLANGCI_LINT_VERSION))"; then \
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) ; \
fi
golangci-lint run ./...

lint-python:
ruff format pylogtracer --check
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nullify-platform/logger

go 1.24.5
go 1.26.0

require go.uber.org/multierr v1.11.0 // indirect

Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/chunking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestChunkOversizedFields_ExactLimit(t *testing.T) {
}

// fieldsToMap converts a slice of zap fields to a map for easier test assertions.
func fieldsToMap(fields []zapcore.Field) map[string]interface{} {
func fieldsToMap(fields []zapcore.Field) map[string]any {
enc := zapcore.NewMapObjectEncoder()
for _, f := range fields {
f.AddTo(enc)
Expand Down
10 changes: 5 additions & 5 deletions pkg/logger/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Trace(trace []byte) Field {
}

// Any adds a field to the logger
func Any(key string, val interface{}) Field {
func Any(key string, val any) Field {
return zap.Any(key, val)
}

Expand Down Expand Up @@ -157,7 +157,7 @@ type ToolCallFields struct {

// WithAgent adds agent-related fields to the log entry
func WithAgent(agent AgentFields) Field {
fields := map[string]interface{}{
fields := map[string]any{
"name": agent.Name,
"status": agent.Status,
}
Expand All @@ -178,7 +178,7 @@ func (a *AgentFields) WithTraceID(traceID string) *AgentFields {

// WithRepository adds repository-related fields to the log entry
func WithRepository(repo RepositoryFields) Field {
fields := map[string]interface{}{
fields := map[string]any{
"name": repo.Name,
"platform": repo.Platform,
"installation_id": repo.InstallationID,
Expand All @@ -193,7 +193,7 @@ func WithRepository(repo RepositoryFields) Field {

// WithService adds service-related fields to the log entry
func WithService(service ServiceFields) Field {
fields := map[string]interface{}{
fields := map[string]any{
"name": service.Name,
}

Expand Down Expand Up @@ -225,7 +225,7 @@ func WithErrorInfo(errFields ErrorFields) []Field {
}

func WithToolCall(toolCall ToolCallFields) Field {
fields := map[string]interface{}{
fields := map[string]any{
"tool_name": toolCall.ToolName,
"status": toolCall.Status,
}
Expand Down
66 changes: 33 additions & 33 deletions pkg/logger/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestLogFields(t *testing.T) {
tests := []struct {
name string
builder func() []Field
expected map[string]interface{}
expected map[string]any
}{
{
name: "agent fields",
Expand All @@ -20,8 +20,8 @@ func TestLogFields(t *testing.T) {
WithAgent("test-agent", "running").
Build()
},
expected: map[string]interface{}{
"agent": map[string]interface{}{
expected: map[string]any{
"agent": map[string]any{
"name": "test-agent",
"status": "running",
},
Expand All @@ -34,8 +34,8 @@ func TestLogFields(t *testing.T) {
WithService("test-service").
Build()
},
expected: map[string]interface{}{
"service": map[string]interface{}{
expected: map[string]any{
"service": map[string]any{
"name": "test-service",
},
},
Expand All @@ -49,8 +49,8 @@ func TestLogFields(t *testing.T) {
WithServiceCategory("test-category").
Build()
},
expected: map[string]interface{}{
"service": map[string]interface{}{
expected: map[string]any{
"service": map[string]any{
"name": "test-service",
"tool_name": "test-tool",
"tool_version": "1.0.0",
Expand All @@ -65,8 +65,8 @@ func TestLogFields(t *testing.T) {
WithRepository("test-repo", "github", "12345").
Build()
},
expected: map[string]interface{}{
"repository": map[string]interface{}{
expected: map[string]any{
"repository": map[string]any{
"name": "test-repo",
"platform": "github",
"installation_id": "12345",
Expand All @@ -81,8 +81,8 @@ func TestLogFields(t *testing.T) {
WithRepositoryOwner("test-owner").
Build()
},
expected: map[string]interface{}{
"repository": map[string]interface{}{
expected: map[string]any{
"repository": map[string]any{
"name": "test-repo",
"platform": "github",
"installation_id": "12345",
Expand All @@ -97,7 +97,7 @@ func TestLogFields(t *testing.T) {
WithError(ErrorTypeAgent, "test error").
Build()
},
expected: map[string]interface{}{
expected: map[string]any{
"error_type": "agent_error",
"error_message": "test error",
},
Expand All @@ -110,7 +110,7 @@ func TestLogFields(t *testing.T) {
WithErrorTraceback("test traceback").
Build()
},
expected: map[string]interface{}{
expected: map[string]any{
"error_type": "agent_error",
"error_message": "test error",
"error_traceback": "test traceback",
Expand All @@ -123,8 +123,8 @@ func TestLogFields(t *testing.T) {
WithToolCallInfo("api_call", "failed").
Build()
},
expected: map[string]interface{}{
"tool_call": map[string]interface{}{
expected: map[string]any{
"tool_call": map[string]any{
"tool_name": "api_call",
"status": "failed",
},
Expand All @@ -138,8 +138,8 @@ func TestLogFields(t *testing.T) {
WithToolCallErrorReason("connection timeout").
Build()
},
expected: map[string]interface{}{
"tool_call": map[string]interface{}{
expected: map[string]any{
"tool_call": map[string]any{
"tool_name": "api_call",
"status": "failed",
"error_reason": "connection timeout",
Expand All @@ -154,8 +154,8 @@ func TestLogFields(t *testing.T) {
WithToolCallDuration(1500).
Build()
},
expected: map[string]interface{}{
"tool_call": map[string]interface{}{
expected: map[string]any{
"tool_call": map[string]any{
"tool_name": "api_call",
"status": "failed",
"duration_ms": int64(1500),
Expand All @@ -171,8 +171,8 @@ func TestLogFields(t *testing.T) {
WithToolCallDuration(1500).
Build()
},
expected: map[string]interface{}{
"tool_call": map[string]interface{}{
expected: map[string]any{
"tool_call": map[string]any{
"tool_name": "api_call",
"status": "failed",
"error_reason": "connection timeout",
Expand All @@ -190,12 +190,12 @@ func TestLogFields(t *testing.T) {
WithError(ErrorTypeToolCall, "tool execution failed").
Build()
},
expected: map[string]interface{}{
"agent": map[string]interface{}{
expected: map[string]any{
"agent": map[string]any{
"name": "executor-agent",
"status": "executing",
},
"tool_call": map[string]interface{}{
"tool_call": map[string]any{
"tool_name": "api_call",
"status": "failed",
"error_reason": "timeout",
Expand All @@ -218,18 +218,18 @@ func TestLogFields(t *testing.T) {
WithErrorTraceback("test traceback").
Build()
},
expected: map[string]interface{}{
"agent": map[string]interface{}{
expected: map[string]any{
"agent": map[string]any{
"name": "test-agent",
"status": "failed",
},
"service": map[string]interface{}{
"service": map[string]any{
"name": "test-service",
"tool_name": "test-tool",
"tool_version": "1.0.0",
"category": "test-category",
},
"repository": map[string]interface{}{
"repository": map[string]any{
"name": "test-repo",
"platform": "github",
"installation_id": "12345",
Expand All @@ -254,20 +254,20 @@ func TestLogFields(t *testing.T) {
WithErrorTraceback("goroutine trace...").
Build()
},
expected: map[string]interface{}{
"agent": map[string]interface{}{
expected: map[string]any{
"agent": map[string]any{
"name": "test-agent",
"status": "executing",
},
"service": map[string]interface{}{
"service": map[string]any{
"name": "tool-executor",
},
"repository": map[string]interface{}{
"repository": map[string]any{
"name": "test-repo",
"platform": "github",
"installation_id": "12345",
},
"tool_call": map[string]interface{}{
"tool_call": map[string]any{
"tool_name": "api_call",
"status": "failed",
"error_reason": "timeout",
Expand Down
4 changes: 2 additions & 2 deletions pkg/logger/nullify_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func extractFieldsFromStruct(ctx context.Context, v reflect.Value, fields []zapc
return fields
}

if v.Kind() == reflect.Ptr {
if v.Kind() == reflect.Pointer {
v = v.Elem()
}

Expand All @@ -133,7 +133,7 @@ func extractFieldsFromStruct(ctx context.Context, v reflect.Value, fields []zapc
fieldValue := v.Field(i)

// If the field is a struct, recurse into it
if fieldValue.Kind() == reflect.Struct || (fieldValue.Kind() == reflect.Ptr && fieldValue.Elem().Kind() == reflect.Struct) {
if fieldValue.Kind() == reflect.Struct || (fieldValue.Kind() == reflect.Pointer && fieldValue.Elem().Kind() == reflect.Struct) {
fields = extractFieldsFromStruct(ctx, fieldValue, fields)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/tracer/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func CreateClientContextForLambdaInvoke(ctx context.Context, custom map[string]s
InjectTracingIntoCustomMessage(ctx, custom)

var clientContextBase64 *string
if marshalled, err := json.Marshal(map[string]interface{}{"custom": custom}); err == nil {
if marshalled, err := json.Marshal(map[string]any{"custom": custom}); err == nil {
clientContextJSON := marshalled
clientContextBase64 = aws.String(base64.StdEncoding.EncodeToString(clientContextJSON))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/add_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestAddField(t *testing.T) {
fmt.Println("stdout: " + output.String())

// check that the output doesn't include the added field
var jsonOutput map[string]interface{}
var jsonOutput map[string]any
err = json.Unmarshal(output.Bytes(), &jsonOutput)
require.Nil(t, err)
_, ok := jsonOutput["my"]
Expand Down
2 changes: 1 addition & 1 deletion tests/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestProductionLogger(t *testing.T) {

fmt.Println("stdout: " + output.String())

var jsonOutput map[string]interface{}
var jsonOutput map[string]any
err = json.Unmarshal(output.Bytes(), &jsonOutput)
require.Nil(t, err, "stdout was not valid json")

Expand Down