-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(google-cloud): Add @sentry/google-cloud package #10993
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
10555cf
feat(google-cloud): Add @sentry/google-cloud package
AbhiPrasad 763c16d
use new package.json exports
AbhiPrasad d53f922
restructure package json exports
AbhiPrasad f5f595e
use node instead of node-experimental
AbhiPrasad 522949a
fix tests
AbhiPrasad 709c313
remove migration note
AbhiPrasad e0d5af2
clean up exports
AbhiPrasad b3c9fc5
add get root span
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
}, | ||
extends: ['../../.eslintrc.js'], | ||
rules: { | ||
'@sentry-internal/sdk/no-optional-chaining': 'off', | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['scripts/**/*.ts'], | ||
parserOptions: { | ||
project: ['../../tsconfig.dev.json'], | ||
}, | ||
}, | ||
{ | ||
files: ['test/**'], | ||
parserOptions: { | ||
sourceType: 'module', | ||
}, | ||
}, | ||
], | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Copyright (c) 2024 Sentry (https://sentry.io) and individual contributors. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<p align="center"> | ||
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank"> | ||
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84"> | ||
</a> | ||
</p> | ||
|
||
# Official Sentry SDK for Google Cloud Functions | ||
|
||
## Links | ||
|
||
- [Official SDK Docs](https://docs.sentry.io/) | ||
- [TypeDoc](http://getsentry.github.io/sentry-javascript/) | ||
|
||
## General | ||
|
||
This package is a wrapper around `@sentry/node`, with added functionality related to various Serverless solutions. All | ||
methods available in `@sentry/node` can be imported from `@sentry/google-cloud`. | ||
|
||
To use this SDK, call `Sentry.init(options)` at the very beginning of your JavaScript file. | ||
|
||
```javascript | ||
import * as Sentry from '@sentry/google-cloud'; | ||
|
||
Sentry.init({ | ||
dsn: '__DSN__', | ||
tracesSampleRate: 1.0, | ||
// ... | ||
}); | ||
|
||
// For HTTP Functions: | ||
|
||
exports.helloHttp = Sentry.wrapHttpFunction((req, res) => { | ||
throw new Error('oh, hello there!'); | ||
}); | ||
|
||
// For Background Functions: | ||
|
||
exports.helloEvents = Sentry.wrapEventFunction((data, context, callback) => { | ||
throw new Error('oh, hello there!'); | ||
}); | ||
|
||
// For CloudEvents: | ||
|
||
exports.helloEvents = Sentry.wrapCloudEventFunction((context, callback) => { | ||
throw new Error('oh, hello there!'); | ||
}); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../jest/jest.config.js'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"name": "@sentry/google-cloud", | ||
"version": "8.0.0-alpha.2", | ||
"description": "Official Sentry SDK for Google Cloud Functions", | ||
"repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/google-cloud", | ||
"author": "Sentry", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=14.18" | ||
}, | ||
"files": [ | ||
"cjs", | ||
"esm", | ||
"types", | ||
"types-ts3.8" | ||
], | ||
"main": "build/cjs/index.js", | ||
"module": "build/esm/index.js", | ||
"types": "build/types/index.d.ts", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": { | ||
"types": "./build/types/index.d.ts", | ||
"default": "./build/esm/index.js" | ||
}, | ||
"require": { | ||
"types": "./build/types/index.d.ts", | ||
"default": "./build/cjs/index.js" | ||
} | ||
} | ||
}, | ||
"typesVersions": { | ||
"<4.9": { | ||
"build/types/index.d.ts": [ | ||
"build/types-ts3.8/index.d.ts" | ||
] | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@sentry/core": "8.0.0-alpha.2", | ||
"@sentry/node": "8.0.0-alpha.2", | ||
"@sentry/types": "8.0.0-alpha.2", | ||
"@sentry/utils": "8.0.0-alpha.2", | ||
"@types/express": "^4.17.14" | ||
}, | ||
"devDependencies": { | ||
"@google-cloud/bigquery": "^5.3.0", | ||
"@google-cloud/common": "^3.4.1", | ||
"@google-cloud/functions-framework": "^1.7.1", | ||
"@google-cloud/pubsub": "^2.5.0", | ||
"@types/node": "^14.6.4", | ||
"find-up": "^5.0.0", | ||
"google-gax": "^2.9.0", | ||
"nock": "^13.0.4", | ||
"npm-packlist": "^2.1.4" | ||
}, | ||
"scripts": { | ||
"build": "run-p build:transpile build:types", | ||
"build:dev": "yarn build", | ||
"build:transpile": "rollup -c rollup.npm.config.mjs", | ||
"build:types": "run-s build:types:core build:types:downlevel", | ||
"build:types:core": "tsc -p tsconfig.types.json", | ||
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8", | ||
"build:watch": "run-p build:transpile:watch build:types:watch", | ||
"build:dev:watch": "yarn build:watch", | ||
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch", | ||
"build:types:watch": "tsc -p tsconfig.types.json --watch", | ||
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build", | ||
"circularDepCheck": "madge --circular src/index.ts", | ||
"clean": "rimraf build coverage sentry-google-cloud-*.tgz", | ||
"fix": "eslint . --format stylish --fix", | ||
"lint": "eslint . --format stylish", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"yalc:publish": "ts-node ../../scripts/prepack.ts --bundles && yalc publish ./build/npm --push --sig" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
}, | ||
"sideEffects": false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; | ||
|
||
export default makeNPMConfigVariants(makeBaseNPMConfig()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
declare const __DEBUG_BUILD__: boolean; | ||
|
||
/** | ||
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code. | ||
* | ||
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking. | ||
*/ | ||
export const DEBUG_BUILD = __DEBUG_BUILD__; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, handleCallbackErrors } from '@sentry/core'; | ||
import { captureException, flush, getCurrentScope, startSpanManual } from '@sentry/node'; | ||
import { logger } from '@sentry/utils'; | ||
|
||
import { DEBUG_BUILD } from '../debug-build'; | ||
import { domainify, markEventUnhandled, proxyFunction } from '../utils'; | ||
import type { CloudEventFunction, CloudEventFunctionWithCallback, WrapperOptions } from './general'; | ||
|
||
export type CloudEventFunctionWrapperOptions = WrapperOptions; | ||
|
||
/** | ||
* Wraps an event function handler adding it error capture and tracing capabilities. | ||
* | ||
* @param fn Event handler | ||
* @param options Options | ||
* @returns Event handler | ||
*/ | ||
export function wrapCloudEventFunction( | ||
fn: CloudEventFunction | CloudEventFunctionWithCallback, | ||
wrapOptions: Partial<CloudEventFunctionWrapperOptions> = {}, | ||
): CloudEventFunctionWithCallback { | ||
return proxyFunction(fn, f => domainify(_wrapCloudEventFunction(f, wrapOptions))); | ||
} | ||
|
||
function _wrapCloudEventFunction( | ||
fn: CloudEventFunction | CloudEventFunctionWithCallback, | ||
wrapOptions: Partial<CloudEventFunctionWrapperOptions> = {}, | ||
): CloudEventFunctionWithCallback { | ||
const options: CloudEventFunctionWrapperOptions = { | ||
flushTimeout: 2000, | ||
...wrapOptions, | ||
}; | ||
return (context, callback) => { | ||
return startSpanManual( | ||
{ | ||
name: context.type || '<unknown>', | ||
op: 'function.gcp.cloud_event', | ||
attributes: { | ||
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component', | ||
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_cloud_event', | ||
}, | ||
}, | ||
span => { | ||
const scope = getCurrentScope(); | ||
scope.setContext('gcp.function.context', { ...context }); | ||
|
||
const newCallback = domainify((...args: unknown[]) => { | ||
if (args[0] !== null && args[0] !== undefined) { | ||
captureException(args[0], scope => markEventUnhandled(scope)); | ||
} | ||
span.end(); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
flush(options.flushTimeout) | ||
.then(null, e => { | ||
DEBUG_BUILD && logger.error(e); | ||
}) | ||
.then(() => { | ||
callback(...args); | ||
}); | ||
}); | ||
|
||
if (fn.length > 1) { | ||
return handleCallbackErrors( | ||
() => (fn as CloudEventFunctionWithCallback)(context, newCallback), | ||
err => { | ||
captureException(err, scope => markEventUnhandled(scope)); | ||
}, | ||
); | ||
} | ||
|
||
return Promise.resolve() | ||
.then(() => (fn as CloudEventFunction)(context)) | ||
.then( | ||
result => newCallback(null, result), | ||
err => newCallback(err, undefined), | ||
); | ||
}, | ||
); | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
l: I think this is by now disabled by default, so we don't need to overwrite this anymore.