Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

feature: adding telemetry #70

Merged
merged 6 commits into from
Jul 11, 2024

Conversation

DamilolaAlao
Copy link
Contributor

Copy link

codesandbox bot commented Jul 7, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@@ -27,6 +34,16 @@ export const devCmd = async (ctx: AppContext, args: any) => {
const { port } = params
const { cwd } = ctx

const projectHash = crypto.createHash('md5').update(cwd).digest('hex')
Copy link
Contributor

Choose a reason for hiding this comment

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

ahh this is a nice method

import crypto from 'crypto'

const posthog = new PostHog(
'your_posthog_api_key_here',
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally we bake in the secret as a build variable somehow then add it as a secret in github actions. Since this project uses tsup we can look at how to configure this using tsup (which uses esbuild behind the scenes)

@DamilolaAlao DamilolaAlao requested a review from seveibar July 7, 2024 06:37
@seveibar
Copy link
Contributor

seveibar commented Jul 7, 2024

@DamilolaAlao it looks like some of the tests are broken, looks related

@seveibar
Copy link
Contributor

This PR is almost ready but tests are broken because of the missing env var.

@@ -19,7 +19,7 @@ import { uploadExamplesFromDirectory } from "./upload-examples-from-directory"
import { PostHog } from "posthog-node"
import crypto from 'crypto'

declare const POSTHOG_API_KEY: string;
const POSTHOG_API_KEY: string = process.env.POSTHOG_API_KEY || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not sure it's a good idea to initialize posthog without an api key, or to initialize it in this file specifically because it's more of a global singleton, what if you did something like this in a global lib/posthog.ts file, then imported and used it

import PostHog from 'posthog-node'

const POSTHOG_API_KEY: string | undefined = process.env.POSTHOG_API_KEY

let posthogInstance: PostHog | null = null

if (POSTHOG_API_KEY) {
  posthogInstance = new PostHog(
    POSTHOG_API_KEY,
    { host: 'https://us.i.posthog.com' }
  )
}

const posthogProxy = new Proxy<PostHog>({} as PostHog, {
  get(target, prop) {
    if (posthogInstance) {
      return Reflect.get(posthogInstance, prop)
    }
    // Return a no-op function for any method call if PostHog is not initialized
    return () => {}
  }
})

export default posthogProxy

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

nice!

@seveibar seveibar merged commit c8b4ce1 into tscircuit:main Jul 11, 2024
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants