Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ProcessMaker/Multitenancy/SwitchTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ private function overrideConfigs(Application $app, IsTenant $tenant)
$app->make('log')->reset();
$app->forgetInstance('log');

// Used for setting the tenantId context when streaming logs to Loki
$app->afterResolving('log', function ($log) use ($tenant) {
$log->shareContext([
'tenantId' => $tenant->id,
'appUrl' => $tenant->config['app.url'],
]);
});

// url() helper
app(UrlGenerator::class)->useOrigin($tenant->config['app.url']);

Expand Down
23 changes: 23 additions & 0 deletions ProcessMaker/Providers/ProcessMakerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function boot(): void

$this->checkConfigCache();

$this->shareServiceLogContext();

// Hook after service providers boot
self::$bootTime = (microtime(true) - self::$bootStart) * 1000; // Convert to milliseconds
}
Expand Down Expand Up @@ -634,4 +636,25 @@ private function checkConfigCache(): void
});
}
}

/**
* Share non-tenant log context (service/replica from k8s hostname) for Loki.
*/
private function shareServiceLogContext(): void
{
$this->app->afterResolving('log', function ($log) {
$pattern = '/^(?:.*-)?([^-]+)-[^-]+-([^-]+)$/';
$service = '';
$replica = '';
if (preg_match($pattern, config('app.hostname'), $matches)) {
$service = $matches[1];
$replica = $matches[2];
}

$log->shareContext([
'service' => $service,
'replica' => $replica,
]);
});
}
}
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,6 @@
'claim_timeout_minutes' => env('SCHEDULER_CLAIM_TIMEOUT_MINUTES', 5),
'bpmn_timer_overlap_minutes' => env('SCHEDULER_BPMN_TIMER_OVERLAP_MINUTES', 5),
],

'hostname' => env('HOSTNAME', ''),
];
10 changes: 9 additions & 1 deletion config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
|
*/

'deprecations' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
'deprecations' => [
'channel' => 'deprecations',
'trace' => false,
],

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -135,6 +138,11 @@
'level' => 'debug',
'days' => env('DATA_SOURCE_CLEAR_LOG', 7),
],
'deprecations' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
'level' => 'emergency',
],
],

];
Loading