OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix(api): api and workers start again when HyperDX log shipping is on
Carl-Gerhard Lindesvärd7adb3e868441
diff --git a/.github/smoke/docker-compose.yml b/.github/smoke/docker-compose.ymlindex efbd3d497..a64a96646 100644--- a/.github/smoke/docker-compose.yml+++ b/.github/smoke/docker-compose.yml@@ -150,6 +150,10 @@ services:environment:<<: *app_envROLE: worker+ # Boots with HyperDX log shipping on, which loads its transport at+ # startup; nothing listens on the endpoint, the export just fails.+ HYPERDX_API_KEY: smoke+ OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:9# The api serves /healthz/ready.healthcheck:test: ["CMD-SHELL", "curl -f http://localhost:3000/healthz/ready || exit 1"]diff --git a/packages/core/src/pino-logger.test.ts b/packages/core/src/pino-logger.test.tsindex 7910afd9c..4d880e58f 100644--- a/packages/core/src/pino-logger.test.ts+++ b/packages/core/src/pino-logger.test.ts@@ -1,5 +1,7 @@import { describe, expect, it } from 'bun:test';-import { redactSensitive } from './pino-logger';+import { existsSync } from 'node:fs';+import { isAbsolute } from 'node:path';+import { hyperdxTransport, redactSensitive } from './pino-logger';describe('redactSensitive', () => {it('filters the query of a string url value', () => {@@ -27,3 +29,13 @@ describe('redactSensitive', () => {});});});++describe('hyperdxTransport', () => {+ // pino resolves a bare target from the module that called pino(), which+ // in the api image is apps/api — a package that does not install HyperDX.+ it('hands pino an absolute path that exists, not a package name', () => {+ const { target } = hyperdxTransport('info', 'test-service');+ expect(isAbsolute(target)).toBe(true);+ expect(existsSync(target)).toBe(true);+ });+});diff --git a/packages/core/src/pino-logger.ts b/packages/core/src/pino-logger.tsindex 9b0c8d1dd..fd0b1ff4d 100644--- a/packages/core/src/pino-logger.ts+++ b/packages/core/src/pino-logger.ts@@ -1,3 +1,4 @@+import { createRequire } from 'node:module';import * as HyperDX from '@hyperdx/node-opentelemetry';import pino, { type Logger as PinoLogger } from 'pino';import type { CoreConfig } from './config';@@ -68,6 +69,24 @@ export function getServiceName(config: CoreConfig, name: string): string {// Pretty printing is therefore off under Bun.const isBun = !!process.versions.bun;+const requireFromCore = createRequire(import.meta.url);++/**+ * The HyperDX transport with its target resolved from this package, which+ * depends on HyperDX. Left as a package name, pino resolves it from the caller,+ * and an app that does not install HyperDX itself crashes at boot.+ */+export function hyperdxTransport(+ level: string,+ service: string+): ReturnType<typeof HyperDX.getPinoTransport> {+ const transport = HyperDX.getPinoTransport(level, {+ detectResources: true,+ service,+ });+ return { ...transport, target: requireFromCore.resolve(transport.target) };+}+export function createLogger({name,config,@@ -94,10 +113,7 @@ export function createLogger({// correlation survives when a collector does the shipping.mixin: hyperdxApiKey ? HyperDX.getPinoMixinFunction : undefined,transport: useHyperDX- ? HyperDX.getPinoTransport(level, {- detectResources: true,- service,- })+ ? hyperdxTransport(level, service): usePretty? {target: 'pino-pretty',