Skip to content

feat(otel): export traces to PostHog in production - #2360

Merged
Asherlc merged 4 commits into
mainfrom
Asherlc/lyon-v1
Aug 1, 2026
Merged

Asherlc merged 4 commits into
mainfrom
Asherlc/lyon-v1

Conversation

@Asherlc

@Asherlc Asherlc commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Enable PostHog tracing for project 347753 by exporting OpenTelemetry spans to https://us.i.posthog.com/i/v1/traces in production, mirroring the existing PostHog logs export (/i/v1/logs) in src/instrumentation.ts.
  • New createSpanProcessors() keeps the Axiom trace export (env-driven) and adds a BatchSpanProcessor with a Bearer-auth OTLPTraceExporter to PostHog when DEPLOY_ENVIRONMENT is prod/production. Auto-instrumentation is now active whenever PostHog traces are enabled too.
  • No new env vars: reuses the existing public project API key (phc_...) from src/lib/posthog-config.ts, so no Infisical change is required.
  • Per PostHog tracing docs, the OTLP traces endpoint is https://us.i.posthog.com/i/v1/traces with Authorization: Bearer <project API key>.

Tests

  • Added unit tests (TDD): production configures a PostHog trace exporter with /i/v1/traces URL + Bearer header; Axiom and PostHog exporters coexist in production with an Axiom endpoint.
  • pnpm test:unit (13,990 passed), root/server/web tsc --noEmit, and pnpm lint:sandbox all green. Full pnpm lint's lint:analytics-sql step requires a running ClickHouse and was skipped locally (CI runs it).

Notes

  • Effective after the next production deploy (stack.yml defaults DEPLOY_ENVIRONMENT=production); spans will then appear on the PostHog tracing page.

Summary by Sourcery

Enable OpenTelemetry span export to PostHog in production and wire it into the existing instrumentation setup alongside any Axiom exporters.

New Features:

  • Add PostHog OTLP traces endpoint configuration and use the project API key to export spans in production deployments.

Enhancements:

  • Refactor trace exporter setup into a reusable span processor factory that supports both Axiom and PostHog exporters.
  • Automatically enable auto-instrumentation when PostHog trace exporting is active.

Tests:

  • Add unit tests covering PostHog trace exporter configuration in production and coexistence with Axiom exporters.

Summary by cubic

