Skip to content
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

chore: disable plugin server posthog capture if not set #29275

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

daibhin
Copy link
Contributor

@daibhin daibhin commented Feb 26, 2025

Problem

The plugin server captures events from dev

Changes

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR modifies the plugin server to conditionally capture PostHog analytics based on environment variables rather than using hardcoded values.

  • Changed PostHog client initialization in utils/posthog.ts to only create a client when POSTHOG_API_KEY is provided
  • Added null checks before using the PostHog client in captureTeamEvent and captureException functions
  • Added new environment variables POSTHOG_API_KEY and POSTHOG_HOST_URL to the PluginsServerConfig interface
  • Removed previous random sampling logic (10% of exceptions) that was used in production
  • Set default values in config.ts: empty string for API key and 'http://localhost:8010' for host URL

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@daibhin daibhin requested a review from a team February 27, 2025 09:46
@oliverb123
Copy link
Contributor

oliverb123 commented Feb 28, 2025

One thing that might be nicer here, from the dev/hobby perspective, is to hit the DB and fetch team-1's token if none is set (maybe putting that behaviour behind an env var) - wdyt?

something like if (POSTHOG_API_KEY == '' && POSTHOG_AUTOCONFIGURE) { POSTHOG_API_KEY = fetchKey() }

@daibhin
Copy link
Contributor Author

daibhin commented Feb 28, 2025

@oliverb123 thought something like this might work when creating the config:

    if (!newConfig.POSTHOG_API_KEY && newConfig.POSTHOG_AUTOCONFIGURE) {
        newConfig.POSTHOG_API_KEY = await fetchDevTeamApiToken(newConfig)
    }

    if (!Object.keys(KAFKAJS_LOG_LEVEL_MAPPING).includes(newConfig.KAFKAJS_LOG_LEVEL)) {
        throw Error(
            `Invalid KAFKAJS_LOG_LEVEL ${newConfig.KAFKAJS_LOG_LEVEL}. Valid: ${Object.keys(
                KAFKAJS_LOG_LEVEL_MAPPING
            ).join(', ')}`
        )
    }
    return newConfig
}

async function fetchDevTeamApiToken(config: PluginsServerConfig): Promise<string> {
    const postgres = new PostgresRouter(config)
    const teamManager = new TeamManager(postgres)

    const team = await teamManager.fetchTeam(1)

    if (!team) {
        throw Error('Could not find team with ID 1 to autoconfigure API token')
    }

    return team.api_token
}

Problem is that the lookup will cause things to be async which has a whole array of changes.

Given people were never getting plugin server events locally before (they were sent to production) I think it's ok to not capture them but default and let people add their keys locally if they want to test something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants