Package: code-wake
Python code wake lib/service (pycodewake)ConceptCode Wake is a code instrumentation aid, recording to a database for analysis.With configuration so that Code Wake can find a data store, usage can be as
simple as this, create a process:importcode_wakecwproc=code_wake.Process()cwproc.log()Record events:cwproc.log({"event":"order","type":"special","customer":customer})Or log an exception:cwproc.log({"event":"fault","doing":"create_order","customer":customer},exc)Hereexcis an exception, and by default it's stack trace will be recorded along with
the event. Stack traces may also be recorded for non exception events as well, either
by specifyinginc_st=True, or by changing the configuration such that non exception
events always have them.The event will be logged asynchronously by default if the store supports this, and
thuslogwill returnNone. If you specify the kwardsync=Truethen the event
created will be returned.ConfigurationBy default, if/etc/code_wake.confexists, or./etc/code_wake.conf, then they will
be taken as configuration. If theCODE_WAKE_CONFIGenvironment variable is set then
this will override the config location.What you put in the configuration depends a lot on if it is a global config used my many
different apps, or just one, and having a configuration at all is entirely optional.A complete, canonical configuration might look like this:store:adapter:"code_wake_sql14_store,Sql14Store"config:"sqlite:////tmp/some_file.sqlite"environment:name:"production"app:name:"my_app"vsn:"1.2.3"stacktraces:include:from_exceptions:truefor_non_exceptions:falseThis might be appropriate for a simple app, as it configures the app name and version.
A more general config for use by many apps would certainly omit those.An environment is optional, app versions are optional, the stack trace configuration
will be defaulted, the app name will default to the executable path, so the only really
essential thing is the store adapter and configuration. If you don't want to use a config
you must provide at least that when you instantiate your process.Use without configIf you do not use a config, you should instantiate a store adapter yourself and pass
it to theProcessconstructor:importcode_wakefromcode_wake_sql14_storeimportSql14Storecwproc=code_wake.Process(store=Sql14Store("sqlite:////tmp/some_file.sqlite"))The process is a singleton, so subsequently when you want to log an event you can
simply do:importcode_wakecwproc=code_wake.Process()cwproc.log({"what":"ever"})Other process optionsWhen you instantiate theProcessfor the first time, there are other options which
would be good to use (if there isn't a configurartion to provide good values):importcode_wakefromcode_wake_sql14_storeimportSql14Storecwproc=code_wake.Process(app_name="my_app",app_vsn="1.2.3",env_name="production",store=Sql14Store("sqlite:////tmp/some_file.sqlite"),)Alsost_for_non_exceptionswill override the recording of stack traces for non exception
events andst_from_exceptionsfor exception events.Queue storeA "queue store" which can be mixed in with another store, can be used to turn any
store into one which always queues, instead of immediately adding the event. This
means that a process may be protected from being adversely affected by high latency
or unreliable stores. The events are processed by another thread, which commits them
to whatever actual storage you are using.For example:fromcode_wakeimportQueueStorefromcode_wake_sql14_storeimportSql14StoreclassSql14QueueStore(QueueStore,Sql14Store):passstore=Sql14QueueStore("sqlite:////tmp/some_file.sqlite")The store adapter used with the queue store must be thread safe and cross thread operable.
Sqlite for example, does not work cross threads when used with memory backing!Environment variablesApart fromCODE_WAKE_CONFIGto set the config, the following are supported
and will override any configuration file settings if set:| Environment variable            | Description |
+---------------------------------+-------------|
| CODE_WAKE_STORE_ADAPTER         | set the store adapter (module,class) |
| CODE_WAKE_STORE_CONFIG          | comma separated adapter params |
| CODE_WAKE_ENVIRONMENT           | name of the environment |
| CODE_WAKE_APP_NAME              | name of the application |
| CODE_WAKE_APP_VSN               | version of the application |
| CODE_WAKE_ST_FROM_EXCEPTIONS    | "true" or "false to turn exception stack traces on/off |
| CODE_WAKE_ST_FOR_NON_EXCEPTIONS | "true" or "false to turn other event stack traces on/off |