Add some logging to see if I can figure out why PostHog flags aren't coming through.

This commit is contained in:
Sam Rose 2024-08-12 15:33:48 +01:00
parent 8b9576a55f
commit 72a37ed1a7
No known key found for this signature in database
1 changed files with 13 additions and 0 deletions

View File

@ -7,10 +7,13 @@ import tracer from "dd-trace"
let posthog: PostHog | undefined let posthog: PostHog | undefined
export function init(opts?: PostHogOptions) { export function init(opts?: PostHogOptions) {
if (env.POSTHOG_TOKEN && env.POSTHOG_API_HOST) { if (env.POSTHOG_TOKEN && env.POSTHOG_API_HOST) {
console.log("initializing posthog client...")
posthog = new PostHog(env.POSTHOG_TOKEN, { posthog = new PostHog(env.POSTHOG_TOKEN, {
host: env.POSTHOG_API_HOST, host: env.POSTHOG_API_HOST,
...opts, ...opts,
}) })
} else {
console.log("posthog disabled")
} }
} }
@ -128,6 +131,8 @@ export class FlagSet<V extends Flag<any>, T extends { [key: string]: V }> {
continue continue
} }
tags[`readFromEnvironmentVars`] = true
for (let feature of features) { for (let feature of features) {
let value = true let value = true
if (feature.startsWith("!")) { if (feature.startsWith("!")) {
@ -153,6 +158,8 @@ export class FlagSet<V extends Flag<any>, T extends { [key: string]: V }> {
const license = ctx?.user?.license const license = ctx?.user?.license
if (license) { if (license) {
tags[`readFromLicense`] = true
for (const feature of license.features) { for (const feature of license.features) {
if (!this.isFlagName(feature)) { if (!this.isFlagName(feature)) {
continue continue
@ -175,7 +182,13 @@ export class FlagSet<V extends Flag<any>, T extends { [key: string]: V }> {
} }
const identity = context.getIdentity() const identity = context.getIdentity()
tags[`identity.type`] = identity?.type
tags[`identity.tenantId`] = identity?.tenantId
tags[`identity._id`] = identity?._id
if (posthog && identity?.type === IdentityType.USER) { if (posthog && identity?.type === IdentityType.USER) {
tags[`readFromPostHog`] = true
const posthogFlags = await posthog.getAllFlagsAndPayloads(identity._id) const posthogFlags = await posthog.getAllFlagsAndPayloads(identity._id)
for (const [name, value] of Object.entries(posthogFlags.featureFlags)) { for (const [name, value] of Object.entries(posthogFlags.featureFlags)) {
if (!this.isFlagName(name)) { if (!this.isFlagName(name)) {