@omen.foundation/node-microservice-runtime 0.1.50 → 0.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,cAAc,EACd,aAAa,EACb,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACtF,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACvF,YAAY,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,iBAAiB,EACjB,KAAK,eAAe,EACpB,eAAe,EACf,YAAY,EACZ,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC/G,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,+B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AK,uBAAuB,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC/G,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,KAAK,oCAAoC,EACzC,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,8BAA8B,EAC9B,0BAA0B,EAC1B,sBAAsB,EACtB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,EACnB,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC;AAsBhC,eAAO,MAAM,OAAO,QAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ export { MicroserviceRuntime, runMicroservice } from './runtime.js';
7
7
  export { InventoryUpdateBuilder, createInventoryService, } from './inventory.js';
8
8
  export { StorageService, StorageObject, getStorageMetadata, listRegisteredStorageObjects } from './storage.js';
9
9
  export { FederationComponent, FederationRegistry, getFederationComponents, FederatedInventory, } from './federation.js';
10
- export { isCollectorRunning, getClickHouseCredentialsStatus, fetchClickHouseCredentials, addAuthEnvironmentVars, getCollectorProcessStatus, setupCollectorBeforeLogging, } from './collector-manager.js';
10
+ export { isCollectorRunning, getClickHouseCredentialsStatus, fetchClickHouseCredentials, addAuthEnvironmentVars, getCollectorProcessStatus, setupCollectorBeforeLogging, startCollectorAsync, } from './collector-manager.js';
11
11
  // Export runtime version - read from package.json dynamically
12
12
  import { readFileSync } from 'fs';
