Skip to content

Conversation

@ritoban23
Copy link
Contributor

@ritoban23 ritoban23 commented Oct 17, 2025

Add OTEL Namespace to Logging Package

Creates a reusable OpenTelemetry logger configuration to eliminate code duplication between provider-proxy and api apps.

Changes

  • Add @akashnetwork/logging/otel export with createOtelLogger function
  • Add @opentelemetry/api as optional peer dependency
  • Refactor provider-proxy to use createOtelLogger
  • Refactor api to set global OTEL mixin in logging.provider.ts
  • Remove apps/provider-proxy/src/setupOpenTelemetry.ts
  • Remove apps/api/src/open-telemetry.ts

Benefits

  • Eliminates code duplication
  • Centralized OTEL configuration
  • Consistent logging across apps
  • Easier maintenance and updates

Closes #1801

Summary by CodeRabbit

  • Refactor

    • Made OpenTelemetry initialization opt-in by removing automatic startup instrumentation and moving OTEL handling into the logging path.
  • New Features

    • Added an OTEL-aware logger creator that attaches span context to logs for improved distributed-tracing observability.
  • Chores

    • Exported the new OTEL logger from the logging package and declared the OpenTelemetry API as an optional peer dependency.

@ritoban23 ritoban23 requested a review from a team as a code owner October 17, 2025 09:19
@coderabbitai
Copy link

coderabbitai bot commented Oct 17, 2025

Walkthrough

Removes module-level OpenTelemetry mixins and side-effect OTEL imports from apps, adds a reusable OTEL integration in the logging package (collectOtel and createOtelLogger), and updates applications to instantiate OTEL-aware loggers via the new factory instead of global mixins.

Changes

Cohort / File(s) Summary
Removed OTEL mixin modules
apps/api/src/open-telemetry.ts, apps/provider-proxy/src/setupOpenTelemetry.ts
Deleted code that assigned LoggerService.mixin to collect OpenTelemetry span context; mixin method removed.
Cleared side-effect OTEL imports in apps
apps/api/src/console.ts, apps/api/src/server.ts, apps/provider-proxy/src/server.ts
Removed imports of ./open-telemetry / ./setupOpenTelemetry, eliminating module-level OTEL initialization side effects.
Logging package: new OTEL export & deps
packages/logging/package.json, packages/logging/src/otel.ts
Added public export ./otel -> ./src/otel.ts; added optional peerDependency @opentelemetry/api; implemented collectOtel() and createOtelLogger(options?).
Apps switched to factory-created OTEL loggers
apps/api/src/core/providers/logging.provider.ts, apps/provider-proxy/src/container.ts
Replaced direct new LoggerService(...) and global mixin usage with createOtelLogger(...); added export class LoggerService extends LoggerServiceOriginal {} wrapper in API provider file to preserve exported class shape.

Sequence Diagram(s)

sequenceDiagram
    participant App as App (console/server/container)
    participant Factory as createOtelLogger()
    participant OtelAPI as @opentelemetry/api
    participant Logger as LoggerService

    rect rgb(250,240,240)
    Note over App,Logger: Old flow (module-level mixin)
    App->>App: import "./open-telemetry" (side-effect)
    App->>Logger: LoggerService.mixin = collect span
    App->>Logger: new LoggerService(...)
    Logger-->>App: logger instance (global mixin applied)
    end

    rect rgb(240,250,240)
    Note over App,Factory: New flow (factory)
    App->>Factory: createOtelLogger(options)
    Factory->>OtelAPI: context.active() / trace.getSpan(...)
    OtelAPI-->>Factory: current span / spanContext
    Factory->>Logger: new LoggerService({...options, mixin: collectOtel})
    Logger-->>Factory: pre-configured logger
    Factory-->>App: return logger instance
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • baktun14

Poem

