Skip to content

Conversation

daniyelnnr
Copy link
Contributor

@daniyelnnr daniyelnnr commented Sep 3, 2025

What is the purpose of this pull request?

This pull request updates the diagnostics integration to improve configuration flexibility and control over telemetry behavior.

What problem is this solving?

The main changes include upgrading the diagnostics package, introducing new environment-based configuration options, and ensuring telemetry can be conditionally enabled or disabled.

Summary of the changes

Telemetry configuration and control:
  • Upgraded @vtex/diagnostics-nodejs dependency to version 0.1.0-io-beta.20 in package.json for latest telemetry features and bug fixes.
  • Added new constants in src/constants.ts to control telemetry: OTEL_EXPORTER_OTLP_ENDPOINT (endpoint for telemetry exporter), DK_APP_ID (application ID override), and DIAGNOSTICS_TELEMETRY_ENABLED (flag to enable/disable telemetry via environment variable).
Telemetry client initialization improvements:
  • Updated src/service/telemetry/client.ts to use the new constants for exporter endpoint and app ID, and to pass a noop flag to disable telemetry when DIAGNOSTICS_TELEMETRY_ENABLED is false. Also logs a warning when telemetry is disabled. [1] [2] [3]
  • Instrumentations for telemetry are now only registered when telemetry is enabled, preventing unnecessary overhead when disabled. [1] [2]
Logger initialization:
  • Ensured initLogClient is always called in the Logger constructor in src/service/logger/logger.ts, aligning with the updated telemetry client logic.

How should this be manually tested?

Screenshots or example usage

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Requires change to documentation, which has been updated accordingly.

Enables this client to support logs, metrics, and tracing signals from the diagnostics-nodejs library, making them available already initialized. Additionally, this change enables registration of built-in and community instrumentation.
Remove unused parameters and use logClient already initialized
Refactor client types to use Types.LogClient for consistency
Improve telemetry client initialization using Promise.all to optimize asynchronous calls
Adds OpenTelemetry dependencies for host metrics and Koa instrumentation
Updates startApp function to initialize telemetry beforehand and uses dynamic imports for startMaster and startWorker. This ensures that telemetry clients and libraries are proper initialized so they can use hooks with application libraries that will be loaded later
Add getMetricClient function to make the client available and creates the asynchronous initialization function to retrieve it
This commit creates a middleware for request metrics using OpenTelemetry instruments. This change is inspired by `requestMetricsMiddleware.ts` and follows the same logic, only changing the way it is instrumented to use OTel standard
Add the use of OpenTelemetry metrics middleware for request monitoring
Add Koa instrumentation to the list of instruments that will be registered and used by the telemetry client. This enables automatic instrumentation for the Koa module, as well as automatic collection and export of telemetry data.
This commit creates a wrapper for the host-metrics module, which provides automatic collection for system metrics - such as CPU, memory, and network
Refactors the instrument initialization logic to improve readability and code structure
Refactor MetricClient to use Singleton pattern for improved client management
Refactor OTel instruments initialization to use singleton pattern
This commit creates new constants based on environment variables that will be used to proper configure diagnostics-nodejs on node-vtex-api
Make the new constants available on clients.ts file, which is responsible for create telemetry client.
This commit replaces and updates the telemetry clients to utilize the OTEL_EXPORTER_OTLP_ENDPOINT constant for exporting telemetry data
Small change on parameter to follow o11y team guidelines regarding this field
Updates parameters on telemetry client creation, making use of APPLICATION_ID and adding new additional attributes. Also, we remove unused constant CLIENT_NAME.
This update adds console logging for diagnostics configuration and checks if telemetry is enabled before registering instrumentations. It ensures that the telemetry client operates correctly based on the DIAGNOSTICS_TELEMETRY_ENABLED constant. Also, whenever the app vendor is not enabled it will use a no-op client for diagnostics, meaning any telemetry signal will be ignored
@daniyelnnr
Copy link
Contributor Author

Depends on #596

Copy link
Contributor

@silvadenisaraujo silvadenisaraujo left a comment

Choose a reason for hiding this comment

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

LGTM, just a nitpick and a question

const telemetryClient = await NewTelemetryClient(
APPLICATION_ID,
CLIENT_NAME,
DK_APP_ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wha is the role of this DK app id here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a request from o11y team, the proper identifier for this first parameter should be the DK app id instead of the composite id (vendor, app name and version) that we were using here - that's the reason why I opened #602 and proper onboard node-vtex-api.

Copy link
Contributor

@arturpimentel arturpimentel left a comment

Choose a reason for hiding this comment

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

Left a few clarification request comments before proceeding

This change modifies the DK_APP_ID constant to default to 'apps-team' instead of 'apps'
Replace negative warning message when telemetry is disabled with positive
confirmation message when enabled. This change aligns with the principle
of treating disabled telemetry as the default state.
Copy link
Contributor

@arturpimentel arturpimentel left a comment

Choose a reason for hiding this comment

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

Great iteration!

Base automatically changed from update/metrics to master September 8, 2025 12:41
@daniyelnnr daniyelnnr merged commit 41c8ccb into master Sep 8, 2025
1 of 2 checks passed
@daniyelnnr daniyelnnr deleted the config/enable-telemetry-controls branch September 8, 2025 12:48
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.

3 participants