13
13
  import { createRequire } from 'module';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
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,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC3D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QACvE,OAAO,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yCAAyC;QACzC,OAAO,CAAC,IAAI,CAAC,qEAAqE,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5I,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC","sourcesContent":["export {\r\n Microservice,\r\n Callable,\r\n ClientCallable,\r\n ServerCallable,\r\n AdminCallable,\r\n SwaggerCategory,\r\n SwaggerTags,\r\n ConfigureServices,\r\n InitializeServices,\r\n} from './decorators.js';\r\nexport type { MicroserviceOptions, CallableOptions, ServiceAccess } from './types.js';\r\nexport type { EnvironmentConfig, RequestContext, ServiceDefinition } from './types.js';\r\nexport type { BeamableMicroserviceServices, BoundBeamApi } from './services.js';\r\nexport { BeamableServiceManager } from './services.js';\r\nexport {\r\n DependencyBuilder,\r\n type DependencyScope,\r\n ServiceLifetime,\r\n LOGGER_TOKEN,\r\n ENVIRONMENT_CONFIG_TOKEN,\r\n REQUEST_CONTEXT_TOKEN,\r\n BEAMABLE_SERVICES_TOKEN,\r\n} from './dependency.js';\r\nexport { loadEnvironmentConfig } from './env.js';\r\nexport { BeamableRuntimeError } from './errors.js';\r\nexport { MicroserviceRuntime, runMicroservice } from './runtime.js';\r\nexport {\r\n InventoryUpdateBuilder,\r\n createInventoryService,\r\n type InventoryUpdatePayload,\r\n type InventoryBuilderOptions,\r\n} from './inventory.js';\r\nexport { StorageService, StorageObject, getStorageMetadata, listRegisteredStorageObjects } from './storage.js';\r\nexport {\r\n FederationComponent,\r\n FederationRegistry,\r\n getFederationComponents,\r\n FederatedInventory,\r\n type FederationIdentity,\r\n type FederatedAuthenticationRequest,\r\n type FederatedAuthenticationResponse,\r\n type FederatedInventoryProxyState,\r\n type FederatedInventoryStateRequest,\r\n type FederatedInventoryTransactionRequest,\r\n type FederatedItemCreateRequest,\r\n type FederatedItemDeleteRequest,\r\n type FederatedItemUpdateRequest,\r\n type FederatedItemProperty,\r\n type FederatedItemProxy,\r\n} from './federation.js';\r\nexport {\r\n isCollectorRunning,\r\n getClickHouseCredentialsStatus,\r\n fetchClickHouseCredentials,\r\n addAuthEnvironmentVars,\r\n getCollectorProcessStatus,\r\n setupCollectorBeforeLogging,\r\n type CollectorStatus,\r\n} from './collector-manager.js';\r\n\r\n// Export runtime version - read from package.json dynamically\r\nimport { readFileSync } from 'fs';\r\nimport { createRequire } from 'module';\r\n\r\nfunction getPackageVersion(): string {\r\n try {\r\n // Use createRequire to get a require function that works in both ESM and CJS\r\n // This allows us to resolve the package.json path relative to this module\r\n // @ts-ignore - import.meta is ESM-only, TypeScript error in CJS is expected\r\n const require = createRequire(import.meta.url);\r\n const packageJsonPath = require.resolve('../package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n return packageJson.version || '0.0.0';\r\n } catch (error) {\r\n // Fallback if package.json can't be read\r\n console.warn('[Runtime] Failed to read version from package.json, using fallback:', error instanceof Error ? error.message : String(error));\r\n return '0.0.0';\r\n }\r\n}\r\n\r\nexport const VERSION = getPackageVersion();\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,cAAc,EACd,aAAa,EACb,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,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O,CAAC,IAAI,CAAC,qEAAqE,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5I,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC","sourcesContent":["export {\r\n Microservice,\r\n Callable,\r\n ClientCallable,\r\n ServerCallable,\r\n AdminCallable,\r\n SwaggerCategory,\r\n SwaggerTags,\r\n ConfigureServices,\r\n InitializeServices,\r\n} from './decorators.js';\r\nexport type { MicroserviceOptions, CallableOptions, ServiceAccess } from './types.js';\r\nexport type { EnvironmentConfig, RequestContext, ServiceDefinition } from './types.js';\r\nexport type { BeamableMicroserviceServices, BoundBeamApi } from './services.js';\r\nexport { BeamableServiceManager } from './services.js';\r\nexport {\r\n DependencyBuilder,\r\n type DependencyScope,\r\n ServiceLifetime,\r\n LOGGER_TOKEN,\r\n ENVIRONMENT_CONFIG_TOKEN,\r\n REQUEST_CONTEXT_TOKEN,\r\n BEAMABLE_SERVICES_TOKEN,\r\n} from './dependency.js';\r\nexport { loadEnvironmentConfig } from './env.js';\r\nexport { BeamableRuntimeError } from './errors.js';\r\nexport { MicroserviceRuntime, runMicroservice } from './runtime.js';\r\nexport {\r\n InventoryUpdateBuilder,\r\n createInventoryService,\r\n type InventoryUpdatePayload,\r\n type InventoryBuilderOptions,\r\n} from './inventory.js';\r\nexport { StorageService, StorageObject, getStorageMetadata, listRegisteredStorageObjects } from './storage.js';\r\nexport {\r\n FederationComponent,\r\n FederationRegistry,\r\n getFederationComponents,\r\n FederatedInventory,\r\n type FederationIdentity,\r\n type FederatedAuthenticationRequest,\r\n type FederatedAuthenticationResponse,\r\n type FederatedInventoryProxyState,\r\n type FederatedInventoryStateRequest,\r\n type FederatedInventoryTransactionRequest,\r\n type FederatedItemCreateRequest,\r\n type FederatedItemDeleteRequest,\r\n type FederatedItemUpdateRequest,\r\n type FederatedItemProperty,\r\n type FederatedItemProxy,\r\n} from './federation.js';\r\nexport {\r\n isCollectorRunning,\r\n getClickHouseCredentialsStatus,\r\n fetchClickHouseCredentials,\r\n addAuthEnvironmentVars,\r\n getCollectorProcessStatus,\r\n setupCollectorBeforeLogging,\r\n startCollectorAsync,\r\n type CollectorStatus,\r\n} from './collector-manager.js';\r\n\r\n// Export runtime version - read from package.json dynamically\r\nimport { readFileSync } from 'fs';\r\nimport { createRequire } from 'module';\r\n\r\nfunction getPackageVersion(): string {\r\n try {\r\n // Use createRequire to get a require function that works in both ESM and CJS\r\n // This allows us to resolve the package.json path relative to this module\r\n // @ts-ignore - import.meta is ESM-only, TypeScript error in CJS is expected\r\n const require = createRequire(import.meta.url);\r\n const packageJsonPath = require.resolve('../package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n return packageJson.version || '0.0.0';\r\n } catch (error) {\r\n // Fallback if package.json can't be read\r\n console.warn('[Runtime] Failed to read version from package.json, using fallback:', error instanceof Error ? error.message : String(error));\r\n return '0.0.0';\r\n }\r\n}\r\n\r\nexport const VERSION = getPackageVersion();\r\n"]}
package/dist/logger.cjs CHANGED
@@ -32,9 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
35
  Object.defineProperty(exports, "__esModule", { value: true });
