X-TraceC++Library
|
Represents an X-Trace context, which carries information about the current task and the most recent preceding event in a thread. More...
#include <XtrContext.h>
Static Public Member Functions | |
static const Metadata & | getContext () |
Get the current context metadata. | |
static void | setContext (Metadata const &xtr) |
Set the current context metadata. | |
static void | unsetContext () |
Clear the current context. | |
static xtr_result | logEvent (const char *agent, const char *label, u_int8_t severity=OptionSeverity::_DEFAULT) |
Logs an event to the X-Trace framework. | |
static xtr_result | logEvent (Event *e, u_int8_t severity=OptionSeverity::_DEFAULT) |
Logs an event to the X-Trace framework. | |
static auto_ptr< Event > | createEvent (const char *agent, const char *label, u_int8_t severity=OptionSeverity::_DEFAULT) |
The same as logEvent, but does not send the report, and returns the created Event object. | |
static auto_ptr< Event > | prepareEvent (const char *agent, const char *label, u_int8_t severity=OptionSeverity::_DEFAULT) |
Prepares an event object for reporting, returning a(n auto) pointer to the created event object. | |
static void | setHost (const char *name) |
Sets the host name that is automatically added to the reports generated by logEvent() and createEvent(). | |
static void | forkContext () |
Explicitly indicate the start of a new chain of events. | |
Static Public Attributes | |
static pthread_key_t | context_key |
Represents an X-Trace context, which carries information about the current task and the most recent preceding event in a thread.
This class also provides methods to create and log X-Trace events.
static auto_ptr<Event> xtr::Context::createEvent | ( | const char * | agent, |
const char * | label, | ||
u_int8_t | severity = OptionSeverity::_DEFAULT |
||
) | [static] |
The same as logEvent, but does not send the report, and returns the created Event object.
Use this to add more information to the report.
agent | value of the Agent: key for the created report |
label | value of the Label: key for the created report |
severity | desired severity level for this report. This event will be logged only if the event severity <= reporting context's severityThreshold. |
static void xtr::Context::forkContext | ( | ) | [static] |
Explicitly indicate the start of a new chain of events.
This is used for explicitly capturing concurrency, and is experimental.
static const Metadata& xtr::Context::getContext | ( | ) | [static] |
Get the current context metadata.
static xtr_result xtr::Context::logEvent | ( | const char * | agent, |
const char * | label, | ||
u_int8_t | severity = OptionSeverity::_DEFAULT |
||
) | [static] |
Logs an event to the X-Trace framework.
This call prepares and logs an event atomically, with a reduced set of standard information in the report. If you want to add more information to events, use the pair of calls prepareEvent() / logEvent(Event *).
This does several things:
If the current context is not valid, it will create a new context with a random task id and set it.
agent | value of the Agent: key for the created report |
label | value of the Label: key for the created report |
severity | desired severity level for this event. The default value is OptionSeverity::_DEFAULT. This event will be logged only if the event severity <= reporting context's severityThreshold. |
static xtr_result xtr::Context::logEvent | ( | Event * | e, |
u_int8_t | severity = OptionSeverity::_DEFAULT |
||
) | [static] |
Logs an event to the X-Trace framework.
The second version of the logEvent call, taking an event object pointer rather than message strings. This event will be, most likely, the result of a previous call to prepareEvent(). This call will, atomically:
e | A pointer to an event object to be logged. The calling function maintains ownership of the pointer. |
severity | (default OptionSeverity::_DEFAULT) The severity of the logged event. |
static auto_ptr<Event> xtr::Context::prepareEvent | ( | const char * | agent, |
const char * | label, | ||
u_int8_t | severity = OptionSeverity::_DEFAULT |
||
) | [static] |
Prepares an event object for reporting, returning a(n auto) pointer to the created event object.
Use this if you want to add more information to the event before logging than the simple Context::logEvent() call gives. The most common usage pattern should be:
auto_ptr<Event> e = prepareEvent(...) e->addInfo(...) e->addEdge(...) ... logEvent(e.get())
This does the following:
agent | value of the Agent: key for the created report |
label | value of the Label: key for the created report |
severity | Desired severity level for this report. This event will be logged only if the event severity <= reporting context's severityThreshold. |
static void xtr::Context::setContext | ( | Metadata const & | xtr | ) | [static] |
Set the current context metadata.
xtr | the metadata to set the context to. |
static void xtr::Context::setHost | ( | const char * | name | ) | [static] |
Sets the host name that is automatically added to the reports generated by logEvent() and createEvent().
The setting overrides the default, which the class tries to obtain from the underlying OS.
name | a regular C string with the host name. At most MAXHOSTNAME (256) characters are copied from this string into the class. |
static void xtr::Context::unsetContext | ( | ) | [static] |
Clear the current context.
After this, a call to Context.getContext().isValid() will return false. This is important to avoid the context leaking to other unrelated operations
pthread_key_t xtr::Context::context_key [static] |