zoobzio December 15, 2025 Edit this page

Events Reference

Complete reference for rocco event signals and field keys.

Event System

Rocco emits events via capitan. Hook into events for logging, metrics, and tracing.

import "github.com/zoobz-io/capitan"

// Hook specific event
capitan.Hook(rocco.RequestCompleted, func(ctx context.Context, e *capitan.Event) {
    method, _ := rocco.MethodKey.From(e)
    // ...
})

// Observe all events
capitan.Observe(func(ctx context.Context, e *capitan.Event) {
    // Handle any event
})

Server Lifecycle Events

EngineCreated

Signal: http.engine.createdLevel: Debug

Emitted when engine instance is created.

No fields.

EngineStarting

Signal: http.engine.startingLevel: Info

Emitted when server starts listening.

FieldTypeDescription
AddressKeystringAddress being listened on
TLSEnabledKeyboolWhether TLS is enabled

EngineShutdownStarted

Signal: http.engine.shutdown.startedLevel: Info

Emitted when shutdown is initiated.

No fields.

EngineShutdownComplete

Signal: http.engine.shutdown.completeLevel: Info/Error

Emitted when shutdown completes.

FieldTypeDescription
GracefulKeyboolWhether shutdown was graceful
ErrorKeystringError message (if failed)

Handler Registration Events

HandlerRegistered

Signal: http.handler.registeredLevel: Debug

Emitted when a handler is registered.

FieldTypeDescription
HandlerNameKeystringHandler name
MethodKeystringHTTP method
PathKeystringURL path

Request Lifecycle Events

RequestReceived

Signal: http.request.receivedLevel: Debug

Emitted when request is received.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name

RequestCompleted

Signal: http.request.completedLevel: Info

Emitted when request completes successfully.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
StatusCodeKeyintHTTP status code
DurationMsKeyint64Duration in milliseconds

RequestFailed

Signal: http.request.failedLevel: Error

Emitted when request fails with error.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
StatusCodeKeyintHTTP status code
DurationMsKeyint64Duration in milliseconds
ErrorKeystringError message

Handler Execution Events

HandlerExecuting

Signal: http.handler.executingLevel: Debug

Emitted when handler function starts.

FieldTypeDescription
HandlerNameKeystringHandler name

HandlerSuccess

Signal: http.handler.successLevel: Info

Emitted when handler returns successfully.

FieldTypeDescription
HandlerNameKeystringHandler name
StatusCodeKeyintSuccess status code

HandlerError

Signal: http.handler.errorLevel: Error

Emitted when handler returns unexpected error.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

HandlerSentinelError

Signal: http.handler.sentinel.errorLevel: Warn

Emitted when handler returns declared sentinel error.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message
StatusCodeKeyintError status code

HandlerUndeclaredSentinel

Signal: http.handler.sentinel.undeclaredLevel: Warn

Emitted when handler returns undeclared sentinel error (programming error).

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message
StatusCodeKeyintWould-be status code

Request Processing Events

RequestParamsInvalid

Signal: http.request.params.invalidLevel: Error

Emitted when path/query parameter extraction fails.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

RequestBodyReadError

Signal: http.request.body.read.errorLevel: Error/Warn

Emitted when request body read fails.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

RequestBodyParseError

Signal: http.request.body.parse.errorLevel: Error

Emitted when JSON body parsing fails.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

RequestValidationInputFailed

Signal: http.request.validation.input.failedLevel: Warn

Emitted when input validation fails.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringValidation errors

RequestValidationOutputFailed

Signal: http.request.validation.output.failedLevel: Warn

Emitted when output validation fails (if enabled).

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringValidation errors

RequestResponseMarshalError

Signal: http.request.response.marshal.errorLevel: Error

Emitted when response JSON marshaling fails.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

RequestBodyCloseError

Signal: http.request.body.close.errorLevel: Warn

Emitted when closing the request body stream fails.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

ResponseWriteError

Signal: http.response.write.errorLevel: Warn

Emitted when writing response body to client fails (e.g., client disconnected).

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

Authentication Events