39
36
  exports.createLogger = createLogger;
40
37
  const pino_1 = __importStar(require("pino"));
@@ -46,7 +43,6 @@ const sdk_logs_1 = require("@opentelemetry/sdk-logs");
46
43
  const exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
47
44
  const resources_1 = require("@opentelemetry/resources");
48
45
  const collector_manager_js_1 = require("./collector-manager.js");
49
- const deasync_1 = __importDefault(require("deasync"));
50
46
  function getRequire() {
51
47
  if (typeof require !== 'undefined' && typeof require.main !== 'undefined') {
52
48
  return require;
@@ -361,72 +357,14 @@ function createBeamableLogFormatter(serviceName, qualifiedServiceName, otlpProvi
361
357
  },
362
358
  });
363
359
  }
364
- function initializeOtlpSync(serviceName, qualifiedServiceName, env, timeoutMs = 60000) {
365
- const isInDocker = process.env.IS_LOCAL !== '1' && process.env.IS_LOCAL !== 'true';
366
- const useLocalOtel = !!process.env.BEAM_LOCAL_OTEL;
367
- const standardOtelEnabled = (isInDocker || useLocalOtel) && !process.env.BEAM_DISABLE_STANDARD_OTEL;
368
- const hasExplicitEndpoint = !!process.env.BEAM_OTEL_EXPORTER_OTLP_ENDPOINT;
369
- if (!standardOtelEnabled && !hasExplicitEndpoint) {
370
- return null;
371
- }
372
- const initLogger = (0, pino_1.default)({
373
- name: 'beamable-otlp-init',
374
- level: 'info',
375
- }, process.stdout);
376
- let provider = null;
377
- let completed = false;
378
- let initError = null;
379
- initializeOtlpLogging(serviceName, qualifiedServiceName, env, initLogger).then((result) => {
380
- provider = result;
381
- completed = true;
382
- if (result) {
383
- initLogger.info('[OTLP] OpenTelemetry logging initialized successfully');
384
- }
385
- return result;
386
- }).catch((error) => {
387
- initError = error instanceof Error ? error : new Error(String(error));
388
- completed = true;
389
- initLogger.error(`[OTLP] Failed to initialize: ${initError.message}`);
390
- return null;
391
- });
392
- const startTime = Date.now();
393
- const timeoutId = setTimeout(() => {
394
- if (!completed) {
395
- initLogger.warn(`[OTLP] Initialization timeout after ${timeoutMs}ms, continuing without OTLP`);
396
- completed = true;
397
- }
398
- }, timeoutMs);
399
- try {
400
- deasync_1.default.loopWhile(() => {
401
- const elapsed = Date.now() - startTime;
402
- if (elapsed >= timeoutMs) {
403
- initLogger.warn(`[OTLP] Synchronous wait timeout after ${elapsed}ms`);
404
- return false;
405
- }
406
- return !completed;
407
- });
408
- }
409
- catch (error) {
410
- initLogger.error(`[OTLP] Error during synchronous wait: ${error instanceof Error ? error.message : String(error)}`);
411
- }
412
- clearTimeout(timeoutId);
413
- if (completed && provider) {
414
- initLogger.info('[OTLP] Initialization completed successfully, collector is ready');
415
- }
416
- else if (!completed) {
417
- initLogger.warn('[OTLP] Initialization did not complete in time, logs may not be sent via OTLP initially');
418
- initLogger.warn('[OTLP] Service will continue without OTLP telemetry - requests will still be serviced');
419
- }
420
- else {
421
- initLogger.warn('[OTLP] Initialization completed but no provider returned, OTLP telemetry disabled');
422
- }
423
- return provider;
424
- }
425
360
  function createLogger(env, options = {}) {
426
361
  var _a, _b, _c;
427
362
  const configuredDestination = (_a = options.destinationPath) !== null && _a !== void 0 ? _a : process.env.LOG_PATH;
428
363
  const usePrettyLogs = shouldUsePrettyLogs();
429
- let otlpProvider = null;
364
+ const isInDocker = process.env.IS_LOCAL !== '1' && process.env.IS_LOCAL !== 'true';
365
+ const useLocalOtel = !!process.env.BEAM_LOCAL_OTEL;
366
+ const standardOtelEnabled = (isInDocker || useLocalOtel) && !process.env.BEAM_DISABLE_STANDARD_OTEL;
367
+ const otlpProviderRef = { provider: null };
430
368
  if (options.otlpEndpoint) {
431
369
  const originalEndpoint = process.env.BEAM_OTEL_EXPORTER_OTLP_ENDPOINT;
432
370
  process.env.BEAM_OTEL_EXPORTER_OTLP_ENDPOINT = options.otlpEndpoint;
@@ -456,7 +394,7 @@ function createLogger(env, options = {}) {
456
394
  }
457
395
  return !completed;
458
396
  });
459
- otlpProvider = provider;
397
+ otlpProviderRef.provider = provider;
460
398
  if (originalEndpoint !== undefined) {
461
399
  process.env.BEAM_OTEL_EXPORTER_OTLP_ENDPOINT = originalEndpoint;
462
400
  }
@@ -465,9 +403,25 @@ function createLogger(env, options = {}) {
465
403
  }
466
404
  }
467
405
  else {
468
- otlpProvider = initializeOtlpSync(options.serviceName, options.qualifiedServiceName, env, 60000);
406
+ otlpProviderRef.provider = null;
407
+ if (standardOtelEnabled) {
408
+ (async () => {
409
+ await new Promise(resolve => setTimeout(resolve, 2000));
410
+ try {
411
+ const discoveredEndpoint = await (0, collector_manager_js_1.discoverOrStartCollector)((0, pino_1.default)({ name: 'beamable-otlp-bg', level: 'info' }, process.stdout), standardOtelEnabled, env);
412
+ if (discoveredEndpoint) {
413
+ const newProvider = await initializeOtlpLogging(options.serviceName, options.qualifiedServiceName, env, (0, pino_1.default)({ name: 'beamable-otlp-bg', level: 'info' }, process.stdout));
414
+ if (newProvider) {
415
+ otlpProviderRef.provider = newProvider;
416
+ console.error(`[OTLP] Connected to collector at ${discoveredEndpoint} (background connection)`);
417
+ }
418
+ }
419
+ }
420
+ catch (error) {
421
+ }
422
+ })();
423
+ }
469
424
  }
470
- const otlpProviderRef = { provider: otlpProvider };
471
425
  const pinoOptions = {
472
426
  name: (_b = options.name) !== null && _b !== void 0 ? _b : 'beamable-node-runtime',
473
427
  level: env.logLevel,
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAa,EAAe,KAAK,MAAM,EAAsB,MAAM,MAAM,CAAC;AAI1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAkCpD,UAAU,oBAAoB;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAylBD,wBAAgB,YAAY,CAAC,GAAG,EAAE,iBAAiB,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAyJ/F"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAa,EAAe,KAAK,MAAM,EAAsB,MAAM,MAAM,CAAC;AAI1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAiCpD,UAAU,oBAAoB;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA8eD,wBAAgB,YAAY,CAAC,GAAG,EAAE,iBAAiB,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CA8L/F"}
package/dist/logger.js CHANGED
@@ -7,7 +7,6 @@ import { LoggerProvider, SimpleLogRecordProcessor } from '@opentelemetry/sdk-log
7
7
  import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
8
8
  import { resourceFromAttributes, defaultResource } from '@opentelemetry/resources';
9
9
  import { discoverOrStartCollector } from './collector-manager.js';
10
- import deasync from 'deasync';
11
10
  function getRequire() {
12
11
  // Check if we're in CJS context (require.main exists)
13
12
  if (typeof require !== 'undefined' && typeof require.main !== 'undefined') {
@@ -480,104 +479,18 @@ function createBeamableLogFormatter(serviceName, qualifiedServiceName, otlpProvi
480
479
  },
481
480
  });
482
481
  }
483
- /**
484
- * Synchronously initializes OTLP logging with a timeout.
485
- * This ensures OTLP is ready before any logs are emitted.
486
- * Similar to C# microservices which configure logging early in startup.
487
- *
488
- * Uses a blocking wait mechanism to ensure initialization completes before returning.
489
- */
490
- function initializeOtlpSync(serviceName, qualifiedServiceName, env, timeoutMs = 60000 // 60 seconds to allow collector download, startup, and readiness check
491
- ) {
492
- // Match C# logic: (this.InDocker() || UseLocalOtel) && !BEAM_DISABLE_STANDARD_OTEL
493
- const isInDocker = process.env.IS_LOCAL !== '1' && process.env.IS_LOCAL !== 'true';
494
- const useLocalOtel = !!process.env.BEAM_LOCAL_OTEL;
495
- const standardOtelEnabled = (isInDocker || useLocalOtel) && !process.env.BEAM_DISABLE_STANDARD_OTEL;
496
- const hasExplicitEndpoint = !!process.env.BEAM_OTEL_EXPORTER_OTLP_ENDPOINT;
497
- // If OTLP is not needed, return immediately
498
- if (!standardOtelEnabled && !hasExplicitEndpoint) {
499
- return null;
500
- }
501
- // Create a minimal console logger for initialization messages
502
- const initLogger = pino({
503
- name: 'beamable-otlp-init',
504
- level: 'info',
505
- }, process.stdout);
506
- // If collector was already set up via setupCollectorBeforeLogging,
507
- // discoverOrStartCollector will find it and use a shorter timeout.
508
- // If not, it will start it (with full timeout).
509
- // Use deasync to wait synchronously for the async initialization
510
- // This allows the event loop to process while we wait, enabling async operations
511
- // (like collector download) to complete
512
- let provider = null;
513
- let completed = false;
514
- let initError = null;
515
- // Start initialization promise (callbacks set flags for deasync.loopWhile to check)
516
- initializeOtlpLogging(serviceName, qualifiedServiceName, env, initLogger).then((result) => {
517
- provider = result;
518
- completed = true;
519
- if (result) {
520
- initLogger.info('[OTLP] OpenTelemetry logging initialized successfully');
521
- }
522
- return result;
523
- }).catch((error) => {
524
- initError = error instanceof Error ? error : new Error(String(error));
525
- completed = true;
526
- initLogger.error(`[OTLP] Failed to initialize: ${initError.message}`);
527
- return null;
528
- });
529
- // Set timeout to prevent infinite wait
530
- const startTime = Date.now();
531
- const timeoutId = setTimeout(() => {
532
- if (!completed) {
533
- initLogger.warn(`[OTLP] Initialization timeout after ${timeoutMs}ms, continuing without OTLP`);
534
- completed = true;
535
- }
536
- }, timeoutMs);
537
- // Wait synchronously for the promise to resolve using deasync
538
- // deasync.loopWhile() allows event loop to process while we wait
539
- // This enables async operations (like collector download) to run and complete
540
- // CRITICAL: This must complete before the logger is created to capture all startup logs
541
- try {
542
- // Use deasync to wait for completion, with timeout check
543
- // loopWhile returns false to stop waiting, true to continue
544
- deasync.loopWhile(() => {
545
- // Check if we've exceeded timeout
546
- const elapsed = Date.now() - startTime;
547
- if (elapsed >= timeoutMs) {
548
- initLogger.warn(`[OTLP] Synchronous wait timeout after ${elapsed}ms`);
549
- return false; // Stop waiting
550
- }
551
- // Continue waiting if not completed
552
- // This allows the event loop to process async operations
553
- return !completed;
554
- });
555
- }
556
- catch (error) {
557
- // If deasync fails, log and continue
558
- initLogger.error(`[OTLP] Error during synchronous wait: ${error instanceof Error ? error.message : String(error)}`);
559
- }
560
- clearTimeout(timeoutId);
561
- // Verify we got a provider (collector is ready)
562
- if (completed && provider) {
563
- initLogger.info('[OTLP] Initialization completed successfully, collector is ready');
564
- }
565
- else if (!completed) {
566
- initLogger.warn('[OTLP] Initialization did not complete in time, logs may not be sent via OTLP initially');
567
- initLogger.warn('[OTLP] Service will continue without OTLP telemetry - requests will still be serviced');
568
- }
569
- else {
570
- initLogger.warn('[OTLP] Initialization completed but no provider returned, OTLP telemetry disabled');
571
- }
572
- return provider;
573
- }
574
482
  export function createLogger(env, options = {}) {
575
483
  const configuredDestination = options.destinationPath ?? process.env.LOG_PATH;
576
484
  const usePrettyLogs = shouldUsePrettyLogs();
577
485
  // Initialize OTLP synchronously BEFORE creating the logger
578
486
  // If otlpEndpoint is provided (collector already set up), create provider directly
579
487
  // Otherwise, try to discover/start collector (with timeout)
580
- let otlpProvider = null;
488
+ // Check if standard OTLP is enabled (needed for the else branch)
489
+ const isInDocker = process.env.IS_LOCAL !== '1' && process.env.IS_LOCAL !== 'true';
490
+ const useLocalOtel = !!process.env.BEAM_LOCAL_OTEL;
491
+ const standardOtelEnabled = (isInDocker || useLocalOtel) && !process.env.BEAM_DISABLE_STANDARD_OTEL;
492
+ // Shared reference for OTLP logger provider (create before async operations)
493
+ const otlpProviderRef = { provider: null };
581
494
  if (options.otlpEndpoint) {
582
495
  // Collector is already set up, create OTLP provider directly without discovery/startup
583
496
  // Set endpoint in env temporarily so initializeOtlpLogging uses it directly
@@ -614,7 +527,7 @@ export function createLogger(env, options = {}) {
614
527
  }
615
528
  return !completed;
616
529
  });
617
- otlpProvider = provider;
530
+ otlpProviderRef.provider = provider;
618
531
  // Restore original endpoint if it existed
619
532
  if (originalEndpoint !== undefined) {
620
533
  process.env.BEAM_OTEL_EXPORTER_OTLP_ENDPOINT = originalEndpoint;
@@ -624,13 +537,37 @@ export function createLogger(env, options = {}) {
624
537
  }
625
538
  }
626
539
  else {
627
- // No endpoint provided - try to discover/start collector (full initialization)
628
- // This ensures all logs from this point forward are captured via OTLP
629
- otlpProvider = initializeOtlpSync(options.serviceName, options.qualifiedServiceName, env, 60000 // 60 second timeout to allow collector download, startup, and readiness verification
630
- );
540
+ // No endpoint provided - collector is starting asynchronously in background
541
+ // Don't block here - logger works immediately via stdout, OTLP will connect when collector is ready
542
+ otlpProviderRef.provider = null; // Start without OTLP - will connect when collector is ready
543
+ // Start async discovery in background (non-blocking)
544
+ // This allows the service to start immediately while collector is downloading/starting
545
+ if (standardOtelEnabled) {
546
+ // Try to discover collector asynchronously (won't block service startup)
547
+ // If collector is already running, we'll connect immediately
548
+ // If not, we'll retry periodically in the background
549
+ (async () => {
550
+ // Give collector a moment to start (if it's just starting)
551
+ await new Promise(resolve => setTimeout(resolve, 2000));
552
+ // Try to discover collector (quick check, non-blocking)
553
+ try {
554
+ const discoveredEndpoint = await discoverOrStartCollector(pino({ name: 'beamable-otlp-bg', level: 'info' }, process.stdout), standardOtelEnabled, env);
555
+ if (discoveredEndpoint) {
556
+ // Collector is ready - initialize OTLP logging now
557
+ const newProvider = await initializeOtlpLogging(options.serviceName, options.qualifiedServiceName, env, pino({ name: 'beamable-otlp-bg', level: 'info' }, process.stdout));
558
+ if (newProvider) {
559
+ // Update the provider reference so future logs use OTLP
560
+ otlpProviderRef.provider = newProvider;
561
+ console.error(`[OTLP] Connected to collector at ${discoveredEndpoint} (background connection)`);
562
+ }
563
+ }
564
+ }
565
+ catch (error) {
566
+ // Silently fail - collector will connect later if it starts
567
+ }
568
+ })(); // Fire and forget - don't await
569
+ }
631
570
  }
632
- // Shared reference for OTLP logger provider
633
- const otlpProviderRef = { provider: otlpProvider };
634
571
  const pinoOptions = {
635
572
  name: options.name ?? 'beamable-node-runtime',
636
573
  level: env.logLevel,