🐇
I nibble traces from the active span,
tuck them into logs with a gentle paw.
One clean factory, no scattered yeast,
carrots of context, tidy at least.
Hop — the logs are snug, and that’s the law.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Linked Issues Check ❓ Inconclusive Most objectives from issue #1801 are met: the @akashnetwork/logging/otel export is added to package.json with createOtelLogger and collectOtel functions [packages/logging/src/otel.ts and package.json], provider-proxy is refactored to use createOtelLogger with setupOpenTelemetry.ts removed [apps/provider-proxy/src/container.ts and server.ts], and console-api is refactored with open-telemetry.ts removed [apps/api/src/console.ts, server.ts, and logging.provider.ts]. However, the raw summary for packages/logging/src/otel.ts does not explicitly mention the baggage extraction logic for sentry-release that was specified in objective #1801, creating uncertainty about whether this requirement was fully implemented. Please verify that the collectOtel() function in packages/logging/src/otel.ts includes baggage extraction logic to retrieve the sentry-release version as specified in issue #1801. If this logic is present, the check would pass; if absent, the implementation does not fully satisfy the linked issue requirements.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat: add otel namespace to logging package" accurately reflects the primary change in the changeset. The main objective is to introduce a new @akashnetwork/logging/otel export with reusable OpenTelemetry logger configuration functions, which is precisely what the title conveys. The title is concise, specific, and clearly communicates the feature being added without unnecessary detail.
Out of Scope Changes Check ✅ Passed All code changes in this PR are directly aligned with the objectives from issue #1801. The modifications include: consolidating OTEL logger configuration into the logging package with new exports, refactoring both provider-proxy and console-api applications to use the centralized createOtelLogger function, and removing duplicate OTEL setup files (setupOpenTelemetry.ts and open-telemetry.ts). No unrelated changes or files beyond the stated scope of eliminating code duplication and centralizing OTEL configuration are present.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9fe60c7 and 3949407.

📒 Files selected for processing (9)
  • apps/api/src/console.ts (0 hunks)
  • apps/api/src/core/providers/logging.provider.ts (1 hunks)
  • apps/api/src/open-telemetry.ts (0 hunks)
  • apps/api/src/server.ts (0 hunks)
  • apps/provider-proxy/src/container.ts (3 hunks)
  • apps/provider-proxy/src/server.ts (0 hunks)
  • apps/provider-proxy/src/setupOpenTelemetry.ts (0 hunks)
  • packages/logging/package.json (2 hunks)
  • packages/logging/src/otel.ts (1 hunks)
💤 Files with no reviewable changes (5)
  • apps/provider-proxy/src/setupOpenTelemetry.ts
  • apps/api/src/console.ts
  • apps/provider-proxy/src/server.ts
  • apps/api/src/server.ts
  • apps/api/src/open-telemetry.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/logging/src/otel.ts
  • apps/api/src/core/providers/logging.provider.ts
  • apps/provider-proxy/src/container.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: Validate local packages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f0a134 and 5890d54.

📒 Files selected for processing (9)
  • apps/api/src/console.ts (0 hunks)
  • apps/api/src/core/providers/logging.provider.ts (1 hunks)
  • apps/api/src/open-telemetry.ts (0 hunks)
  • apps/api/src/server.ts (0 hunks)
  • apps/provider-proxy/src/container.ts (3 hunks)
  • apps/provider-proxy/src/server.ts (0 hunks)
  • apps/provider-proxy/src/setupOpenTelemetry.ts (0 hunks)
  • packages/logging/package.json (2 hunks)
  • packages/logging/src/otel.ts (1 hunks)
💤 Files with no reviewable changes (5)
  • apps/provider-proxy/src/setupOpenTelemetry.ts
  • apps/provider-proxy/src/server.ts
  • apps/api/src/console.ts
  • apps/api/src/server.ts
  • apps/api/src/open-telemetry.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • packages/logging/src/otel.ts
  • apps/provider-proxy/src/container.ts
  • apps/api/src/core/providers/logging.provider.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • packages/logging/src/otel.ts
  • apps/provider-proxy/src/container.ts
  • apps/api/src/core/providers/logging.provider.ts
🧬 Code graph analysis (3)
packages/logging/src/otel.ts (1)
packages/logging/src/services/logger/logger.service.ts (1)
  • LoggerOptions (18-21)
apps/provider-proxy/src/container.ts (2)
packages/logging/src/otel.ts (1)
  • createOtelLogger (20-22)
apps/provider-proxy/src/services/CertificateValidator/CertificateValidator.ts (1)
  • createCertificateValidatorInstrumentation (84-99)
