View Source Corsica.Telemetry (Corsica v2.1.3)

Telemetry helpers and documentation around Corsica events.

Corsica emits the following events:

  • [:corsica, :accepted_request] — when a CORS request is accepted.
  • [:corsica, :invalid_request] — when a request is not a CORS request.
  • [:corsica, :rejected_request] — when a CORS request is rejected. Includes the following extra metadata:
    • :reason — the reason why the request was rejected. Can be one of:
      • :origin_not_allowed
      • {:req_method_not_allowed, req_method}
      • {:req_headers_not_allowed, non_allowed_headers}

Metadata: all the events include the following metadata in addition to any metadata explicitly specified in the list above.

  • :request_type — :simple or :preflight.
  • :conn - the Plug.Conn struct for the request.

Measurements: none of the events include any measurements.



Corsica supports basic logging functionality through attach_default_handler/0.

Link to this section Summary


Attaches a Telemetry handler for Corsica events that logs through Logger.

Link to this section Functions

Link to this function

attach_default_handler(options \\ [])

View Source (since 2.0.0)
@spec attach_default_handler(keyword()) :: :ok

Attaches a Telemetry handler for Corsica events that logs through Logger.

This function exists to mimic the behavior of the :log option that existed in Corsica v1.x. It attaches a handler for the following events:

  • [:corsica, :accepted_request]
  • [:corsica, :invalid_request]
  • [:corsica, :rejected_request]

The log levels can be customized through the :log_levels option that you can pass to this function. The levels and their defaults are:

  • :accepted — :debug
  • :invalid — :debug
  • :rejected — :warning

The :log_levels option mirrors the :log option that you could pass to Corsica in v1.x.



We recommend calling this function in your application's Application.start/2 callback.



def start(_type, _args) do
  children = [
    # ...

  Corsica.Telemetry.attach_default_handler(log_levels: [rejected: :error])

  Supervisor.start_link(children, strategy: :one_for_one)