AuthenticationFailed

Signal: http.auth.failedLevel: Warn

Emitted when identity extraction fails.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
ErrorKeystringError message

AuthenticationSucceeded

Signal: http.auth.succeededLevel: Debug

Emitted when identity extraction succeeds.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
IdentityIDKeystringIdentity ID
TenantIDKeystringTenant ID

Authorization Events

AuthorizationScopeDenied

Signal: http.authz.scope.deniedLevel: Warn

Emitted when scope check fails.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
IdentityIDKeystringIdentity ID
RequiredScopesKeystringRequired scopes (comma-separated)
UserScopesKeystringUser's scopes (comma-separated)

AuthorizationRoleDenied

Signal: http.authz.role.deniedLevel: Warn

Emitted when role check fails.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
IdentityIDKeystringIdentity ID
RequiredRolesKeystringRequired roles (comma-separated)
UserRolesKeystringUser's roles (comma-separated)

AuthorizationSucceeded

Signal: http.authz.succeededLevel: Debug

Emitted when authorization passes.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
IdentityIDKeystringIdentity ID

Rate Limiting Events

RateLimitExceeded

Signal: http.ratelimit.exceededLevel: Warn

Emitted when usage limit is exceeded.

FieldTypeDescription
MethodKeystringHTTP method
PathKeystringRequest path
IdentityIDKeystringIdentity ID
LimitKeyKeystringLimit key name
CurrentValueKeyintCurrent usage value
ThresholdKeyintLimit threshold

Stream (SSE) Events

StreamExecuting

Signal: http.stream.executingLevel: Debug

Emitted when stream handler starts.

FieldTypeDescription
HandlerNameKeystringHandler name

StreamStarted

Signal: http.stream.startedLevel: Info

Emitted when SSE stream is established and headers sent.

FieldTypeDescription
HandlerNameKeystringHandler name

StreamEnded

Signal: http.stream.endedLevel: Info

Emitted when stream handler completes normally.

FieldTypeDescription
HandlerNameKeystringHandler name

StreamClientDisconnected

Signal: http.stream.client.disconnectedLevel: Info

Emitted when client disconnects from stream.

FieldTypeDescription
HandlerNameKeystringHandler name

StreamError

Signal: http.stream.errorLevel: Error

Emitted when stream handler encounters error.

FieldTypeDescription
HandlerNameKeystringHandler name
ErrorKeystringError message

Field Keys Reference

KeyTypeDescription
AddressKeystringServer address (e.g., ":8080")
MethodKeystringHTTP method
PathKeystringRequest path
HandlerNameKeystringHandler name
StatusCodeKeyintHTTP status code
DurationMsKeyint64Duration in milliseconds
ErrorKeystringError message
GracefulKeyboolGraceful shutdown flag
IdentityIDKeystringIdentity ID
TenantIDKeystringTenant ID
RequiredScopesKeystringRequired scopes
UserScopesKeystringUser's scopes
RequiredRolesKeystringRequired roles
UserRolesKeystringUser's roles
LimitKeyKeystringUsage limit key
CurrentValueKeyintCurrent usage value
ThresholdKeyintUsage threshold

Usage Example

import (
    "context"
    "github.com/zoobz-io/capitan"
    "github.com/zoobz-io/rocco"
)

func setupObservability() {
    // Log all requests
    capitan.Hook(rocco.RequestCompleted, func(ctx context.Context, e *capitan.Event) {
        method, _ := rocco.MethodKey.From(e)
        path, _ := rocco.PathKey.From(e)
        status, _ := rocco.StatusCodeKey.From(e)
        duration, _ := rocco.DurationMsKey.From(e)

        log.Info("request",
            "method", method,
            "path", path,
            "status", status,
            "duration_ms", duration,
        )
    })

    // Alert on auth failures
    capitan.Hook(rocco.AuthenticationFailed, func(ctx context.Context, e *capitan.Event) {
        path, _ := rocco.PathKey.From(e)
        err, _ := rocco.ErrorKey.From(e)
        alerting.Warn("auth_failed", path, err)
    })
}

See Also