apps/api/src/core/providers/logging.provider.ts (1)
apps/api/src/core/services/execution-context/execution-context.service.ts (1)
  • context (18-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: Validate local packages
🔇 Additional comments (7)
apps/provider-proxy/src/container.ts (2)

3-3: LGTM: Import added for centralized OTEL logger.

The import correctly references the new @akashnetwork/logging/otel export introduced in this PR.


16-16: LGTM: Logger instantiations correctly migrated to createOtelLogger.

All logger instances now use the centralized OTEL-aware factory function, eliminating code duplication and ensuring consistent trace context injection.

Also applies to: 32-32, 35-36

apps/api/src/core/providers/logging.provider.ts (1)

3-3: LGTM: OpenTelemetry API imported for mixin.

The import correctly brings in the necessary APIs for trace context collection.

packages/logging/package.json (2)

14-14: LGTM: Export added for OTEL logger factory.

The export correctly maps ./otel to the new otel.ts module, enabling consumers to import the centralized OTEL logger creation function.


38-38: LGTM: Peer dependency correctly configured.

The @opentelemetry/api peer dependency version ^1.9.0 is current and stable, and the optional flag appropriately reflects that OTEL integration is opt-in. Based on learnings.

Also applies to: 44-46

packages/logging/src/otel.ts (2)

1-4: LGTM: Imports are correct.

The necessary OpenTelemetry APIs and logging service types are correctly imported.


20-22: LGTM: Factory function correctly creates OTEL-aware logger.

The createOtelLogger function correctly instantiates a LoggerService with the collectOtel mixin, ensuring trace context is automatically injected into all log entries.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
apps/provider-proxy/src/container.ts (2)

15-15: DRY the logger creation with a tiny helper.

Avoid repeating the isLoggingDisabled ? undefined : createOtelLogger({ name }) ternary; define once and reuse.

   const isLoggingDisabled = process.env.NODE_ENV === "test";
 
+  const mkLogger = (name: string) => (isLoggingDisabled ? undefined : createOtelLogger({ name }));
+
   const wsStats = new WebsocketStats();
-  const appLogger = isLoggingDisabled ? undefined : createOtelLogger({ name: "app" });
+  const appLogger = mkLogger("app");
@@
-    isLoggingDisabled ? undefined : createCertificateValidatorInstrumentation(createOtelLogger({ name: "cert-validator" }))
+    (mkLogger("cert-validator")
+      ? createCertificateValidatorInstrumentation(mkLogger("cert-validator")!)
+      : undefined)
@@
-  const wsLogger = isLoggingDisabled ? undefined : createOtelLogger({ name: "ws" });
-  const httpLogger = isLoggingDisabled ? undefined : createOtelLogger({ name: "http" });
+  const wsLogger = mkLogger("ws");
+  const httpLogger = mkLogger("http");

Also applies to: 31-31, 34-35


34-36: Confirm interceptor constructor tolerates undefined logger; guard if not.

If HttpLoggerIntercepter expects a concrete logger, passing undefined when tests run will throw. Guard creation or make the parameter optional.

-  const httpLoggerInterceptor = new HttpLoggerIntercepter(httpLogger);
+  const httpLoggerInterceptor = httpLogger
+    ? new HttpLoggerIntercepter(httpLogger)
+    : undefined as unknown as HttpLoggerIntercepter; // if type must exist in the container, consider a Noop interceptor instead

If types don’t allow undefined, consider exporting a Noop interceptor from the logging package and use that in tests.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5890d54 and e164386.

📒 Files selected for processing (1)
  • apps/provider-proxy/src/container.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/provider-proxy/src/container.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/provider-proxy/src/container.ts
🧬 Code graph analysis (1)
apps/provider-proxy/src/container.ts (2)
packages/logging/src/otel.ts (1)
  • createOtelLogger (20-22)
apps/provider-proxy/src/services/CertificateValidator/CertificateValidator.ts (1)
  • createCertificateValidatorInstrumentation (84-99)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: Validate local packages
🔇 Additional comments (1)
apps/provider-proxy/src/container.ts (1)

31-31: Verify OTEL resource initialization and add explicit service/resource attributes if needed.

The review comment's concern is valid. Investigation confirms that:

  1. The OTEL mixin (collectOtel) adds only span context (trace/span IDs), not service/resource metadata
  2. Service names passed to loggers as options ({ name: "app" }) are not exposed as OTEL resource attributes
  3. No explicit OpenTelemetry Resource configuration is present in the codebase

While @opentelemetry/auto-instrumentations-node is a dependency and may provide default resource metadata at runtime, this is not explicitly configured. To ensure consistent service/resource metadata (service.name, service.version) across components for proper log correlation, the developer should:

  • Verify that auto-instrumentations-node provides adequate resource initialization, OR
  • Explicitly configure an OTEL Resource with service.name, service.version, and other identifying attributes during app initialization

@ritoban23 ritoban23 force-pushed the feat/add-otel-namespace-1801 branch from 9d4654c to 9fe60c7 Compare October 17, 2025 09:56
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
apps/provider-proxy/src/container.ts (1)

2-2: Critical issues from previous review remain unaddressed.

The past review comments on this line identified two critical issues that appear to still be valid:

  1. Unconditional import of optional peerpackages/logging/src/otel.ts imports @opentelemetry/api unconditionally, but it's declared as an optional peer dependency. This will cause runtime failures if the peer is not installed.

  2. Missing OTEL SDK initialization — The removal of setupOpenTelemetry.ts left no SDK initialization in provider-proxy. Without initializing an OTEL SDK (NodeSDK, BasicTracerProvider, etc.), trace.getSpan(context.active()) returns null and tracing features are non-functional.

Please address both issues or confirm that SDK initialization occurs elsewhere.

🧹 Nitpick comments (2)
apps/api/src/core/providers/logging.provider.ts (1)

6-8: Consider removing explanatory comments.

The comments explain what the code does, which may be unnecessary for expert developers. The code is self-documenting: LoggerServiceOriginal.mixin = collectOtel clearly sets up the OTEL mixin.

As per coding guidelines, consider this diff:

-// Set up OpenTelemetry mixin for all LoggerService instances
-// This collects trace information and adds it to log entries
 LoggerServiceOriginal.mixin = collectOtel;
-
apps/provider-proxy/src/container.ts (1)

15-35: Consider extracting repeated ternary pattern.

The pattern isLoggingDisabled ? undefined : createOtelLogger({ name: "..." }) is repeated at lines 15, 31, 34, and 35, creating minor duplication.

Consider extracting a helper:

const createLogger = (name: string) => 
  isLoggingDisabled ? undefined : createOtelLogger({ name });

Then use it:

-  const appLogger = isLoggingDisabled ? undefined : createOtelLogger({ name: "app" });
+  const appLogger = createLogger("app");

Apply similarly to wsLogger, httpLogger, and the cert-validator logger.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d4654c and 9fe60c7.

📒 Files selected for processing (9)
  • apps/api/src/console.ts (0 hunks)
  • apps/api/src/core/providers/logging.provider.ts (1 hunks)
  • apps/api/src/open-telemetry.ts (0 hunks)
  • apps/api/src/server.ts (0 hunks)
  • apps/provider-proxy/src/container.ts (3 hunks)
  • apps/provider-proxy/src/server.ts (0 hunks)
  • apps/provider-proxy/src/setupOpenTelemetry.ts (0 hunks)
  • packages/logging/package.json (2 hunks)
  • packages/logging/src/otel.ts (1 hunks)
💤 Files with no reviewable changes (5)
  • apps/provider-proxy/src/setupOpenTelemetry.ts
  • apps/provider-proxy/src/server.ts
  • apps/api/src/server.ts
  • apps/api/src/console.ts
  • apps/api/src/open-telemetry.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/logging/src/otel.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/core/providers/logging.provider.ts
  • apps/provider-proxy/src/container.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/core/providers/logging.provider.ts
  • apps/provider-proxy/src/container.ts
🧬 Code graph analysis (2)
apps/api/src/core/providers/logging.provider.ts (1)
packages/logging/src/otel.ts (1)
  • collectOtel (10-13)
apps/provider-proxy/src/container.ts (2)
packages/logging/src/otel.ts (1)
  • createOtelLogger (20-22)
apps/provider-proxy/src/services/CertificateValidator/CertificateValidator.ts (1)
  • createCertificateValidatorInstrumentation (84-99)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: Validate local packages

@stalniy
Copy link
Contributor

stalniy commented Oct 18, 2025

Nice, thank you for contribution!

Creates a reusable OpenTelemetry logger configuration to eliminate code duplication between provider-proxy and api apps.

Changes:
- Add @akashnetwork/logging/otel export with createOtelLogger function
- Add @opentelemetry/api as optional peer dependency
- Refactor provider-proxy to use createOtelLogger
- Refactor api to set global OTEL mixin in logging.provider.ts
- Remove apps/provider-proxy/src/setupOpenTelemetry.ts
- Remove apps/api/src/open-telemetry.ts
@stalniy stalniy force-pushed the feat/add-otel-namespace-1801 branch from 9fe60c7 to 3949407 Compare October 18, 2025 01:16

// Set up OpenTelemetry mixin for all LoggerService instances
// This collects trace information and adds it to log entries
LoggerServiceOriginal.mixin = collectOtel;
Copy link
Contributor

@stalniy stalniy Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue(blocking): this needs to be moved back to open-telemetry.ts file in api app because this app imports and uses instances of LoggerService in other files. So, please restore open-telemetry.ts file in api for now (you can just do LoggerService.mixin = collectOtel;). SO, there may be the case when LoggerService is created before logging.provider.ts is required. In result, those logger instances won't use otel.

And in the follow up PR, you can replace LoggerService instances either with injected LoggerService from DI or with createOtelLogger

Copy link
Contributor

@stalniy stalniy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small remark but overall a nice job!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move this file to a more appropriate location. There's utils dir for instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add otel namespace to logging package

3 participants