logger

package
v0.0.85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package logger provides a general logging tools

Index

Constants

View Source
const Text = "text"

Text is the constant for the text format

Variables

This section is empty.

Functions

func Interceptor

Interceptor creates a gRPC unary server interceptor that logs incoming requests and their responses using the Zerolog logger attached to the context.Context. Successful requests are logged at the info level and error requests are logged at the error level.

Returns:

  • grpc.UnaryServerInterceptor: The gRPC unary server interceptor function.

Example usage:

server := grpc.NewServer(
  ...
  grpc.UnaryServerInterceptor(logger.Interceptor(loggingConfig)),
  ...
)

func RequestIDInterceptor added in v0.0.67

func RequestIDInterceptor(headerSuffix string) grpc.UnaryServerInterceptor

RequestIDInterceptor traces request ids.

It's job is to add a request id (UUID) to the context so that all subsequent logs inherit it, making it easier to track down problems on a per-request basis. It also sends back it back in a header.

Types

type ActionEvalData

type ActionEvalData struct {
	// how was the action configured - on, off, ...
	State string `json:"state"`
	// what was the result of the action - success, failure, ...
	Result string `json:"result"`
}

ActionEvalData reports

type Profile

type Profile struct {
	Name string    `json:"name"`
	ID   uuid.UUID `json:"id"`
}

Profile is a struct describing a Profile for telemetry purposes

type ProjectTombstone

type ProjectTombstone struct {
	// Project records the project ID that the request was associated with.
	Project uuid.UUID `json:"project"`

	// ProfileCount records the number of profiles associated with the project.
	ProfileCount int `json:"profile_count"`
	// RepositoriesCount records the number of repositories associated with the project.
	RepositoriesCount int `json:"repositories_count"`
	// Entitlements that the projects has.
	Entitlements []string `json:"entitlements"`
}

ProjectTombstone can be used to store project metadata in the context of deletion.

func (ProjectTombstone) Equals

func (pt ProjectTombstone) Equals(other ProjectTombstone) bool

Equals compares two ProjectTombstone structs for equality.

type RuleEvalData

type RuleEvalData struct {
	RuleType RuleType `json:"ruletype"`
	Profile  Profile  `json:"profile"`

	EvalResult string                                   `json:"eval_result"`
	Actions    map[interfaces.ActionType]ActionEvalData `json:"actions"`
}

RuleEvalData reports

type RuleType

type RuleType struct {
	Name string    `json:"name"`
	ID   uuid.UUID `json:"id"`
}

RuleType is a struct describing a rule type for telemetry purposes

type TelemetryStore

type TelemetryStore struct {
	// Project records the project ID that the request was associated with.
	Project uuid.UUID `json:"project"`

	// Provider records the provider name that the request was associated with.
	Provider string `json:"provider"`

	// ProviderID records the provider ID that the request was associated with.
	ProviderID uuid.UUID `json:"provider_id"`

	// Repository is the repository ID that the request was associated with.
	Repository uuid.UUID `json:"repository"`

	// Artifact is the artifact ID that the request was associated with.
	Artifact uuid.UUID `json:"artifact"`

	// PullRequest is the pull request ID that the request was associated with.
	PullRequest uuid.UUID `json:"pr"`

	// Profile is the profile that the request was associated with.
	Profile Profile `json:"profile"`

	// RuleType is the rule type that the request was associated with.
	RuleType RuleType `json:"ruletype"`

	// Hashed (SHA256) `sub` from the JWT.  This should be hard to reverse (pseudonymized),
	// but allows correlation between requests.
	LoginHash string `json:"login_sha"`

	// Rules evaluated during processing
	Evals []RuleEvalData `json:"rules"`

	// Metadata about the project tombstone
	ProjectTombstone ProjectTombstone `json:"project_tombstone"`
}

TelemetryStore is a struct that can be used to store telemetry data in the context.

func BusinessRecord

func BusinessRecord(ctx context.Context) *TelemetryStore

BusinessRecord provides the ability to store an observation about the current flow of business logic in the context of the current request. When called in in the context of a logged action, it will record and send the marshalled data to the logging system.

When called outside a logged context, it will collect and discard the data.

func (*TelemetryStore) AddRuleEval

func (ts *TelemetryStore) AddRuleEval(
	evalInfo interfaces.ActionsParams,
	ruleTypeName string,
)

AddRuleEval is a convenience method to add a rule evaluation result to the telemetry store.

func (*TelemetryStore) Record

func (ts *TelemetryStore) Record(e *zerolog.Event) *zerolog.Event

Record adds the collected data to the supplied event record.

func (*TelemetryStore) WithTelemetry

func (ts *TelemetryStore) WithTelemetry(ctx context.Context) context.Context

WithTelemetry enriches the current context with a TelemetryStore which will collect observations about the current flow of business logic.

type TelemetryStoreWMMiddleware

type TelemetryStoreWMMiddleware struct {
	// contains filtered or unexported fields
}

TelemetryStoreWMMiddleware is a Watermill middleware that logs the relevant telemetry data.

func NewTelemetryStoreWMMiddleware

func NewTelemetryStoreWMMiddleware(l *zerolog.Logger) *TelemetryStoreWMMiddleware

NewTelemetryStoreWMMiddleware returns a new TelemetryStoreWMMiddleware.

func (*TelemetryStoreWMMiddleware) TelemetryStoreMiddleware

func (m *TelemetryStoreWMMiddleware) TelemetryStoreMiddleware(h message.HandlerFunc) message.HandlerFunc

TelemetryStoreMiddleware is a Watermill middleware that logs the relevant telemetry data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL