Skip to content

Commit

Permalink
feat(core): change configuration warn
Browse files Browse the repository at this point in the history
  • Loading branch information
bozzelliandrea committed Sep 20, 2024
1 parent c2b7b3b commit 4f1ab97
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ PORT=3301
MOCK_TOKEN_ENDPOINT=http://localhost:4005/logto/mock/token
MOCK_KEYS_ENDPOINT=http://localhost:4005/logto/mock/keys

# OGCIO OpenTelemetry config
OTEL_COLLECTOR_URL=http://alloy.local:4317
OTEL_SERVICE_NAME=logto
1 change: 0 additions & 1 deletion docker-compose-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: p0stgr3s
PGPORT: 5433
POSTGRES_DB: logto
healthcheck:
test: [ "CMD-SHELL", "pg_isready" ]
interval: 10s
Expand Down
17 changes: 10 additions & 7 deletions packages/core/src/app/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ export default async function initApp(app: Koa): Promise<void> {
const consoleLog = new ConsoleLog(chalk.blue(requestId));
ctx.requestId = requestId;
ctx.console = consoleLog;
// OGCIO
const loggerOtel = getLogger();
await koaLogger({
transporter: (string, [, _, requestPath]) => {
// Ignoring static file requests in development since vite will load a crazy amount of files
if (!EnvSet.values.isProduction && path.basename(requestPath).includes('.')) {
return;
}

loggerOtel.emit({
severityNumber: logsAPI.SeverityNumber.INFO,
severityText: 'INFO',
body: string,
attributes: { 'log.type': 'LogRecord' },
});
// OGCIO
if (loggerOtel) {
loggerOtel.emit({
severityNumber: logsAPI.SeverityNumber.INFO,
severityText: 'INFO',
body: string,
attributes: { 'log.type': 'LogRecord' },
});
}

consoleLog.plain(string);
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { findUp } from 'find-up';

dotenv.config({ path: await findUp('.env', {}) });

// OGCIO
await import('./instrumentation.js');
await import('./main.js');
7 changes: 4 additions & 3 deletions packages/core/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// OGCIO whole file
import { type Logger } from '@opentelemetry/api-logs';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { W3CTraceContextPropagator } from '@opentelemetry/core';
Expand Down Expand Up @@ -66,10 +67,10 @@ if (OTEL_COLLECTOR_URL) {
}
/* eslint-enable no-console, @silverhand/fp/no-let, @silverhand/fp/no-mutation */

export function getLogger(): Logger {
export function getLogger(): Logger | undefined {
/* eslint-disable @silverhand/fp/no-mutation */
if (!OTEL_COLLECTOR_URL) {
throw new Error('OTEL_COLLECTOR_URL not set. Logger not available!');
return;
}

if (loggerOtel) {
Expand Down Expand Up @@ -107,7 +108,7 @@ process.on('SIGTERM', () => {
console.log('SDK shut down successfully');
},
(error) => {
console.log('Error shutting down SDK', error);
console.error('Error shutting down SDK', error);
}
)
.finally(() => process.exit(0));
Expand Down

0 comments on commit 4f1ab97

Please sign in to comment.