Revision 3 as of 2009-09-01 21:00:21

Clear message

Dev Week -- Writing Apport Package Hooks -- bdmurray -- Tue Sep 1st, 2009


(04:03:26 PM) bdmurray: Hi, my name is Brian Murray and I'm a member of the Ubuntu QA team.
(04:03:37 PM) bdmurray: I'm here today to talk about how you can get higher quality bug reports about packages that you care about.
(04:03:51 PM) bdmurray: You can do this by writing an apport hook for your particular package.
(04:04:20 PM) bdmurray: First off, what is apport?
(04:04:32 PM) bdmurray: Apport is a system which intercepts crashes right when they happen, in development releases of Ubuntu, and gathers useful information about the crash and the operating system environment.
(04:04:45 PM) bdmurray: Additionally, it is used as a mechanism to file non-crash bug reports about software so that we receive more detailed reports.
(04:05:00 PM) bdmurray: Let's look at a sample apport bug report -
(04:05:19 PM) bdmurray: The bzr package does not have an apport hook but some useful information is still collected.
(04:05:28 PM) bdmurray: We have the architecture, the release being used, the package version and the source package name.
(04:05:42 PM) bdmurray: Additionally, in the Dependencies.txt attachment we have information about the versions of packages upon which bzr depends.
(04:06:26 PM) bdmurray: Are there any questions about apport so far?
(04:07:37 PM) bdmurray: Okay then, carrying on.
(04:07:48 PM) bdmurray: So while all of that can be really useful an apport hook for a package allows us to gather specific information for that package.
(04:08:04 PM) bdmurray: For example, consider a bug report about usplash.
(04:08:17 PM) bdmurray: usplash has a dedicated configuration file, located at "/etc/usplash.conf", and this would be something quite helpful in debugging a usplash bug report but not very useful in other package bug reports.
(04:08:35 PM) bdmurray: Apport looks for package hooks in "/usr/share/apport/package-hooks/" for ones named after the package for which they will be used.
(04:08:46 PM) bdmurray: Looking in "/usr/share/apport/package-hooks/" lets take a look at the usplash hook - with the filename
(04:09:13 PM) bdmurray: The package hooks are written in python.
(04:09:33 PM) bdmurray: We can see that the hook imports the apport.hookutils module - "from apport.hookutils import *".
(04:09:47 PM) bdmurray: hookutils is a collection of readymade and safe functions for many commonly used things.  There are functions for attaching a file's contents, getting a command's output, grabbing hardware information and much more.
(04:10:09 PM) bdmurray: This package hook is using 'attach_file_if_exists' and 'attach_hardware'.
(04:10:19 PM) bdmurray: 'attach_file_if_exists' is pretty self explanatory but what does attach_hardware include?
(04:10:33 PM) bdmurray: Let's look at the hookutils module to find out.
(04:10:45 PM) bdmurray: You can use "python -c 'import apport.hookutils; help(apport.hookutils)'" or you can view it using codebrowse -
(04:11:42 PM) bdmurray: he 'attach_hardware' function starts at line 72.
(04:11:57 PM) bdmurray: As we can see it adds a wide variety of hardware information to a bug report which can be quite useful for some packages like the kernel and usplash!
(04:12:24 PM) bdmurray: Having the apport package hooks has reduced the amount of bug ping pong necessary to get information out of a bug reporter and having these convenience functions reduces the amount of work it takes to write a package hook.
(04:12:56 PM) bdmurray: In addition to 'attach_hardware' and 'attach_file_if_exists' other functions include: 'attach_conffiles', 'attach_dmesg', 'attach_alsa', 'command_output', 'recent_syslog', 'pci_devices' and 'attach_related_packages'.
(04:13:21 PM) bdmurray: In the event that you have a group of packages that would benefit from a shared convenience function, please file a bug about apport and include the function you'd like added.
(04:14:03 PM) bdmurray: Are there any questions so far?
(04:15:14 PM) bdmurray: < tormod> QUESTION: is there a way to present a question to the bug  reporter?
(04:15:36 PM) bdmurray: tormod: yes, there actually is and this is a new feature of apport I'll be getting to shorty.
(04:16:19 PM) bdmurray: shortly even ;-)
(04:16:40 PM) bdmurray: Back to the usplash hook, we can see that the usplash configuartion file is added like so "attach_file_if_exists(report, '/etc/usplash.conf', 'UsplashConf')".
(04:16:59 PM) bdmurray: This means that a bug reported about usplash using apport should have an attachment named 'UsplashConf' and it will contain the reporter's usplash.conf file.
(04:17:14 PM) bdmurray: Looking at we can see this actually isn't the case.
(04:17:52 PM) bdmurray: Because usplash.conf is only 4 or 5 lines it ends up getting put into the bug description.  However, most items end up getting added as attachments in Launchpad.
(04:18:22 PM) bdmurray: Regardless the information is still there and can help triaging the bug.
(04:18:36 PM) bdmurray: Now that we've covered what a hook can include lets's look at how to control when hooks are run.
(04:18:54 PM) bdmurray: In the totem hook, "", we can see there is a check to see if the hook was called due to a crash - "if report['ProblemType'] == 'Crash':".
(04:19:16 PM) bdmurray: If it is due to a crash the hook is not run.
(04:19:28 PM) bdmurray: If someone were reporting a bug, using ubuntu-bug or 'Help -> Report a Problem', the ProblemType would be Bug.
(04:19:42 PM) bdmurray: In this case the totem hook is only ran when the "ProblemType" is "Bug".
(04:20:03 PM) bdmurray: < thekorn> QUESTION: let's say I'm writing an apport hook which adds a  log file, should this hook automatically purge sensitive data,  what's best practice in such cases?
(04:21:10 PM) bdmurray: thekorn: let me find an example - I saw a hook that does some scrubbing recently
(04:23:13 PM) bdmurray: thekorn: there is one in mysql-dfsg-5.1
(04:23:54 PM) bdmurray:
(04:24:23 PM) bdmurray: you can see it is checking for the password in the configuration file and replaces it before attaching it to the report
(04:24:47 PM) bdmurray: I think this, scrubbing the data before uploading, is the best idea
(04:25:47 PM) bdmurray: Now to tormod's question ...
(04:25:55 PM) bdmurray: The totem hook is particularly interesting as it is utilizes interactive questions - which is a new feature in apport.
(04:26:04 PM) bdmurray: You can see how this works by executing "ubuntu-bug totem", but please don't actually report the bug! ;-)
(04:26:31 PM) bdmurray: The totem hook asks questions and runs tests to determine if the bug report is related to alsa, pulseaudio or codecs in gstreamer.
(04:26:43 PM) bdmurray: Well add of course totem itself.
(04:27:13 PM) bdmurray: The totem apport hook also sets the affected package appropriately.
(04:27:48 PM) bdmurray: The interactive questions can greatly reduce the amount of triaging work required and helps make the initial bug report much more complete.
(04:28:01 PM) bdmurray: More detailed information regarding how to use the hook user interface can be found in the python help for the available functions: "python -c 'import apport.ui; help(apport.ui.HookUI)'".
(04:29:26 PM) bdmurray: Are there any questions about the interactive questions or the convenience functions?
(04:34:25 PM) bdmurray: Now that we know a lot of what hooks can do, lets talk about how to write and test one.
(04:34:41 PM) bdmurray: After the last Ubuntu Developer Summit I compiled a list of packages that had recently received a fair number of bug reports and subsequently might benefit from an apport package hook.
(04:34:56 PM) bdmurray: That list can be found at
(04:35:18 PM) bdmurray: Let's take rhythmbox from that list and write a simple apport hook for it.
(04:35:44 PM) bdmurray: I say simple because I'm not entirely certain what would be useful but thought these things might be.
(04:36:32 PM) bdmurray: < andresmujica> QUESTION: What's  the purpose of the general-hooks   available at /usr/share/apport/general-hooks ?
(04:38:33 PM) bdmurray: andresmujica: these are always run.  For example if you look at the one you can see ifi certain criteria are met the bug reports are not filed.
(04:39:57 PM) bdmurray: And the checks to see if the package is an ubuntu one among other things.
(04:40:22 PM) bdmurray: The easiest way of writing and testing a package hook is to put one in "/usr/share/apport/package-hooks" named after the appropriate package.
(04:40:36 PM) bdmurray: I'll create one called "".
(04:40:47 PM) bdmurray: We'll import hookutils from apport and os, then in the add_info function we'll add the rhythmdb.xml file, if it exists, and gconf settings for rhythmbox.
(04:40:57 PM) bdmurray: The hook as written looks like
(04:41:35 PM) bdmurray: Its really only 2 or so lines of code but now we'll have some potentially useful information in every rhythmbox crash or bug report.
(04:41:51 PM) bdmurray: After I've put this file in "/usr/share/apport/package-hooks" I can test it using "ubuntu-bug".
(04:42:13 PM) bdmurray: After running "ubuntu-bug rhythmbox", apport presents the user with a dialog asking them if they want to send the problem report.
(04:42:28 PM) bdmurray: In this dialog box we can see the complete contents of the report and if our collected information was attached.
(04:42:46 PM) bdmurray: I see a key named rhythmdb.xml which contains the same as the one on my system and a key named GconfRhythbox which contains my gconf settings for rhythmbox.
(04:43:06 PM) bdmurray: contains the same information that is ;-)
(04:44:22 PM) bdmurray: If you look at the compiz hook,, you can see it includes a debugging portion so you can just execute it.  However, I personally find this harder to parse.
(04:44:39 PM) bdmurray: That's really all there is to writing and testing an apport hook!
(04:45:30 PM) bdmurray:  < andresmujica> QUESTION: Why and not just
(04:45:33 PM) bdmurray:              ?
(04:46:29 PM) bdmurray: andresmujica: this way any binary package produced by rhythmbox would have the hook run for it.
(04:46:51 PM) bdmurray: This is less of an issue with rhythmbox but makes a lot of sense with other packages.
(04:47:46 PM) bdmurray: Like evolution for example
(04:48:16 PM) bdmurray: thekorn: the evolution hook is also a good example of data scrubbing
(04:48:49 PM) bdmurray: In the event that you write a hook for a package that you can not upload or need help getting sponsored, please report a bug about the package missing a hook.
(04:49:01 PM) bdmurray: Then add the hook as a patch (or a merge proposal) and subscribe me, brian-murray, and the appropriate sponsor's team to the bug report.
(04:49:08 PM) bdmurray: I'll work to ensure that it gets uploaded.
(04:49:18 PM) bdmurray: If you need any further help the apport code is very well documented and there are a few wiki pages about it - and  Additionally, you can find me in the ubuntu-bugs channel.
(04:49:36 PM) bdmurray: < sbarthelemy> QUESTION: in which package should the new apport-hook go,  in apport or in rhythmbox?
(04:49:52 PM) bdmurray: apport hooks are distributed with the package that will use them
(04:50:11 PM) bdmurray: er, the package that will benefit from them
(04:50:35 PM) bdmurray: that's why I didn't have the mysql hook readily availabe as the package is not installed on my system
(04:51:13 PM) bdmurray: additionally, this make it easier for us as developers as we can just stick them in our packages and not have to muck with apport
(04:53:13 PM) bdmurray: < openweek4> QUESTION: will apport hooks work with 3rd party applications?
(04:54:27 PM) bdmurray: openweek4: I'm actually really not certain about that question.  If you look at the ubuntuone-client hook - bugs get reported to Launchpad but about the ubuntuone project.  So it might very well be possible.  However, apport would have to be able to communicate with the appropriate bug tracking system.
(04:54:54 PM) bdmurray: < sbarthelemy> QUESTION: the apport hook is expected to be included in  debian's own rhythmbox too?
(04:55:21 PM) bdmurray: sbarthelemy: most of the apport hooks are carried as a diff from what I have seen
(04:56:16 PM) bdmurray: Are there any more questions?
(04:59:29 PM) bdmurray: Alright well thanks for coming everyone and I hope this was informative.  I look forward to seeing some more apport hooks!