generated from getsentry/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 57
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(telemetry): Add telemetry via @sentry/node
#213
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ff95fed
feat(telemetry): Add telemetry via `@sentry/node
andreiborza 7a50d4d
Replace DSN with `sentry-github-action` dsn
andreiborza 2839b6b
Add step tracing
andreiborza b9f36f1
Remove `debug` and hooks from init
andreiborza 39b6c26
Add session tracking
andreiborza f14edb3
Propagate sentry trace to CLI
andreiborza 248798c
Add `disable_telemetry` flag to action
andreiborza 93f5b5e
Remove cli singleton in favor of creating a new instance for proper t…
andreiborza 202993b
Lift mocking env variables out of cli
andreiborza 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 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 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 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 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 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 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 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 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,94 @@ | ||
import * as options from './options'; | ||
import * as Sentry from '@sentry/node'; | ||
import packageJson from '../package.json'; | ||
|
||
const SENTRY_SAAS_HOSTNAME = 'sentry.io'; | ||
|
||
/** | ||
* Initializes Sentry and wraps the given callback | ||
* in a span. | ||
*/ | ||
export async function withTelemetry<F>( | ||
options: {enabled: boolean}, | ||
callback: () => F | Promise<F> | ||
): Promise<F> { | ||
Sentry.initWithoutDefaultIntegrations({ | ||
dsn: 'https://[email protected]/4508608809533441', | ||
enabled: options.enabled, | ||
environment: `production-sentry-github-action`, | ||
tracesSampleRate: 1, | ||
sampleRate: 1, | ||
release: packageJson.version, | ||
integrations: [Sentry.httpIntegration()], | ||
tracePropagationTargets: ['sentry.io/api'], | ||
}); | ||
|
||
const session = Sentry.startSession(); | ||
|
||
Sentry.setTag('node', process.version); | ||
Sentry.setTag('platform', process.platform); | ||
|
||
try { | ||
return await Sentry.startSpan( | ||
{ | ||
name: 'sentry-github-action-execution', | ||
op: 'action.flow', | ||
}, | ||
async () => { | ||
updateProgress('start'); | ||
const res = await callback(); | ||
updateProgress('finished'); | ||
|
||
return res; | ||
} | ||
); | ||
} catch (e) { | ||
session.status = 'crashed'; | ||
Sentry.captureException('Error during sentry-github-action execution.'); | ||
throw e; | ||
} finally { | ||
Sentry.endSession(); | ||
await safeFlush(); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the `progress` tag to a given step. | ||
*/ | ||
export function updateProgress(step: string): void { | ||
Sentry.setTag('progress', step); | ||
} | ||
|
||
/** | ||
* Wraps the given callback in a span. | ||
*/ | ||
export function traceStep<T>(step: string, callback: () => T): T { | ||
updateProgress(step); | ||
return Sentry.startSpan({name: step, op: 'action.step'}, () => callback()); | ||
} | ||
|
||
/** | ||
* Flushing can fail, we never want to crash because of telemetry. | ||
*/ | ||
export async function safeFlush(): Promise<void> { | ||
try { | ||
await Sentry.flush(3000); | ||
} catch { | ||
// Noop when flushing fails. | ||
// We don't even need to log anything because there's likely nothing the user can do and they likely will not care. | ||
} | ||
} | ||
|
||
/** | ||
* Determine if telemetry should be enabled | ||
*/ | ||
export function isTelemetryEnabled(): boolean { | ||
const url = new URL( | ||
process.env['SENTRY_URL'] || `https://${SENTRY_SAAS_HOSTNAME}` | ||
); | ||
|
||
return ( | ||
!options.getBooleanOption('disable_telemetry', false) && | ||
url.hostname === SENTRY_SAAS_HOSTNAME | ||
); | ||
} |
This file contains 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
Oops, something went wrong.
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.
Just to confirm: the
for
loop for setting the variables was moved tocheckEnvironmentVariables
, right?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.
Yep, correct. That was really only necessary once at startup and since
getCli
is now not returning a singleton anymore I moved it over there.