-
Notifications
You must be signed in to change notification settings - Fork 702
feat(generator): add internalTelemetryInfo configuration to nunjucks templates #9174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,6 +203,15 @@ export class {{ service.name }}Client { | |
| gaxInstance = gax as typeof gax; | ||
| } | ||
| {%- endif %} | ||
|
|
||
| {%- if api.enableTelemetryTracing %} | ||
| opts.internalTelemetryInfo = { | ||
| gcpClientService: '{{ api.loggingName }}', | ||
| gcpClientVersion: '{{ api.naming.version }}', | ||
| gcpRepo: 'googleapis/google-cloud-node', | ||
| gcpArtifact: '{{ api.publishName }}', | ||
| } | ||
| {%- endif %} | ||
|
Comment on lines
+207
to
+214
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly mutating the To prevent both issues, create a shallow copy of |
||
|
|
||
| // Choose either gRPC or proto-over-HTTP implementation of google-gax. | ||
| this._gaxModule = {% if not api.legacyProtoLoad %}opts.fallback ? gaxInstance.fallback : gaxInstance{% else %}gax{% endif %}; | ||
|
|
@@ -409,6 +418,15 @@ export class {{ service.name }}Client { | |
| , 'x-goog-api-version': '{{ service.apiVersion }}' | ||
| {%- endif %}}); | ||
|
|
||
| {%- if api.enableTelemetryTracing %} | ||
| if (opts.enableTelemetryTracing) { | ||
| for (const methodName of Object.keys(this._defaults)) { | ||
| this._defaults[methodName].enableTelemetryTracing = opts.enableTelemetryTracing; | ||
| this._defaults[methodName].internalTelemetryInfo = opts.internalTelemetryInfo; | ||
| } | ||
| } | ||
| {%- endif %} | ||
|
|
||
| // Set up a dictionary of "inner API calls"; the core implementation | ||
| // of calling the API is handled in `google-gax`, with this code | ||
| // merely providing the destination and request information. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly mutating the
optsobject passed to the constructor is unsafe and can lead to unexpected side-effects if the user reuses the options object across multiple clients. Additionally, sinceoptsis optional (opts?: ClientOptions), attempting to set properties on it directly will throw aTypeErrorat runtime if the client is instantiated without options.To prevent both issues, create a shallow copy of
optsusingObject.assign({}, opts)before assigning the telemetry info. This safely handlesundefined(resulting in an empty object{}) and protects the user's original configuration from mutation.