Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: logging for track calls

Carl-Gerhard Lindesvärd1db2c8a0d985
diff --git a/apps/api/src/hooks/request-logging.hook.ts b/apps/api/src/hooks/request-logging.hook.ts
index 7b9644ba9..1db703678 100644
--- a/apps/api/src/hooks/request-logging.hook.ts
+++ b/apps/api/src/hooks/request-logging.hook.ts
@@ -10,7 +10,7 @@ const getTrpcInput = (
const input = path<any>(['query', 'input'], request);
try {
return typeof input === 'string' ? JSON.parse(input).json : input;
- } catch (e) {
+ } catch {
return undefined;
}
};
@@ -33,7 +33,13 @@ export async function requestLoggingHook(
elapsed: reply.elapsedTime,
});
} else {
- request.log.info('request done', {
+ const payload: {
+ url: string;
+ method: string;
+ elapsed: number;
+ headers: Record<string, string | string[] | undefined>;
+ body?: unknown;
+ } = {
url: request.url,
method: request.method,
elapsed: reply.elapsedTime,
@@ -41,6 +47,12 @@ export async function requestLoggingHook(
['openpanel-client-id', 'openpanel-sdk-name', 'openpanel-sdk-version'],
request.headers
),
- });
+ };
+
+ if (payload.url.startsWith('/track')) {
+ payload.body = request.body;
+ }
+
+ request.log.info('request done', payload);
}
}
diff --git a/biome.json b/biome.json
index 4db27e00a..910c45a3d 100644
--- a/biome.json
+++ b/biome.json
@@ -72,7 +72,8 @@
},
"suspicious": {
"noExplicitAny": "off",
- "noShadowRestrictedNames": "off"
+ "noShadowRestrictedNames": "off",
+ "useAwait": "off"
},
"security": {
"noDangerouslySetInnerHtml": "off"
diff --git a/packages/sdks/sdk/src/index.ts b/packages/sdks/sdk/src/index.ts
index 71789d629..dfbfbc63c 100644
--- a/packages/sdks/sdk/src/index.ts
+++ b/packages/sdks/sdk/src/index.ts
@@ -175,7 +175,7 @@ export class OpenPanel {
this.flush();
}
- if (Object.keys(payload).length > 1) {
+ if (payload.profileId && Object.keys(payload).length > 1) {
return this.send({
type: 'identify',
payload: {