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 withIncendiaryService
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 withIncendiaryService
.- Parameters
app (insanic.app.Insanic) –
- Return type
None
-
classmethod
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
¶
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
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 thetrace_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
¶
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) –