Skip to content

Filtered Reports

Functional options let you slice the report before exporting. Filters compose — pass multiple options to intersect them.

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 minutes
report := plugin.ReportFiltered(
auditlog.WithEventsByType(auditlog.EventTypeInvocation),
auditlog.WithTimeRange(time.Now().Add(-5*time.Minute), time.Now()),
)
// Only eager services
report = plugin.ReportFiltered(
auditlog.WithServicesByType(auditlog.ProviderTypeEager),
)
// Only services named "*main.Database" in scope "drivers"
report = plugin.ReportFiltered(
auditlog.WithServicesByName("*main.Database"),
auditlog.WithScope("drivers"),
)

Export the filtered report directly to a file:

plugin.ExportFilteredToFile("lazy.json",
auditlog.WithServicesByType(auditlog.ProviderTypeLazy),
)

Filters intersect — all conditions must be met:

// Lazy services with invocation events in the last hour
report := plugin.ReportFiltered(
auditlog.WithServicesByType(auditlog.ProviderTypeLazy),
auditlog.WithEventsByType(auditlog.EventTypeInvocation),
auditlog.WithTimeRange(time.Now().Add(-time.Hour), time.Now()),
)

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.