From 6e43859106626500068e957b096e372f7c3fed97 Mon Sep 17 00:00:00 2001 From: Omri Zeneva Date: Tue, 24 May 2022 05:08:17 -0400 Subject: [PATCH] doc: add explanation about the new two functions and example Signed-off-by: Omri Zeneva --- doc/radosgw/lua-scripting.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/doc/radosgw/lua-scripting.rst b/doc/radosgw/lua-scripting.rst index 39268d8aae2..5240f933597 100644 --- a/doc/radosgw/lua-scripting.rst +++ b/doc/radosgw/lua-scripting.rst @@ -320,6 +320,19 @@ during execution so that it may be read and used later during other executions, - The maximum number of entries in the table is 100,000. Each entry has a key and string value with a combined length of no more than 1KB. A Lua script will abort with an error if the number of entries or entry size exceeds these limits. +Tracing +~~~~~~~ +Tracing functions can be used only in `postRequest` context. + +- ``Request.Trace.SetAttribute()`` - sets the attribute for the request's trace. + Takes two arguments. The first is the `key`, which should be a string. The second is the value, which can either be a string or a number. + Using the attribute, you can locate specific traces. + +- ``Request.Trace.AddEvent()`` - adds an event to the first span of the request's trace + An event is defined by event name, event time, and zero or more event attributes. + Therefore, the function accepts one or two arguments. A string containing the event name should be the first argument, followed by the event attributes, which is optional for events without attributes. + An event's attributes must be a table of strings. + Lua Code Samples ---------------- - Print information on source and destination objects in case of copy: @@ -470,3 +483,21 @@ In the `preRequest` context: Note that changing `Request.Trace.Enable` does not change the tracer's state, but disables or enables the tracing for the request only. + +- Add Information for requests traces + +in `postRequest` context, we can add attributes and events to the request's trace. + +.. code-block:: lua + + Request.Trace.AddEvent("lua script execution started") + + Request.Trace.SetAttribute("HTTPStatusCode", Request.Response.HTTPStatusCode) + + event_attrs = {} + for k,v in pairs(Request.GenericAttributes) do + event_attrs[k] = v + end + + Request.Trace.AddEvent("second event", event_attrs) + -- 2.39.5