Skip to content

Commit

Permalink
feat(logger): add sourceReferences field
Browse files Browse the repository at this point in the history
  • Loading branch information
ww24 committed Sep 26, 2023
1 parent 45e401c commit 4838669
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion logger/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,33 @@ func (l *sourceLocation) MarshalLogObject(enc zapcore.ObjectEncoder) error {
return nil
}

// see: https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorContext#SourceReference
type sourceReference struct {
Repository string
RevisionID string
}

func (r *sourceReference) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("repository", r.Repository)
enc.AddString("revisionId", r.RevisionID)
return nil
}

type sourceReferences []*sourceReference

func (r sourceReferences) MarshalLogArray(enc zapcore.ArrayEncoder) error {
for _, sr := range r {
if err := enc.AppendObject(sr); err != nil {
return fmt.Errorf("failed to append sourceReference: %w", err)
}
}
return nil
}

// see: https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorContext
type errorContext struct {
ReportLocation *sourceLocation
ReportLocation *sourceLocation
SourceReferences sourceReferences
}

func (c *errorContext) MarshalLogObject(enc zapcore.ObjectEncoder) error {
Expand All @@ -56,6 +80,11 @@ func (c *errorContext) MarshalLogObject(enc zapcore.ObjectEncoder) error {
return fmt.Errorf("failed to add reportLocation field: %w", err)
}
}
if len(c.SourceReferences) > 0 {
if err := enc.AddArray("sourceReferences", c.SourceReferences); err != nil {
return fmt.Errorf("failed to add sourceReferences field: %w", err)
}
}
return nil
}

Expand Down

0 comments on commit 4838669

Please sign in to comment.