SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(audit): add auditortypes package (#10761)
Pandey37d202de9207
diff --git a/pkg/types/auditortypes/action.go b/pkg/types/auditortypes/action.gonew file mode 100644index 0000000000..370e869d03--- /dev/null+++ b/pkg/types/auditortypes/action.go@@ -0,0 +1,28 @@+package auditortypes++import "github.com/SigNoz/signoz/pkg/valuer"++// Action represents what was done.+type Action struct {+ valuer.String+ pastTense string+}++var (+ ActionCreate = Action{valuer.NewString("create"), "created"}+ ActionUpdate = Action{valuer.NewString("update"), "updated"}+ ActionDelete = Action{valuer.NewString("delete"), "deleted"}+)++func (Action) Enum() []any {+ return []any{+ ActionCreate,+ ActionUpdate,+ ActionDelete,+ }+}++// PastTense returns the past-tense form of the action for use in EventName.+func (a Action) PastTense() string {+ return a.pastTense+}diff --git a/pkg/types/auditortypes/category.go b/pkg/types/auditortypes/category.gonew file mode 100644index 0000000000..f583b747e5--- /dev/null+++ b/pkg/types/auditortypes/category.go@@ -0,0 +1,23 @@+package auditortypes++import "github.com/SigNoz/signoz/pkg/valuer"++// ActionCategory classifies the audit event per IEC 62443.+// See https://www.iec.ch/blog/understanding-iec-62443 for the standard reference.+type ActionCategory struct{ valuer.String }++var (+ ActionCategoryAccessControl = ActionCategory{valuer.NewString("access_control")}+ ActionCategoryConfigurationChange = ActionCategory{valuer.NewString("configuration_change")}+ ActionCategoryDataAccess = ActionCategory{valuer.NewString("data_access")}+ ActionCategorySystemEvent = ActionCategory{valuer.NewString("system_event")}+)++func (ActionCategory) Enum() []any {+ return []any{+ ActionCategoryAccessControl,+ ActionCategoryConfigurationChange,+ ActionCategoryDataAccess,+ ActionCategorySystemEvent,+ }+}diff --git a/pkg/types/auditortypes/event.go b/pkg/types/auditortypes/event.gonew file mode 100644index 0000000000..3e18d95127--- /dev/null+++ b/pkg/types/auditortypes/event.go@@ -0,0 +1,51 @@+package auditortypes++import (+ "context"+ "time"+)++// AuditEvent represents a single audit log event.+// Fields are ordered following the OTel LogRecord structure.+type AuditEvent struct {+ // OTel LogRecord intrinsic fields+ Timestamp time.Time `json:"timestamp"`+ TraceID string `json:"traceId,omitempty"`+ SpanID string `json:"spanId,omitempty"`+ Body string `json:"body"`+ EventName EventName `json:"eventName"`++ // Audit attributes — Principal (Who)+ PrincipalID string `json:"principalId"`+ PrincipalEmail string `json:"principalEmail"`+ PrincipalType PrincipalType `json:"principalType"`+ PrincipalOrgID string `json:"principalOrgId"`+ IdentNProvider string `json:"identnProvider,omitempty"`++ // Audit attributes — Action (What)+ Action Action `json:"action"`+ ActionCategory ActionCategory `json:"actionCategory"`+ Outcome Outcome `json:"outcome"`++ // Audit attributes — Resource (On What)+ ResourceName string `json:"resourceName"`+ ResourceID string `json:"resourceId,omitempty"`++ // Audit attributes — Error (When outcome is failure)+ ErrorType string `json:"errorType,omitempty"`+ ErrorCode string `json:"errorCode,omitempty"`+ ErrorMessage string `json:"errorMessage,omitempty"`++ // Transport Context (Where/How)+ HTTPMethod string `json:"httpMethod,omitempty"`+ HTTPRoute string `json:"httpRoute,omitempty"`+ HTTPStatusCode int `json:"httpStatusCode,omitempty"`+ URLPath string `json:"urlPath,omitempty"`+ ClientAddress string `json:"clientAddress,omitempty"`+ UserAgent string `json:"userAgent,omitempty"`+}++// Store is the minimal interface for emitting audit events.+type Store interface {+ Emit(ctx context.Context, event AuditEvent) error+}diff --git a/pkg/types/auditortypes/event_name.go b/pkg/types/auditortypes/event_name.gonew file mode 100644index 0000000000..9cf0ea743c--- /dev/null+++ b/pkg/types/auditortypes/event_name.go@@ -0,0 +1,24 @@+package auditortypes++// EventName is a typed wrapper for audit event names, ensuring not every+// string qualifies as an event name.+type EventName struct {+ s string+}++// NewEventName derives the audit event name from a resource name and action.+// Format: {resource_name}.{pastTense(action)}+//+// Examples:+//+// NewEventName("dashboard", ActionCreate) → "dashboard.created"+// NewEventName("dashboard", ActionUpdate) → "dashboard.updated"+// NewEventName("user.role", ActionUpdate) → "user.role.updated"+func NewEventName(resourceName string, action Action) EventName {+ return EventName{s: resourceName + "." + action.PastTense()}+}++// String returns the string representation of the event name.+func (e EventName) String() string {+ return e.s+}diff --git a/pkg/types/auditortypes/outcome.go b/pkg/types/auditortypes/outcome.gonew file mode 100644index 0000000000..3eeeae46e0--- /dev/null+++ b/pkg/types/auditortypes/outcome.go@@ -0,0 +1,18 @@+package auditortypes++import "github.com/SigNoz/signoz/pkg/valuer"++// Outcome represents the result of an audited operation.+type Outcome struct{ valuer.String }++var (+ OutcomeSuccess = Outcome{valuer.NewString("success")}+ OutcomeFailure = Outcome{valuer.NewString("failure")}+)++func (Outcome) Enum() []any {+ return []any{+ OutcomeSuccess,+ OutcomeFailure,+ }+}diff --git a/pkg/types/auditortypes/principal.go b/pkg/types/auditortypes/principal.gonew file mode 100644index 0000000000..b4b7cd0d2b--- /dev/null+++ b/pkg/types/auditortypes/principal.go@@ -0,0 +1,23 @@+package auditortypes++import "github.com/SigNoz/signoz/pkg/valuer"++// PrincipalType identifies the kind of actor that performed the action.+// TODO: use PrincipalType from coretypes once the coretypes package is available.+type PrincipalType struct{ valuer.String }++var (+ PrincipalTypeUser = PrincipalType{valuer.NewString("user")}+ PrincipalTypeServiceAccount = PrincipalType{valuer.NewString("service_account")}+ PrincipalTypeSystem = PrincipalType{valuer.NewString("system")}+ PrincipalTypeAnonymous = PrincipalType{valuer.NewString("anonymous")}+)++func (PrincipalType) Enum() []any {+ return []any{+ PrincipalTypeUser,+ PrincipalTypeServiceAccount,+ PrincipalTypeSystem,+ PrincipalTypeAnonymous,+ }+}