module Panopticon

Defined in:

panopticon.cr

Constant Summary

HTTPHeader = "X-Correlation-ID"

Header used for passing the correlation ID between services.

LogKey = :correlation_id

Key used for storing correlation IDs within a Log::Context.

Class Method Summary

Class Method Detail

def self.attach(context : HTTP::Server::Context) : ID #

Receives and upstream ID and applies it to the current execution context.

If an ID does not exist on the received request, a new one is created.


[View source]
def self.extract(request : HTTP::Request) : ID | Nil #

Extracts a correlation ID from request.


[View source]
def self.extract(fiber : Fiber) : ID | Nil #

Extracts a correlation ID from fiber.


[View source]
def self.generate_id : ID #

Generates a new correlation ID.


[View source]
def self.id : ID #

Provide an ID for the current execution context.


[View source]
def self.id=(id : ID) : ID #

Sets the ID for the current execution context.


[View source]
def self.id? : ID | Nil #

Provides the current correlation ID, or nil if tracking is not active.


[View source]
def self.inject(id : ID, fiber : Fiber) : ID #

Injects id into fiber.

Once injected the ID will continue to be passed to downstream fibers as they are created as well as applied to all outgoing HTTP requests these make.


[View source]
def self.inject(id : ID, request : HTTP::Request) : ID #

Injects id into request.


[View source]
def self.propagate(to : Fiber | HTTP::Request, from = Fiber.current) : ID | Nil #

Copies the ID from an existing execution context to a new Fiber or outgoing HTTP::Request.


[View source]