From 04df7c06f3ff7be91dfac89235dcc96a00070ce1 Mon Sep 17 00:00:00 2001 From: Brett Hoerner Date: Mon, 9 Oct 2023 07:44:34 -0600 Subject: [PATCH] chore: set Sentry release using commit.txt (#17855) --- plugin-server/src/sentry.ts | 14 ++++++++++++++ posthog/settings/sentry.py | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugin-server/src/sentry.ts b/plugin-server/src/sentry.ts index 60c251a1d7bee..960da7de1599d 100644 --- a/plugin-server/src/sentry.ts +++ b/plugin-server/src/sentry.ts @@ -1,3 +1,5 @@ +const fs = require('fs') + import * as Sentry from '@sentry/node' import { ProfilingIntegration } from '@sentry/profiling-node' import * as Tracing from '@sentry/tracing' @@ -19,6 +21,17 @@ export function initSentry(config: PluginsServerConfig): void { if (config.SENTRY_PLUGIN_SERVER_PROFILING_SAMPLE_RATE > 0) { integrations.push(new ProfilingIntegration()) } + + let release: string | undefined = undefined + try { + // Docker containers should have a commit.txt file in the base directory with the git + // commit hash used to generate them. `plugin-server` runs from a child directory, so we + // need to look up one level. + release = fs.readFileSync('../commit.txt', 'utf8') + } catch (error) { + // The release isn't required, it's just nice to have. + } + Sentry.init({ dsn: config.SENTRY_DSN, normalizeDepth: 8, // Default: 3 @@ -28,6 +41,7 @@ export function initSentry(config: PluginsServerConfig): void { DEPLOYMENT: config.CLOUD_DEPLOYMENT, }, }, + release, integrations, tracesSampleRate: config.SENTRY_PLUGIN_SERVER_TRACING_SAMPLE_RATE, profilesSampleRate: config.SENTRY_PLUGIN_SERVER_PROFILING_SAMPLE_RATE, diff --git a/posthog/settings/sentry.py b/posthog/settings/sentry.py index 23d02d0a68a6c..208f3bfd81e2c 100644 --- a/posthog/settings/sentry.py +++ b/posthog/settings/sentry.py @@ -122,9 +122,20 @@ def sentry_init() -> None: sentry_logging = LoggingIntegration(level=sentry_logging_level, event_level=None) profiles_sample_rate = get_from_env("SENTRY_PROFILES_SAMPLE_RATE", type_cast=float, default=0.0) + release = None + try: + # Docker containers should have a commit.txt file in the base directory with the git + # commit hash used to generate them. + with open("commit.txt") as f: + release = f.read() + except: + # The release isn't required, it's just nice to have. + pass + sentry_sdk.init( send_default_pii=send_pii, dsn=os.environ["SENTRY_DSN"], + release=release, integrations=[DjangoIntegration(), CeleryIntegration(), RedisIntegration(), sentry_logging], request_bodies="always" if send_pii else "never", sample_rate=1.0,