Package: nameko-eventlog-dispatcher
Namekodependency provider that dispatches log data usingEvents(Pub-Sub).UsageDispatching event log dataInclude theEventLogDispatcherdependency in your service class:fromnameko.rpcimportrpcfromnameko_eventlog_dispatcherimportEventLogDispatcherclassFooService:name='foo'eventlog_dispatcher=EventLogDispatcher()@rpcdeffoo_method(self):self.eventlog_dispatcher('foo_event_type',{'value':1},metadata={'meta':2})Callingfoo_methodwill dispatch an event from thefooservice
withlog_eventas the event type. Howeverfoo_event_typewill be
the event type stored as part of the event metadata.event_type,event_data(optional) andmetadata(optional)
can be provided as arguments. Bothevent_dataandmetadatamust
be dictionaries and contain JSON serializable data.Then, anyNamekoservice will be able to handle this event.fromnameko.eventsimportevent_handlerclassBarService:name='bar'@event_handler('foo','log_event')deffoo_log_event_handler(self,body):"""`body` will contain the event log data."""Capturing log data when entrypoints are firedEnable auto capture event logs in yourNamekoconfiguration file:# config.yamlEVENTLOG_DISPATCHER:auto_capture:trueentrypoints_to_exclude:[]event_type:log_eventAll the attributes above are optional and only used to override their
default values.Withauto_captureset totrue, aNamekoevent will be dispatched
every time an entrypoint is fired:They can also be handled by listeninglog_eventevents from the
service dispatching them.entrypoint_firedwill be the event type stored as part of the
event metadata.Only entrypoints listed in theENTRYPOINT_TYPES_TO_LOGclass
attribute will be logged.entrypoints_to_excludecan be used to provide a list of entrypoint
method names to exclude when firing events automatically.event_typecan be added to the config to override the defaultNamekoevent type used to dispatch this kind of events.Format of the event log dataThis is the format of the event log data:{"service_name":"foo","entrypoint_protocol":"Rpc","entrypoint_name":"foo_method","call_id":"foo.foo_method.d7e907ee-9425-48a6-84e6-89db19e3ce50","call_stack":["standalone_rpc_proxy.call.3f349ea4-ed3e-4a3b-93d0-a36fbf928ecb","bla.bla_method.21d623b4-edc4-4232-9957-4fad72533b75","foo.foo_method.d7e907ee-9425-48a6-84e6-89db19e3ce50"],"event_type":"foo_event_type",# "entrypoint_fired", ..."timestamp":"2017-06-12T13:48:16+00:00","meta":2,# extra information provided as "metadata""data":{"value":1}# extra information provided as "event_data"}Thedataattribute will contain the event data that was provided as
an argument for theevent_dataparameter when dispatching the event.Ifmetadatawas provided, then its elements will be included as top
level attributes in the event log data.TestsIt is assumed thatRabbitMQis up and running on the default URIguest:guest@localhostand uses the default ports. There is a
Makefile target to run a RabbitMQ docker containers locally using the
default ports and configuration:$makedocker-rabbitmq-runTo run the tests locally:$# Create/activate a virtual environment$pipinstalltox$toxThere are other Makefile targets to run the tests, but extra
dependencies will have to be installed:$pipinstall-U--editable".[dev]"$maketest$makecoverageA different RabbitMQ URI can be provided overriding the following
environment variables:RABBIT_CTL_URIandAMQP_URI.Additionalpytestparameters can be also provided using theARGSvariable:$maketestRABBIT_CTL_URI=http://guest:guest@dockermachine:15673AMQP_URI=amqp://guest:guest@dockermachine:5673ARGS='-x -vv --disable-pytest-warnings'$makecoverageRABBIT_CTL_URI=http://guest:guest@dockermachine:15673AMQP_URI=amqp://guest:guest@dockermachine:5673ARGS='-x -vv --disable-pytest-warnings'Nameko supportThe followingNamekoversions are supported:2.xseries:2.12,2.13,2.14ChangelogConsult theCHANGELOGdocument for fixes and enhancements of each version.LicenseThe MIT License. SeeLICENSEfor details.