Filtered Reports
Overview
Section titled “Overview”Functional options let you slice the report before exporting. Filters compose — pass multiple options to intersect them.
Available Filters
Section titled “Available Filters”| Option | Filters by |
|---|---|
WithServicesByName(names...) |
Service name(s) |
WithServicesByType(type) |
Provider type (lazy, eager, transient, alias) |
WithEventsByType(type) |
Event type (registration, invocation, shutdown, health_check) |
WithTimeRange(from, to) |
Event timestamp range |
WithScope(scopeID) |
Scope ID |
// Only invocation events in the last 5 minutesreport := plugin.ReportFiltered( auditlog.WithEventsByType(auditlog.EventTypeInvocation), auditlog.WithTimeRange(time.Now().Add(-5*time.Minute), time.Now()),)
// Only eager servicesreport = plugin.ReportFiltered( auditlog.WithServicesByType(auditlog.ProviderTypeEager),)
// Only services named "*main.Database" in scope "drivers"report = plugin.ReportFiltered( auditlog.WithServicesByName("*main.Database"), auditlog.WithScope("drivers"),)Filtered Export
Section titled “Filtered Export”Export the filtered report directly to a file:
plugin.ExportFilteredToFile("lazy.json", auditlog.WithServicesByType(auditlog.ProviderTypeLazy),)Composing Filters
Section titled “Composing Filters”Filters intersect — all conditions must be met:
// Lazy services with invocation events in the last hourreport := plugin.ReportFiltered( auditlog.WithServicesByType(auditlog.ProviderTypeLazy), auditlog.WithEventsByType(auditlog.EventTypeInvocation), auditlog.WithTimeRange(time.Now().Add(-time.Hour), time.Now()),)Report Methods
Section titled “Report Methods”The Report type also has Filtered() for chaining:
report := plugin.Report()filtered := report.Filtered( auditlog.WithServicesByType(auditlog.ProviderTypeTransient),)Filtered reports have their counts (ServiceCount, EventCount, etc.) recomputed to match the filtered data. Validate() will pass on filtered reports.