Skip to content

feat(generator): add internalTelemetryInfo configuration to nunjucks templates - #9174

Draft
shivanee-p wants to merge 1 commit into
shivaneep-o11y-tracer-helperfrom
shivaneep-o11y-generator-templates
Draft

feat(generator): add internalTelemetryInfo configuration to nunjucks templates#9174
shivanee-p wants to merge 1 commit into
shivaneep-o11y-tracer-helperfrom
shivaneep-o11y-generator-templates

Conversation

@shivanee-p

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces telemetry tracing configuration (internalTelemetryInfo) to the generated service client templates for both CommonJS and ESM formats when telemetry tracing is enabled. The review feedback highlights a critical issue where directly mutating the opts object can lead to a TypeError if opts is undefined, or cause unintended side-effects if the options object is reused. It is recommended to safely clone opts using Object.assign({}, opts) before assigning the telemetry properties.

Comment on lines +200 to +207
{%- if api.enableTelemetryTracing %}
opts.internalTelemetryInfo = {
gcpClientService: '{{ api.loggingName }}',
gcpClientVersion: '{{ api.naming.version }}',
gcpRepo: 'googleapis/google-cloud-node',
gcpArtifact: '{{ api.publishName }}',
}
{%- endif %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Directly mutating the opts object passed to the constructor is unsafe and can lead to unexpected side-effects if the user reuses the options object across multiple clients. Additionally, since opts is optional (opts?: ClientOptions), attempting to set properties on it directly will throw a TypeError at runtime if the client is instantiated without options.

To prevent both issues, create a shallow copy of opts using Object.assign({}, opts) before assigning the telemetry info. This safely handles undefined (resulting in an empty object {}) and protects the user's original configuration from mutation.

    {%- if api.enableTelemetryTracing %}
      opts = Object.assign({}, opts);
      opts.internalTelemetryInfo = {
        gcpClientService: '{{ api.loggingName }}',
        gcpClientVersion: '{{ api.naming.version }}',
        gcpRepo: 'googleapis/google-cloud-node',
        gcpArtifact: '{{ api.publishName }}',
      };
    {%- endif %}

Comment on lines +207 to +214
{%- if api.enableTelemetryTracing %}
opts.internalTelemetryInfo = {
gcpClientService: '{{ api.loggingName }}',
gcpClientVersion: '{{ api.naming.version }}',
gcpRepo: 'googleapis/google-cloud-node',
gcpArtifact: '{{ api.publishName }}',
}
{%- endif %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Directly mutating the opts object passed to the constructor is unsafe and can lead to unexpected side-effects if the user reuses the options object across multiple clients. Additionally, since opts is optional (opts?: ClientOptions), attempting to set properties on it directly will throw a TypeError at runtime if the client is instantiated without options.

To prevent both issues, create a shallow copy of opts using Object.assign({}, opts) before assigning the telemetry info. This safely handles undefined (resulting in an empty object {}) and protects the user's original configuration from mutation.

    {%- if api.enableTelemetryTracing %}
      opts = Object.assign({}, opts);
      opts.internalTelemetryInfo = {
        gcpClientService: '{{ api.loggingName }}',
        gcpClientVersion: '{{ api.naming.version }}',
        gcpRepo: 'googleapis/google-cloud-node',
        gcpArtifact: '{{ api.publishName }}',
      };
    {%- endif %}

@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch 2 times, most recently from 33674b2 to f8305b2 Compare August 19, 2026 23:18
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch from f8305b2 to c13d658 Compare August 19, 2026 23:47
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch from c13d658 to feea2ed Compare August 19, 2026 23:54
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch 4 times, most recently from a263692 to d9982c7 Compare August 20, 2026 19:36
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch from d9982c7 to 249eea0 Compare August 20, 2026 22:46
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch from 249eea0 to 07e057a Compare August 20, 2026 22:53
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch from 07e057a to 93e864d Compare August 21, 2026 18:46
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch from 93e864d to 0835dbf Compare August 21, 2026 19:26
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-generator-templates branch from 0835dbf to 9077df6 Compare August 21, 2026 21:34
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.

1 participant