Skip to content

Commit

Permalink
Merge pull request #27 from pablo-mayrgundter/server-refactor
Browse files Browse the repository at this point in the history
Add sentry tracing handler, 100% sampling.
  • Loading branch information
pablo-mayrgundter authored Sep 28, 2023
2 parents 5258720 + 20460c1 commit 7222246
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
Binary file modified server-render.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const WARN = 2 // Use this as default for prod. Should never see these m
export const INFO = 1
export const DEBUG = 0
/* eslint-enable no-unused-vars */
let DEBUG_LEVEL = WARN
let DEBUG_LEVEL = INFO


/**
Expand Down
19 changes: 18 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,25 @@ const port = 8001

// Initialize and enable Sentry middleware
// It must be the first middleware in the stack
Sentry.init()
Sentry.init({
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Sentry.Integrations.Express({
// to trace all requests to the default router
app,
// alternatively, you can specify the routes you want to trace:
// router: someRouter,
}),
],
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
})
app.use(Sentry.Handlers.requestHandler())
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler())

// Enable JSON request body middleware
app.use(express.json())
Expand Down
10 changes: 6 additions & 4 deletions src/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,25 @@ export function parseUrl(url) {

const baseUrl = url.origin == 'null' ? url : new URL(url.pathname, url.origin)
const baseUrlStr = baseUrl.toString()
// console.log('matching:', baseUrlStr)
matcher(
baseUrlStr,
/https?:\/\/github.com\/(?<org>[\w-]+)\/(?<repo>[\w-]+)\/blob\/(?<ref>[\w-]+)\/(?<path>[\w\/.-]+)/
/https?:\/\/github.com\/(?<org>[\w%.-]+)\/(?<repo>[\w%.-]+)\/blob\/(?<ref>[\w%.-]+)\/(?<path>[\w\/%.-]+)/
)
.then((match) => {
parsed.type = 'vcs:github'
const {org, repo, ref, path} = match.groups
parsed.type = 'vcs:github'
parsed.target = {
organization: org,
repository: repo,
ref: ref,
url: new URL(`/${org}/${repo}/${ref}/${path}`, 'https://raw.githubusercontent.com')
}
})
.or(/\/share\/v\/gh\/(?<org>[\w-]+)\/(?<repo>\w+)\/(?<ref>\w+)\/(?<path>[\w\/.]+)/)
.or(/\/share\/v\/gh\/(?<org>[\w.-]+)\/(?<repo>[\w.-]+)\/(?<ref>[\w.-]+)\/(?<path>[\w\/%.-]+)/)
.then((match) => {
parsed.type = 'vcs:github'
const {org, repo, ref, path} = match.groups
parsed.type = 'vcs:github'
parsed.target = {
organization: org,
repository: repo,
Expand All @@ -68,6 +69,7 @@ export function parseUrl(url) {
}
})
.or(() => {
// TODO(pablo): this case is buggy/not being called
parsed.type = 'url'
parsed.target = {
url: parsed.original
Expand Down
60 changes: 60 additions & 0 deletions src/urls.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {parseUrl} from './urls.js'


describe('parseUrl', () => {
it('parses bldrs index.ifc', () => {
const url = new URL('https://bldrs.ai/share/v/p/index.ifc#c:-133.022,131.828,161.85,-38.078,22.64,-2.314')
const converted = new URL('https://raw.githubusercontent.com/bldrs-ai/Share/main/public/index.ifc')
const parsed = parseUrl(url)
expect(parsed).toStrictEqual({
original: url,
type: 'vcs:github',
target: {
organization: 'bldrs-ai',
repository: 'Share',
ref: 'main',
url: converted
},
params: { c: '-133.022,131.828,161.85,-38.078,22.64,-2.314' }
})
})


it('parses bldrs index.ifc', () => {
const url = new URL('https://bldrs.ai/share/v/gh/Swiss-Property-AG/Momentum-Public/main/Momentum.ifc#c:-38.64,12.52,35.4,-5.29,0.94,0.86')
const converted = new URL('https://raw.githubusercontent.com/Swiss-Property-AG/Momentum-Public/main/Momentum.ifc')
const parsed = parseUrl(url)
expect(parsed).toStrictEqual({
original: url,
type: 'vcs:github',
target: {
organization: 'Swiss-Property-AG',
repository: 'Momentum-Public',
ref: 'main',
url: converted
},
params: { c: '-38.64,12.52,35.4,-5.29,0.94,0.86' }
})
})


it('parses bldrs index.ifc', () => {
const url = new URL('https://github.com/buildingSMART/IFC/blob/master/Examples/Building%20element%20standard%20case/Examples/Wall%20standard%20case/File.ifc')
const converted = new URL('https://raw.githubusercontent.com/buildingSMART/IFC/master/Examples/Building%20element%20standard%20cas\
e/Examples/Wall%20standard%20case/File.ifc')
const parsed = parseUrl(url)
expect(parsed).toStrictEqual({
original: url,
type: 'vcs:github',
target: {
organization: 'buildingSMART',
repository: 'IFC',
ref: 'master',
url: converted
},
params: {
"": undefined,
},
})
})
})

0 comments on commit 7222246

Please sign in to comment.