Skip to content

Commit 0a41bf1

Browse files
lohanidamodarclaude
andcommitted
fix: extract country and userAgent from tags into dedicated columns
Use Metric::EVENT_COLUMNS to extract all event columns from tags instead of hardcoding the list. Now country and userAgent are properly stored in dedicated columns instead of being left in tags JSON. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 798fe93 commit 0a41bf1

1 file changed

Lines changed: 12 additions & 33 deletions

File tree

src/Usage/Adapter/ClickHouse.php

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,48 +1335,27 @@ public function addBatch(array $metrics, string $type = Usage::TYPE_EVENT, int $
13351335
$tenant = $this->sharedTables ? $this->resolveTenantFromMetric($metricData) : null;
13361336

13371337
if ($type === Usage::TYPE_EVENT) {
1338-
// Extract event-specific columns from tags
1339-
$path = null;
1340-
$method = null;
1341-
$status = null;
1342-
$resource = null;
1343-
$resourceId = null;
1344-
1345-
if (isset($tags['path'])) {
1346-
$path = (string) $tags['path'];
1347-
unset($tags['path']);
1348-
}
1349-
if (isset($tags['method'])) {
1350-
$method = (string) $tags['method'];
1351-
unset($tags['method']);
1352-
}
1353-
if (isset($tags['status'])) {
1354-
$status = (string) $tags['status'];
1355-
unset($tags['status']);
1356-
}
1357-
if (isset($tags['resource'])) {
1358-
$resource = (string) $tags['resource'];
1359-
unset($tags['resource']);
1360-
}
1361-
if (isset($tags['resourceId'])) {
1362-
$resourceId = (string) $tags['resourceId'];
1363-
unset($tags['resourceId']);
1338+
// Extract event-specific columns from tags into dedicated columns
1339+
$eventColumns = [];
1340+
foreach (Metric::EVENT_COLUMNS as $col) {
1341+
if (isset($tags[$col])) {
1342+
$eventColumns[$col] = (string) $tags[$col];
1343+
unset($tags[$col]);
1344+
} else {
1345+
$eventColumns[$col] = null;
1346+
}
13641347
}
13651348

13661349
ksort($tags);
13671350

1368-
$row = [
1351+
$row = array_merge([
13691352
'id' => $this->generateId(),
13701353
'metric' => $metric,
13711354
'value' => $value,
13721355
'time' => $this->formatDateTime(null),
1373-
'path' => $path,
1374-
'method' => $method,
1375-
'status' => $status,
1376-
'resource' => $resource,
1377-
'resourceId' => $resourceId,
1356+
], $eventColumns, [
13781357
'tags' => $tags,
1379-
];
1358+
]);
13801359
} else {
13811360
// Gauge: simple schema
13821361
ksort($tags);

0 commit comments

Comments
 (0)