diff --git a/.gitignore b/.gitignore index 7e44927..a625b23 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ pids logs results +docs/_build +docs/doctrees + node_modules npm-debug.log diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1e6464a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "docs/_sentryext"] + path = docs/_sentryext + url = https://github.com/getsentry/sentry-doc-support diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f378b15 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +develop: update-submodules + npm install . + +update-submodules: + git submodule init + git submodule update + +docs: + cd docs; $(MAKE) html + +docs-live: + while true; do \ + sleep 2; \ + $(MAKE) docs; \ + done + +clean: + rm -rf docs/html + +.PHONY: develop update-submodules docs docs-live clean diff --git a/README.md b/README.md index e863f8e..8c846a5 100644 --- a/README.md +++ b/README.md @@ -1,248 +1,9 @@ -# Raven [![Build Status](https://secure.travis-ci.org/getsentry/raven-node.png?branch=master)](http://travis-ci.org/getsentry/raven-node) -**Node v0.12/iojs compatible** +# raven-node [![Build Status](https://travis-ci.org/getsentry/raven-node.svg?branch=master)](https://travis-ci.org/getsentry/raven-node) -Log errors and stack traces in [Sentry](http://getsentry.com/) from within your Node.js applications. Includes middleware support for [Connect](http://www.senchalabs.org/connect/)/[Express](http://expressjs.com/). +raven-node is a Node.js client for [Sentry](https://www.getsentry.com/). -All processing and sending happens asynchronously to not slow things down if/when Sentry is down or slow. +## Resources -## Compatibility - * 0.8.x - * 0.10.x - * 0.12.x - * iojs - -Raven 0.7+ requires Sentry 6.4+ - -## Installation -``` -$ npm install raven -``` - -## Methods -```javascript -new raven.Client(String dsn[, Object options]) -client.captureMessage(String message[[, Object options], Function callback]) -client.captureError(Error error[[, Object options], Function callback]) -client.captureQuery(String query[[, String type], Function callback]) -``` - -## Basic Usage -```javascript -var raven = require('raven'); -var client = new raven.Client('{{ SENTRY_DSN }}'); - -client.captureMessage('Hello, world!'); -``` -You can specify a level in the second optional parameter. Default level is `error` - - -**Sentry is aware of five different levels:** - * debug (the least serious) - * info - * warning - * error - * fatal (the most serious) - -```javascript -var raven = require('raven'); -var client = new raven.Client('{{ SENTRY_DSN }}', {level: 'warning'}); - -client.captureMessage('Another message') -``` - -**Passing extra HTTP transport options** -```javascript -var raven = require('raven'); -var client = new raven.Client('{{ SENTRY_DSN }}', {transport: new raven.transports.HTTPSTransport({rejectUnauthorized: false})}); -``` - -**Adding extra info to an event** -```javascript -var raven = require('raven'); - -var client = new raven.Client('{{ SENTRY_DSN }}'); - -client.captureMessage("Another message", {extra: {'key': 'value'}}) -``` - -**Adding tags to an event** -```javascript -var raven = require('raven'); - -var client = new raven.Client('{{ SENTRY_DSN }}'); - -client.captureMessage("Another message", {tags: {'key': 'value'}}) -``` - -## Logging an error -```javascript -client.captureError(new Error('Broke!')); -``` - -## Logging a query -```javascript -client.captureQuery('SELECT * FROM `awesome`', 'mysql'); -``` - -## Sentry Identifier -```javascript -client.captureMessage('Hello, world!', function(result) { - console.log(client.getIdent(result)); -}); -``` - -```javascript -client.captureError(new Error('Broke!'), function(result) { - console.log(client.getIdent(result)); -}); -``` - -__Note__: `client.captureMessage` will also return the result directly without the need for a callback, such as: `var result = client.captureMessage('Hello, world!');` - -## Events -If you really care if the event was logged or errored out, Client emits two events, `logged` and `error`: - -```javascript -client.on('logged', function(){ - console.log('Yay, it worked!'); -}); -client.on('error', function(e){ - console.log('oh well, Sentry is broke.'); -}) -client.captureMessage('Boom'); -``` - -### Error Event -The event error is augmented with the original Sentry response object as well as the response body and statusCode for easier debugging. - -```javascript -client.on('error', function(e){ - console.log(e.reason); // raw response body, usually contains a message explaining the failure - console.log(e.statusCode); // status code of the http request - console.log(e.response); // entire raw http response object -}); -``` - -## Environment variables -### SENTRY_DSN -Optionally declare the DSN to use for the client through the environment. Initializing the client in your app won't require setting the DSN. - -### SENTRY_NAME -Optionally set the name for the client to use. [What is name?](http://raven.readthedocs.org/en/latest/config/index.html#name) - -### SENTRY_RELEASE -Optionally set the application release version for the client to use, this is usually a Git SHA hash. - -## Catching global errors -For those times when you don't catch all errors in your application. ;) - -```javascript -client.patchGlobal(); -// or -raven.patchGlobal(client); -// or -raven.patchGlobal('{{ SENTRY_DSN }}'); -``` - -It is recommended that you don't leave the process running after receiving an `uncaughtException` (http://nodejs.org/api/process.html#process_event_uncaughtexception), so an optional callback is provided to allow you to hook in something like: - -```javascript -client.patchGlobal(function() { - console.log('Bye, bye, world.'); - process.exit(1); -}); -``` - -The callback is called **after** the event has been sent to the Sentry server. - -## Integrations -### Connect/Express middleware -The Raven middleware can be used as-is with either Connect or Express in the same way. - -#### Connect and Express -```javascript -var connect = require('connect'); -function mainHandler(req, res) { - throw new Error('Broke!'); -} -function onError(err, req, res, next) { - // The error id is attached to `res.sentry` to be returned - // and optionally displayed to the user for support. - res.statusCode = 500; - res.end(res.sentry+'\n'); -} -connect( - // Should be the first item listed - raven.middleware.connect.requestHandler('{{ SENTRY_DSN }}'), - - connect.bodyParser(), - connect.cookieParser(), - mainHandler, - - // Should come before any other error middleware - raven.middleware.connect.errorHandler('{{ SENTRY_DSN }}'), - onError, // optional error handler if you want to display the error id to a user -).listen(3000); -``` - -#### Express -```javascript -var app = require('express')(); - -app.get('/', function mainHandler(req, res) { - throw new Error('Broke!'); -}); - -// Should be the first item listed -app.use(raven.middleware.express.requestHandler('{{ SENTRY_DSN }}')); - -// Should come before any other error middleware -app.use(raven.middleware.express.errorHandler('{{ SENTRY_DSN }}')); -app.use(onError); // optional error handler if you want to display the error id to a user - -app.listen(3000); -``` - -__Note__: `raven.middleware.express` or `raven.middleware.connect` *must* be added to the middleware stack *before* any other error handling middlewares or there's a chance that the error will never get to Sentry. - -## Coffeescript -In order to use raven-node with coffee-script or another library which overwrites -Error.prepareStackTrace you might run into the exception "Traceback does not support Error.prepareStackTrace being defined already." - -In order to not have raven-node (and the underlying raw-stacktrace library) require -Traceback you can pass your own stackFunction in the options. For example: - -```coffeescript -client = new raven.Client('{{ SENTRY_DSN }}', { stackFunction: {{ Your stack function }}}); -``` - -So for example: -```coffeescript -client = new raven.Client('{{ SENTRY_DSN }}', { - stackFunction: Error.prepareStackTrace -}); -``` - -## Pre-processing data -Pass the `dataCallback` configuration value: - -```javascript -client = new raven.Client('{{ SENTRY_DSN }}', { - dataCallback: function(data) { - delete data.request.env; - return data; - } -}); -``` - -## Disable Raven -Pass `false` as the DSN (or any falsey value). - -```javascript -client = new raven.Client(process.env.NODE_ENV === 'production' && '{{ SENTRY_DSN }}') -``` - -__Note__: We don't infer this from `NODE_ENV` automatically anymore. It's up to you to implement whatever logic you'd like. - -## Support -You can find me on IRC. I troll in `#sentry` on `freenode`. +* [Documentation](https://docs.getsentry.com/hosted/clients/node/) +* [Bug Tracker](https://github.com/getsentry/raven-node/issues) +* [IRC](irc://chat.freenode.net/sentry) (chat.freenode.net, #sentry) diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..60f8b84 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,153 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/raven-js.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/raven-js.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/raven-js" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/raven-js" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/_sentryext b/docs/_sentryext new file mode 160000 index 0000000..9297326 --- /dev/null +++ b/docs/_sentryext @@ -0,0 +1 @@ +Subproject commit 92973260c04c0da73cb4a972cf71895247481c45 diff --git a/docs/coffeescript.rst b/docs/coffeescript.rst new file mode 100644 index 0000000..9190999 --- /dev/null +++ b/docs/coffeescript.rst @@ -0,0 +1,24 @@ +CoffeeScript +============ + +In order to use raven-node with coffee-script or another library which overwrites +Error.prepareStackTrace you might run into the exception "Traceback does not +support Error.prepareStackTrace being defined already." + +In order to not have raven-node (and the underlying raw-stacktrace library) require +Traceback you can pass your own stackFunction in the options. For example: + +.. code-block:: coffeescript + + client = new raven.Client('___DSN___', { + stackFunction: {{ Your stack function }} + }); + + +So for example: + +.. code-block:: coffeescript + + client = new raven.Client('___DSN___', { + stackFunction: Error.prepareStackTrace + }); diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..3dcac45 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,249 @@ +# -*- coding: utf-8 -*- +# +# raven-node documentation build configuration file, created by +# sphinx-quickstart on Mon Jan 21 21:04:27 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os, datetime + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'raven-node' +copyright = u'%s, Sentry' % datetime.date.today().year + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# + +import json +# The full version, including alpha/beta/rc tags. +release = json.load(open('../package.json'))['version'] +# The short X.Y version. +version = release.rsplit('.', 1)[0] + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'raven-nodedoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'raven-node.tex', u'raven-node Documentation', + u'Matt Robenolt', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'raven-js', u'raven-js Documentation', + [u'Sentry'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'raven-node', u'raven-node Documentation', + u'Sentry', 'raven-node', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +if os.environ.get('SENTRY_FEDERATED_DOCS') != '1': + sys.path.insert(0, os.path.abspath('_sentryext')) + import sentryext + sentryext.activate() diff --git a/docs/config.rst b/docs/config.rst new file mode 100644 index 0000000..4b68486 --- /dev/null +++ b/docs/config.rst @@ -0,0 +1,65 @@ +Configuration +============= + +Configuration is passed as the second argument of the ``raven.Client`` constructor: + +.. code-block:: javascript + + var raven = require("raven"); + + new raven.Client(String dsn[, Object options]) + +Optional settings +----------------- + +.. describe:: logger + + The name of the logger used by Sentry. Default: ``''`` + + .. code-block:: javascript + + { + logger: 'default' + } + +.. describe:: release + + Track the version of your application in Sentry. + + .. code-block:: javascript + + { + release: '721e41770371db95eee98ca2707686226b993eda' + } + + Can also be defined with ``Raven.setReleaseContext('721e41770371db95eee98ca2707686226b993eda')``. + +.. describe:: dataCallback + + A function that allows mutation of the data payload right before being + sent to Sentry. + + .. code-block:: javascript + + { + dataCallback: function(data) { + // remove references to the environment + delete data.request.env; + return data; + } + } + +Environment Variables +--------------------- + +.. describe:: SENTRY_DSN + + Optionally declare the DSN to use for the client through the environment. Initializing the client in your app won't require setting the DSN. + +.. describe:: SENTRY_NAME + + Optionally set the name for the client to use. [What is name?](http://raven.readthedocs.org/en/latest/config/index.html#name) + +.. describe:: SENTRY_RELEASE + + Optionally set the application release version for the client to use, this is usually a Git SHA hash. diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..188e2a5 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,75 @@ +.. sentry:edition:: self + + raven-node + ========== + +.. sentry:edition:: hosted, on-premise + + .. class:: platform-js + + Node.js + ======= + +raven-node is a Sentry's officially supported Node.js SDK. + +**Note**: If you're using JavaScript in the browser, you'll need +`raven-js `_. + +Installation +------------ + +Raven is distributed via ``npm``: + +.. code-block:: bash + + $ npm install raven --save + +Configuring the Client +---------------------- + +Now need to configure your application: + +.. code-block:: javascript + + var client = new raven.Client('___DSN___'); + +At this point you'll likely need to integrate it into your application via +middleware or another integration mechanism. Take a look at our documentation +on :doc:`integrations` and :doc:`usage`. + +Reporting Errors +---------------- + +The simplest way, is to try and explicitly capture and report potentially +problematic code with a ``try...catch`` block and +``Raven.captureException``. + +.. code-block:: javascript + + try { + doSomething(a[0]) + } catch(e) { + client.captureException(e) + } + +Deep Dive +--------- + +For more detailed information about how to get most out of Raven.js there +is additional documentation available that covers all the rest: + +.. toctree:: + :maxdepth: 2 + :titlesonly: + + install + plugins + config + usage + integrations + coffeescript + +Resources: + +* `Bug Tracker `_ +* `Github Project `_ diff --git a/docs/install.rst b/docs/install.rst new file mode 100644 index 0000000..b514f7b --- /dev/null +++ b/docs/install.rst @@ -0,0 +1,23 @@ +Installation +============ + +Raven is distributed via ``npm``: + +.. code-block:: bash + + $ npm install raven + +Likely you'll want to add it to your ``package.json``:: + +.. code-block:: bash + + $ npm install raven --save + + +Compatibility +------------- + + * 0.8.x + * 0.10.x + * 0.12.x + * iojs diff --git a/docs/integrations/connect.rst b/docs/integrations/connect.rst new file mode 100644 index 0000000..cda7563 --- /dev/null +++ b/docs/integrations/connect.rst @@ -0,0 +1,33 @@ +Connect +======= + +.. code-block:: javascript + + var connect = require('connect'); + var raven = require('raven'); + + function mainHandler(req, res) { + throw new Error('Broke!'); + } + + function onError(err, req, res, next) { + // The error id is attached to `res.sentry` to be returned + // and optionally displayed to the user for support. + res.statusCode = 500; + res.end(res.sentry+'\n'); + } + + connect( + // The request handler be the first item + raven.middleware.connect.requestHandler('___DSN___'), + + connect.bodyParser(), + connect.cookieParser(), + mainHandler, + + // The error handler must be before any other error middleware + raven.middleware.connect.errorHandler('___DSN___'), + + // Optional fallthrough error handler + onError, + ).listen(3000); diff --git a/docs/integrations/express.rst b/docs/integrations/express.rst new file mode 100644 index 0000000..28910ae --- /dev/null +++ b/docs/integrations/express.rst @@ -0,0 +1,29 @@ +Express +======= + +.. code-block:: javascript + + var app = require('express')(); + var raven = require('raven'); + + function onError(err, req, res, next) { + // The error id is attached to `res.sentry` to be returned + // and optionally displayed to the user for support. + res.statusCode = 500; + res.end(res.sentry+'\n'); + } + + app.get('/', function mainHandler(req, res) { + throw new Error('Broke!'); + }); + + // The request handler be the first item + app.use(raven.middleware.express.requestHandler('{{ SENTRY_DSN }}')); + + // The error handler must be before any other error middleware + app.use(raven.middleware.express.errorHandler('{{ SENTRY_DSN }}')); + + // Optional fallthrough error handler + app.use(onError); + + app.listen(3000); diff --git a/docs/integrations/index.rst b/docs/integrations/index.rst new file mode 100644 index 0000000..ab21692 --- /dev/null +++ b/docs/integrations/index.rst @@ -0,0 +1,8 @@ +Integrations +============ + +.. toctree:: + :maxdepth: 1 + + connect + express diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..13e2848 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,190 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\raven-js.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\raven-js.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +:end diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 0000000..c7028a2 --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,147 @@ +Usage +===== + +.. code-block:: javascript + + var raven = require('raven'); + var client = new raven.Client('___DSN___'); + + client.captureMessage('Hello, world!'); + +Capturing Messages +------------------ + +.. code-block:: javascript + + Raven.captureMessage('Broken!') + +Configuring the HTTP Transport +------------------------------ + +.. code-block:: javascript + + var client = new raven.Client('___DSN___', { + transport: new raven.transports.HTTPSTransport({rejectUnauthorized: false}) + }); + +Adding Context +-------------- + +You can use the ``extra`` key for basic context: + +.. code-block:: javascript + + client.captureError(new Error('Uh oh!'), { + extra: {'key': 'value'} + }); + +And the ``tags`` key for indexed tagging: + +.. code-block:: javascript + + client.captureError(new Error('Uh oh!'), { + tags: {'key': 'value'} + }); + +Specifying Levels +----------------- + +You can specify a level in the second optional parameter. The default level is `error`. + +Sentry is aware of five different levels: + +* debug (the least serious) +* info +* warning +* error +* fatal (the most serious) + +.. code-block:: javascript + + var client = new raven.Client('___DSN___', {level: 'warning'}); + + client.captureError(new Error('Uh oh!')); + +Event IDs +--------- + +To make referencing an event easy (both by the developer and customer), you can grab +the event ID using a callback: + + +.. code-block:: javascript + + client.captureMessage('Hello, world!', function(result) { + console.log(client.getIdent(result)); + }); + +.. code-block:: javascript + + client.captureError(new Error('Broke!'), function(result) { + console.log(client.getIdent(result)); + }); + + +.. note:: + + ``captureMessage`` will also return the result directly without the need for a callback, + such as: ``var result = client.captureMessage('Hello, world!');`` + +Global Error Handler +-------------------- + +It is recommended that you install the global error handler, which will ensure any exceptions +that are unhandled will get reported: + +.. code-block:: javascript + + client.patchGlobal(); + // or + raven.patchGlobal(client); + // or + raven.patchGlobal('___DSN___'); + +Generally you don't want to leave the process running after receiving an +`uncaughtException` (http://nodejs.org/api/process.html#process_event_uncaughtexception), +so an optional callback is provided to allow you to hook in something like: + +.. code-block:: javascript + + client.patchGlobal(function() { + console.log('Bye, bye, world.'); + process.exit(1); + }); + +The callback is called **after** the event has been sent to the Sentry server. + +Events +------ + +If you really care if the event was logged or errored out, Client emits two events, `logged` and `error`: + +.. code-block:: javascript + + client.on('logged', function(){ + console.log('Yay, it worked!'); + }); + + client.on('error', function(e){ + // The event contains information about the failure: + // e.reason -- raw response body + // e.statusCode -- response status code + // e.response -- raw http response object + + console.log('uh oh, couldnt record the event'); + }) + + client.captureMessage('Boom'); + + +Disable Raven +------------- + +Passing any falsey value as the DSN will disable sending events upstream: + +.. code-block:: javascript + + client = new raven.Client(process.env.NODE_ENV === 'production' && '___DSN___')