Export OpenTelemetry traces to PostHog in production using a BatchSpanProcessor and OTLPTraceExporter with Bearer auth, so spans appear in PostHog. Reuses POSTHOG_API_KEY; no new env vars.

  • New Features

    • Send traces to POSTHOG_TRACES_URL (https://us.i.posthog.com/i/v1/traces) with Authorization: Bearer <POSTHOG_API_KEY>; enabled in prod even without Axiom endpoints.
    • Enable auto-instrumentation when PostHog tracing is active.
    • Run PostHog and Axiom trace exporters side-by-side when Axiom is configured.
  • Bug Fixes

    • Treat DEPLOY_ENVIRONMENT=prod or production as production; set it for cdc-health and metric-stream-clickhouse-sink in stack.yml.
    • Harden tests to assert the exact traces URL and Bearer key and use the last NodeSDK call for order-independence; clarify in-code docs on when instrumentation starts.

Written for commit 96eb7f9. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added production tracing support through PostHog.
    • Enabled Axiom and PostHog trace exports to operate together when configured.
  • Bug Fixes

    • Improved trace-export configuration so tracing is enabled only when supported processors are available.

Mirrors the existing PostHog log export in the OpenTelemetry pipeline so
spans land on the PostHog tracing page alongside logs and errors.
Copilot AI review requested due to automatic review settings August 1, 2026 04:05
@cursor

cursor Bot commented Aug 1, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@sourcery-ai

sourcery-ai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds production-only PostHog OTLP trace exporting alongside existing Axiom exporting by introducing a span processor factory and wiring it into the OpenTelemetry NodeSDK, plus tests and a new PostHog traces URL constant.

Sequence diagram for trace exporter setup in startInstrumentation

sequenceDiagram
  participant App
  participant startInstrumentation
  participant createSpanProcessors
  participant NodeSDK
  participant PostHogTracesEndpoint

  App->>startInstrumentation: startInstrumentation(env)
  startInstrumentation->>createSpanProcessors: createSpanProcessors(env)
  createSpanProcessors-->>startInstrumentation: SpanProcessor[]
  startInstrumentation->>NodeSDK: new NodeSDK({ spanProcessors })
  alt hasPostHogTraceExport
    startInstrumentation->>PostHogTracesEndpoint: OTLPTraceExporter url POSTHOG_TRACES_URL Authorization Bearer POSTHOG_API_KEY
  end
Loading

File-Level Changes

Change Details Files
Introduce a span processor factory that configures Axiom and PostHog OTLP trace exporters based on environment.
  • Add createSpanProcessors(env) helper that inspects OTEL_EXPORTER_OTLP_* and DEPLOY_ENVIRONMENT.
  • Configure BatchSpanProcessor with default OTLPTraceExporter when Axiom endpoints are present.
  • Configure BatchSpanProcessor with OTLPTraceExporter pointing at POSTHOG_TRACES_URL and Bearer Authorization using POSTHOG_API_KEY in production deployments.
  • Use the spanProcessors array to determine whether tracing is enabled.
src/instrumentation.ts
Wire new span processor logic into instrumentation startup, keeping auto-instrumentation when traces are exported.
  • Replace inline spanProcessors construction in startInstrumentation with createSpanProcessors(env).
  • Derive hasTraceExport from spanProcessors.length instead of OTEL trace endpoint env vars.
  • Pass computed spanProcessors directly into NodeSDK configuration.
src/instrumentation.ts
Add tests to validate PostHog trace exporter behavior in production and coexistence with Axiom exporter.
  • Add test ensuring production without Axiom endpoints configures a single PostHog trace exporter with /i/v1/traces and Bearer Authorization header.
  • Add test ensuring production with Axiom endpoint configures two span processors (Axiom + PostHog).
src/instrumentation.test.ts
Expose a PostHog traces URL constant alongside the existing logs URL.
  • Add POSTHOG_TRACES_URL constant derived from POSTHOG_HOST with /i/v1/traces path.
src/lib/posthog-config.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codereviewbot-ai

codereviewbot-ai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

LGTM! The addition of the PostHog trace exporter cleanly mirrors the existing log exporter pattern and includes thorough unit test coverage.


🤖 Reviewed by codereviewbot.ai - Catch bugs before your team does.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Export OpenTelemetry traces to PostHog in production

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Add a production-only OTLP trace exporter to PostHog using the existing project API key.
• Refactor trace exporting into createSpanProcessors() to support multiple exporters.
• Add unit tests asserting PostHog trace exporter configuration and coexistence with Axiom.
Diagram

graph TD
  A["App startup"] --> B["src/instrumentation.ts"] --> C["createSpanProcessors()"]
  C --> D["OTLPTraceExporter (Axiom)"] --> E{{"Axiom OTLP endpoint"}}
  C --> F["OTLPTraceExporter (PostHog)"] --> G{{"PostHog /i/v1/traces"}}
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Route via OpenTelemetry Collector
  • ➕ Avoids embedding PostHog API key in application code
  • ➕ Centralizes routing/sampling/retry policy for all telemetry exporters
  • ➕ Makes adding/removing backends a deploy-time change
  • ➖ Requires additional infrastructure/configuration and operational ownership
  • ➖ More moving parts during incident debugging vs direct export
2. Use standard OTEL env vars for headers/endpoint
  • ➕ Keeps application code generic (no PostHog-specific exporter wiring)
  • ➕ Enables tuning per-environment without code changes
  • ➖ Would require introducing/managing OTEL header env vars (contrary to 'no new env vars')
  • ➖ Harder to enforce 'production only' behavior without config discipline

Recommendation: Current approach is reasonable given the stated constraints (production-only enablement and no new env vars) and mirrors the existing PostHog logs export pattern. If the team anticipates adding more telemetry backends or wants to remove API keys from code, consider moving export routing into an OpenTelemetry Collector later.

Files changed (3) +69 / -5

Enhancement (2) +35 / -5
instrumentation.tsCreate span processor factory and add PostHog trace export in prod +33/-5

Create span processor factory and add PostHog trace export in prod

• Introduces 'createSpanProcessors()' to build trace span processors based on environment. Keeps existing Axiom OTLP exporting (env-driven) and adds a production-only PostHog OTLP trace exporter configured with '/i/v1/traces' and a Bearer API key header; 'startInstrumentation()' now uses the generated processor list.

src/instrumentation.ts

posthog-config.tsDefine PostHog OTLP traces endpoint constant +2/-0

Define PostHog OTLP traces endpoint constant

• Adds 'POSTHOG_TRACES_URL' alongside the existing PostHog host and logs URL constants for reuse by instrumentation.

src/lib/posthog-config.ts

Tests (1) +34 / -0
instrumentation.test.tsAdd production tests for PostHog trace span exporter +34/-0

Add production tests for PostHog trace span exporter

• Adds unit coverage ensuring a PostHog OTLP trace exporter is configured in production even without Axiom endpoints. Also verifies Axiom and PostHog span processors can be active simultaneously when an Axiom OTLP endpoint is present.

src/instrumentation.test.ts

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Asherlc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d1fb1cd5-8cf4-4695-a5fb-62af1af7de44

📥 Commits

Reviewing files that changed from the base of the PR and between 145a1a5 and 9d80f82.

📒 Files selected for processing (2)
  • src/instrumentation.test.ts
  • src/instrumentation.ts
📝 Walkthrough

Walkthrough

The instrumentation now creates configurable Axiom and production PostHog trace processors. startInstrumentation passes all configured processors to the SDK. Tests verify PostHog configuration and coexistence with Axiom.

Changes

Trace exporting

Layer / File(s) Summary
Trace processor creation
src/lib/posthog-config.ts, src/instrumentation.ts
Adds POSTHOG_TRACES_URL and centralizes conditional Axiom and production PostHog processor creation.
SDK wiring and validation
src/instrumentation.ts, src/instrumentation.test.ts
Passes the complete processor list to the SDK and tests PostHog headers, automatic instrumentation, and Axiom/PostHog coexistence.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: type/feature

Suggested reviewers: copilot

Sequence Diagram(s)

sequenceDiagram
  participant startInstrumentation
  participant createSpanProcessors
  participant OpenTelemetrySDK
  startInstrumentation->>createSpanProcessors: obtain configured processors
  createSpanProcessors-->>startInstrumentation: return Axiom and/or PostHog processors
  startInstrumentation->>OpenTelemetrySDK: pass complete processor list
Loading
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses imperative mood, identifies the OTEL area, stays under 70 characters, and has no trailing punctuation.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Storybook previews for 55106495 are ready:

This comment updates automatically on each PR push.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the repository’s OpenTelemetry bootstrap (src/instrumentation.ts) to export traces to PostHog in production, mirroring the existing PostHog logs export path.

Changes:

  • Add POSTHOG_TRACES_URL constant for PostHog’s OTLP traces endpoint.
  • Refactor span exporter setup into createSpanProcessors() and enable PostHog trace export in production (while preserving any env-driven OTLP/Axiom export).
  • Add unit tests verifying PostHog trace exporter configuration and coexistence with an env-driven trace exporter.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/lib/posthog-config.ts Adds POSTHOG_TRACES_URL constant for the PostHog OTLP traces endpoint.
src/instrumentation.ts Introduces createSpanProcessors() and wires PostHog trace export in production alongside existing exporters.
src/instrumentation.test.ts Adds unit tests covering PostHog trace exporter configuration and coexistence with an env-driven exporter.
Suppressed comments (1)

src/instrumentation.test.ts:237

  • Same brittleness here: NodeSDK.mock.calls[0] can point at the module auto-start call if this test runs first/in isolation. Use the last call so this test is order-independent.
    const config = vi.mocked(NodeSDK).mock.calls[0]?.[0];

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/instrumentation.test.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/instrumentation.test.ts`:
- Around line 208-240: Update the production PostHog exporter test around
startInstrumentation to run for both DEPLOY_ENVIRONMENT values, "prod" and
"production". Replace the partial OTLPTraceExporter assertions with exact
POSTHOG_TRACES_URL and Authorization values using the existing POSTHOG_API_KEY,
while preserving the Axiom coexistence test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e5f2fdcf-b30d-48a5-aebe-45e9050ac7d4

📥 Commits

Reviewing files that changed from the base of the PR and between f1b92e7 and 145a1a5.

📒 Files selected for processing (3)
  • src/instrumentation.test.ts
  • src/instrumentation.ts
  • src/lib/posthog-config.ts

Comment thread src/instrumentation.test.ts Outdated
@qodo-code-review

qodo-code-review Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 144 rules

Grey Divider


Remediation recommended

1. Prod tracing always-on 🐞 Bug ☼ Reliability
Description
createSpanProcessors() adds a PostHog BatchSpanProcessor solely based on DEPLOY_ENVIRONMENT,
so startInstrumentation() will start the NodeSDK in production even when no
OTEL_EXPORTER_OTLP* env vars are set. Because entrypoint.sh runs all container modes with `node
--import ./src/instrumentation.ts`, non-service/short-lived modes (e.g. migrate/scripts) will also
be instrumented and may export spans to PostHog unexpectedly.
Code

src/instrumentation.ts[R17-42]

+function createSpanProcessors(env: Record<string, string | undefined>): SpanProcessor[] {
+  const endpoint = env.OTEL_EXPORTER_OTLP_ENDPOINT;
+  const tracesEndpoint = env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
+  const hasAxiomTraceExport = Boolean(endpoint || tracesEndpoint);
+  const hasPostHogTraceExport = isProductionDeployment(env.DEPLOY_ENVIRONMENT);
+
+  const processors: SpanProcessor[] = [];
+
+  if (hasAxiomTraceExport) {
+    processors.push(new BatchSpanProcessor(new OTLPTraceExporter()));
+  }
+
+  if (hasPostHogTraceExport) {
+    processors.push(
+      new BatchSpanProcessor(
+        new OTLPTraceExporter({
+          url: POSTHOG_TRACES_URL,
+          headers: {
+            Authorization: `Bearer ${POSTHOG_API_KEY}`,
+          },
+        }),
+      ),
+    );
+  }
+
+  return processors;
Relevance

●●● Strong

History favors env-gating telemetry to avoid unintended prod reporting (PR#1882) and traces were
OTLP-env-driven (PR#316).

PR-#1882
PR-#316
PR-#358

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR adds a PostHog span processor whenever DEPLOY_ENVIRONMENT is production, which makes
hasTraceExport true and causes startInstrumentation() to start the SDK even without OTLP
endpoints. The container entrypoint uses --import ./src/instrumentation.ts for multiple modes, so
the broadened enablement condition impacts migrations/scripts as well as services.

src/instrumentation.ts[17-43]
src/instrumentation.ts[81-129]
src/instrumentation.ts[131-132]
entrypoint.sh[19-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
PostHog trace exporting is enabled purely by `DEPLOY_ENVIRONMENT` in `createSpanProcessors()`, which makes `startInstrumentation()` start OTel in production even when no OTLP exporter env vars are configured. Since the container entrypoint imports `./src/instrumentation.ts` for all modes, this expands tracing beyond the intended long-running services and can create unintended outbound traffic/telemetry volume during one-off jobs.

## Issue Context
- `src/instrumentation.ts` auto-starts on import, and with this PR production now always has a span processor due to PostHog.
- `entrypoint.sh` uses `--import ./src/instrumentation.ts` for all modes (web/worker/migrate/etc.), so the widened enable condition affects more than just the web/worker services.

## Fix Focus Areas
- Add an explicit disable/opt-out guard for OTel startup (e.g., honor `OTEL_SDK_DISABLED=true`) and set it for non-service entrypoint modes, OR
- Restrict PostHog trace exporter creation to only the service modes you intend (e.g., require existing OTLP env vars, or only enable when `OTEL_SERVICE_NAME` is explicitly configured and matches expected service names), OR
- Move the `--import ./src/instrumentation.ts` usage in `entrypoint.sh` so it’s only applied to the modes that should emit telemetry.

### Suggested edit locations
- src/instrumentation.ts[17-43]
- src/instrumentation.ts[81-129]
- entrypoint.sh[19-47]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Comment thread src/instrumentation.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 3 files

Confidence score: 3/5

  • src/instrumentation.ts can drop production tracing for cdc-health and metric-stream-clickhouse-sink when DEPLOY_ENVIRONMENT is missing, which creates an observability blind spot in PostHog during incidents—set DEPLOY_ENVIRONMENT for all instrumented prod services or derive the environment from deployment metadata.
  • src/instrumentation.test.ts uses broad stringContaining checks for the trace endpoint and auth header, so wrong PostHog hosts or malformed Bearer tokens could slip through CI and regress telemetry routing—tighten these to exact URL/header assertions.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/instrumentation.ts">

<violation number="1" location="src/instrumentation.ts:21">
P2: Production `cdc-health` and `metric-stream-clickhouse-sink` spans will not reach PostHog because these deployments omit `DEPLOY_ENVIRONMENT`. Set that variable for every instrumented production service, or derive the production condition from configuration shared by all production services.</violation>
</file>

<file name="src/instrumentation.test.ts">

<violation number="1" location="src/instrumentation.test.ts:219">
P3: The assertions here use `expect.stringContaining("/i/v1/traces")` and `expect.stringContaining("Bearer ")` instead of exact matches, so an incorrect PostHog host or malformed Authorization header would still pass. Additionally, only `DEPLOY_ENVIRONMENT: "production"` is exercised — `"prod"` (also treated as production by `isProductionDeployment`) isn't covered. Consider asserting the exact `POSTHOG_TRACES_URL` and `` `Bearer ${POSTHOG_API_KEY}` `` values and parameterizing the test for both `"prod"` and `"production"`.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/instrumentation.ts Outdated
Comment thread src/instrumentation.test.ts
- Robustify NodeSDK config assertions (use last call, not first) so
  tests are order-independent against module auto-start.
- Assert exact PostHog traces URL and bearer key in tests.
- Parameterize production exporter test over both prod and production
  DEPLOY_ENVIRONMENT values.
- Set DEPLOY_ENVIRONMENT for cdc-health and metric-stream-clickhouse-sink
  so all instrumented prod services export traces and logs to PostHog.
@codereviewbot-ai

codereviewbot-ai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

LGTM! The changes cleanly integrate PostHog trace exporting alongside Axiom, mirroring the existing log exporter structure. The updated unit tests appropriately verify both prod and production deployment environments as well as combined Axiom + PostHog trace processor configurations.


🤖 Reviewed by codereviewbot.ai - Catch bugs before your team does.

@codereviewbot-ai

codereviewbot-ai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

LGTM! The changes cleanly implement the PostHog trace exporter for production environments alongside Axiom trace exporting, with updated unit tests covering both "prod" and "production" deployment environments.


🤖 Reviewed by codereviewbot.ai - Catch bugs before your team does.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 4 files

Confidence score: 4/5

  • In deploy/stack.yml, setting DEPLOY_ENVIRONMENT for cdc-health and metric-stream-clickhouse-sink can unintentionally activate PostHog exporters via shared createLogRecordProcessors/createSpanProcessors in src/instrumentation.ts, which risks noisy telemetry or data being sent from services that weren’t meant to export it; verify intended environments and gate exporter activation explicitly for these services.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="deploy/stack.yml">

<violation number="1" location="deploy/stack.yml:184">
P2: This stack change sets `DEPLOY_ENVIRONMENT` on `cdc-health` and `metric-stream-clickhouse-sink`, which the shared `createLogRecordProcessors`/`createSpanProcessors` in `src/instrumentation.ts` use to enable PostHog exporters. The PR is described as adding PostHog *traces*, but because log export is keyed on the same `DEPLOY_ENVIRONMENT` flag and is not covered by the 10% trace sampler, these two services will also start sending their full logs to PostHog once they run instrumentation. That's a broader telemetry-egress change than the PR title suggests; worth confirming the intent (or scoping it to traces only) before merge.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread deploy/stack.yml Outdated
Use the existing production runtime plus explicit OTLP trace setup for helper services, avoiding broader PostHog log export.
@codereviewbot-ai

Copy link
Copy Markdown

🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews.

@Asherlc

Asherlc commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Review-summary follow-up:

Validation: pnpm lint, root/server/web TypeScript checks, and pnpm test (15,253 passed).

@Asherlc
Asherlc merged commit 87b2d11 into main Aug 1, 2026
104 checks passed
@Asherlc
Asherlc deleted the Asherlc/lyon-v1 branch August 1, 2026 18:02
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