-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Breadcrumbs #210
feat: Breadcrumbs #210
Changes from all commits
66aa32e
3051584
3e96332
b13402b
397d2dc
093e314
0aec067
ebe0b55
76c3bc0
18790c5
276f9c0
3fc2324
346dadc
28f2dc9
5420798
34751e0
bdfe7c8
06127fe
ffe86ba
15f4120
62b342d
03a6ec1
5fee12a
fb7c68f
7021803
a92b586
73ae88d
fe75b49
b2def16
89c39af
61a5570
9d6fab3
4a4543a
a7c9e85
937615e
2284214
5db3977
add1c11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,10 @@ | ||
var config = require("config"); | ||
|
||
if (config.Raygun.Key === "YOUR_API_KEY") { | ||
console.error( | ||
"[Raygun4Node-Express-Sample] You need to set your Raygun API key in the config file", | ||
); | ||
process.exit(1); | ||
} | ||
|
||
// Setup Raygun | ||
var raygun = require("raygun"); | ||
var raygunClient = new raygun.Client().init({ | ||
apiKey: config.Raygun.Key, | ||
}); | ||
|
||
var express = require("express"); | ||
var path = require("path"); | ||
var logger = require("morgan"); | ||
var cookieParser = require("cookie-parser"); | ||
var bodyParser = require("body-parser"); | ||
var sassMiddleware = require("node-sass-middleware"); | ||
var raygunClient = require("./raygun.client"); | ||
|
||
var routes = require("./routes/index"); | ||
var users = require("./routes/users"); | ||
|
@@ -34,6 +20,9 @@ raygunClient.user = function (req) { | |
app.set("views", path.join(__dirname, "views")); | ||
app.set("view engine", "ejs"); | ||
|
||
// Add the Raygun breadcrumb Express handler | ||
app.use(raygunClient.expressHandlerBreadcrumbs); | ||
|
||
// uncomment after placing your favicon in /public | ||
// app.use(favicon(__dirname + '/public/favicon.ico')); | ||
Comment on lines
26
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The favicon was missing in the /public folder, this should be cleaned up, or we need a favicon. I'll see if we can get a raygun one. |
||
app.use(logger("dev")); | ||
|
@@ -58,7 +47,9 @@ app.use(express.static(path.join(__dirname, "public"))); | |
app.use("/", routes); | ||
app.use("/users", users); | ||
|
||
// Add the Raygun Express handler | ||
// Add the Raygun error Express handler | ||
app.use(raygunClient.expressHandler); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that it (express naming usage) is too tightly coupled at the moment. But until we see popular requests for other frameworks, I'm happy with the current implementation until we implement support for other frameworks. I think the new approach looks good (moving to But does a standalone node app need breadcrumbs tracked manually? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, users would need to manually add breadcrumbs. The |
||
|
||
raygunClient.addBreadcrumb("Express Server started!"); | ||
|
||
module.exports = app; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var config = require("config"); | ||
|
||
if (config.Raygun.Key === "YOUR_API_KEY") { | ||
console.error( | ||
"[Raygun4Node-Express-Sample] You need to set your Raygun API key in the config file", | ||
); | ||
process.exit(1); | ||
} | ||
|
||
// Setup Raygun | ||
var raygun = require("raygun"); | ||
var raygunClient = new raygun.Client().init({ | ||
apiKey: config.Raygun.Key, | ||
}); | ||
|
||
module.exports = raygunClient; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title><%= title %></title> | ||
<link rel='stylesheet' href='/stylesheets/style.css' /> | ||
</head> | ||
<body> | ||
<h1><%= title %></h1> | ||
<p><%= title %></p> | ||
<div> | ||
<%= body %> | ||
</div> | ||
|
||
<div> | ||
<a href="/">Back to index</a> | ||
</div> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Request } from "express"; | ||
import type { Breadcrumb } from "./types"; | ||
import { getBreadcrumbs } from "./raygun.breadcrumbs"; | ||
|
||
const debug = require("debug")("raygun"); | ||
|
||
/** | ||
* Parses an ExpressJS Request and adds it to the breadcrumbs store | ||
* @param request | ||
*/ | ||
export function addRequestBreadcrumb(request: Request) { | ||
const crumbs = getBreadcrumbs(); | ||
|
||
if (!crumbs) { | ||
debug( | ||
"[raygun.breadcrumbs.express.ts] Add request breadcrumb skip, no store!", | ||
); | ||
return; | ||
} | ||
|
||
const internalCrumb: Breadcrumb = { | ||
miquelbeltran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
category: "http", | ||
message: `${request.method} ${request.url}`, | ||
level: "info", | ||
timestamp: Number(new Date()), | ||
type: "request", | ||
}; | ||
|
||
debug( | ||
`[raygun.breadcrumbs.express.ts] recorded request breadcrumb: ${internalCrumb}`, | ||
); | ||
|
||
crumbs.push(internalCrumb); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"used" instead of "user"