fix: no-op blank project tokens#3703
Open
marandaneto wants to merge 2 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
packages/ai/src/otel/exporter.ts:76-80
The `safeOptions = options ?? {}` guard is superfluous: the TypeScript default parameter `= {}` already handles `undefined`. The only extra case it covers is explicit `null`, which only arises from a type-system bypass (`null as any` in tests). Collapsing the two lets the reader trust the default parameter alone.
```suggestion
constructor(options: PostHogTraceExporterOptions = {}) {
const token = normalizeToken(options.projectToken) || normalizeToken(options.apiKey)
const disabled = !token
const host = token ? new URL(normalizeHost(options.host)).origin : DEFAULT_OTEL_HOST
```
### Issue 2 of 2
packages/ai/src/otel/processor.ts:78-90
Same redundancy as in `exporter.ts`: `safeOptions = options ?? {}` adds nothing beyond what the `= {}` default already provides for the TypeScript-typed call path. Removing it keeps the code simpler.
```suggestion
constructor(options: PostHogSpanProcessorOptions = {}) {
const apiKey = normalizeApiKey(options.apiKey)
if (!apiKey) {
console.warn('[PostHogSpanProcessor] apiKey is missing or blank; the processor will be disabled.')
this.inner = new NoopSpanProcessor()
return
}
if (options._spanProcessor) {
this.inner = options._spanProcessor
} else {
const host = new URL(normalizeHost(options.host)).origin
```
Reviews (1): Last reviewed commit: "fix: no-op blank project tokens" | Re-trigger Greptile |
Contributor
Contributor
|
Size Change: +3.31 kB (+0.02%) Total Size: 16.5 MB
ℹ️ View Unchanged
|
dustinbyrne
approved these changes
May 29, 2026
dustinbyrne
reviewed
May 29, 2026
|
|
||
| override export(spans: ReadableSpan[], resultCallback: (result: { code: number; error?: Error }) => void): void { | ||
| if (this.disabled) { | ||
| resultCallback({ code: ExportResultCode.SUCCESS }) |
Contributor
There was a problem hiding this comment.
Probably worth a comment that we're returning success due to compatibility reasons (at least that's my assumption here)
otherwise I could see this being changed in the future, as it looks to me like it should be reporting ExportResultCode.FAILED
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When PostHog project tokens are missing, blank, or only whitespace, SDK initialization paths can throw or continue into feature flag / remote config request flows. This makes token-less or misconfigured environments noisier than needed and can trigger unnecessary network work.
Changes
posthog-nodeshort-circuit feature flag, remote config, and capture-with-flags paths when the client is disabled due to a missing/blank project token.@posthog/aiOpenTelemetry exporter/processor no-op instead of throwing when tokens are missing/blank.PostHogSpanProcessorusing the existingapiKeyoption name while preserving the new no-op behavior.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file