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.

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


export const OTEL_EXPORTER_OTLP_ENDPOINT = process.env.OTEL_EXPORTER_OTLP_ENDPOINT as string;

export const DK_APP_ID = process.env.NODE_VTEX_API_DK_APP_ID as string || "apps";
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I would update the default name to something else to don't confuse with our Apps service.

try {
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

@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

Comment on lines +62 to +64
if (!DIAGNOSTICS_TELEMETRY_ENABLED) {
console.warn(`Telemetry disabled for app: ${APP.ID} (vendor: ${APP.VENDOR})`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would go in the opposite direction here, since we're enabling the new telemetry in just a few tenants and I also prefer positive-leaning messages that assert that something is working instead of not working (which should be the default assumption). This warning could even be moved into the if (DIAGNOSTICS_TELEMETRY_ENABLED) {} block further below

];

telemetryClient.registerInstrumentations(instrumentations);
if (DIAGNOSTICS_TELEMETRY_ENABLED) {
Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, a sanity check: does this line risk disabling the current telemetry? I see this condition didn't exist before

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