X-Ray API Reference

incendiary.xray.app

class Incendiary[source]
classmethod init_app(app, recorder=None)[source]

Initializes Insanic to use Incendiary.

  • This loads all default Incendiary configs.

  • Validates connection information to X-Ray Daemon.

  • Configures X-Ray SDK Recorder

  • Attaches middlewares to start stop segments

  • Replaces Service object with IncendiaryService to trace interservice communications.

  • Replaces asyncio task factory.

  • Patches configured modules.

Parameters
  • app (insanic.app.Insanic) – Your Insanic application/

  • recorder (aws_xray_sdk.core.async_recorder.AsyncAWSXRayRecorder) – If you want to use your own recorder.

Return type

None

classmethod setup_listeners(app)[source]
  • Attaches before server start listener that configures the X-Ray Recorder.

  • Attaches a before server start listener that replaces the default asyncio task factory that can hold context.

Parameters

app (insanic.app.Insanic) –

Return type

None

classmethod setup_client(app)[source]

Replaces the Service class on the service registry with IncendiaryService.

Parameters

app (insanic.app.Insanic) –

Return type

None

classmethod setup_middlewares(app)[source]

Sets up request and response middlewares that starts a segment, or creates segment, and ends the segment on response.

Parameters

app (insanic.app.Insanic) –

Return type

None

classmethod xray_config(app)[source]

Class method that returns all the configurations for the X-Ray SDK Recoder.

Parameters

app (insanic.app.Insanic) –

Return type

dict

incendiary.xray.hooks

begin_subsegment(request, recorder, name=None)[source]

Begins a subsegment before sending an interservice request.

Parameters
  • request (httpx.Request) – The httpx request object for interservice communications.

  • recorder (aws_xray_sdk.core.async_recorder.AsyncAWSXRayRecorder) – The AWS X-Ray recorder for this application.

  • name (str) –

Returns

The started subsegment.

Return type

Optional[aws_xray_sdk.core.models.subsegment.Subsegment]

end_subsegment(*, request, response, recorder, subsegment=None)[source]

The function that ends the subsegment after a response gets received.

Parameters
  • request – The request object for interservice communications.

  • response – Response object of the request.

  • subsegment (Optional[aws_xray_sdk.core.models.subsegment.Subsegment]) – Subsegment of this request.

  • recorder – The aws xray recorder.

Return type

Optional[aws_xray_sdk.core.models.subsegment.Subsegment]

end_subsegment_with_exception(*, request, exception, subsegment=None, recorder)[source]

The function that ends the subsegment when an exception is raised while attempting to send an interservice request.

Parameters
  • request (httpx.Request) –

  • exception (Exception) –

  • subsegment (Optional[aws_xray_sdk.core.models.subsegment.Subsegment]) –

  • recorder (aws_xray_sdk.core.async_recorder.AsyncAWSXRayRecorder) –

Return type

Optional[aws_xray_sdk.core.models.subsegment.Subsegment]

incendiary.xray.middlewares

async before_request(request)[source]

The request middleware that runs when Sanic receives a request. Starts a segment if sampling determines if it should be traced.

Parameters

request (insanic.request.Request) –

Return type

None

async after_request(request, response)[source]

Ends the segment before response is returned.

Parameters
  • request (insanic.request.Request) –

  • response (sanic.response.BaseHTTPResponse) –

Return type

None

incendiary.xray.mixins

class IncendiaryAsyncSubsegmentContextManager(instance, *args, **kwargs)[source]

A context manager that starts and ends a segment.

class CaptureMixin[source]
classmethod capture_async(name=None)[source]

A decorator that records enclosed function or method in a subsegment. It only works with asynchronous function

Parameters

name (Optional[str]) – The name of the subsegment. If not specified, the function name will be used.

Return type

incendiary.xray.mixins.IncendiaryAsyncSubsegmentContextManager

classmethod capture(name=None)[source]

A decorator that records decorated callable in a subsegment.

Parameters

name (Optional[str]) – The name of the subsegment. If not specified the function name will be used.

Return type

aws_xray_sdk.core.models.subsegment.SubsegmentContextManager

incendiary.xray.sampling

class IncendiaryDefaultSampler(app)[source]
calculate_sampling_decision(trace_header, recorder, service_name, method, path)[source]

Return 1 if should sample and 0 if should not. The sampling decision coming from trace_header always has the highest precedence. If the trace_header doesn’t contain sampling decision then it checks if sampling is enabled or not in the recorder. If not enabled it returns 1. Otherwise it uses sampling rule to decide.

incendiary.xray.services

class IncendiaryService(service_name, partial_path=None)[source]

Bases: insanic.services.client.Service

xray_recorder = None

incendiary.xray.utils

tracing_name(name=None)[source]

Returns that tracing node name. Appends the environment with the application’s service name.

Parameters

name (Optional[str]) –

Return type

str

abbreviate_for_xray(payload)[source]

If the payload includes a file, the file is translated to just it’s name and size instead of including the whole file.

Parameters

payload (dict) –

Return type

dict

cleanse_value(key, value)[source]

Cleanse an individual setting key/value of sensitive content. If the value is a dictionary, recursively cleanse the keys in that dictionary.

Parameters
  • key (str) –

  • value (Any) –

get_safe_dict(target)[source]

Returns a dictionary with sensitive settings blurred out.

Parameters

target (dict) –

Return type

dict

get_safe_settings()[source]

Returns a dictionary of the settings module, with sensitive settings blurred out.

Return type

dict