Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ export class {{ service.name }}Client {
}
{%- endif %}

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

// 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 %};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

// 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 %};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class Generator {
restNumericEnums?: boolean;
mixinsOverride?: string[];
format?: string | string[];
enableTelemetryTracing?: boolean;

private root: protobuf.Root;

Expand Down Expand Up @@ -227,6 +228,12 @@ export class Generator {
}
}

private readEnableTelemetryTracing() {
if (this.paramMap['enable-telemetry-tracing'] === 'true') {
this.enableTelemetryTracing = true;
}
}

private readLegacyProtoLoad() {
if (this.paramMap['legacy-proto-load'] === 'true') {
this.legacyProtoLoad = true;
Expand Down Expand Up @@ -274,6 +281,7 @@ export class Generator {
this.readLegacyProtoLoad();
this.readRestNumericEnums();
this.readFormat();
this.readEnableTelemetryTracing();
}
}

Expand Down Expand Up @@ -334,6 +342,7 @@ export class Generator {
legacyProtoLoad: this.legacyProtoLoad,
restNumericEnums: this.restNumericEnums,
mixinsOverridden: this.mixinsOverride !== undefined,
enableTelemetryTracing: this.enableTelemetryTracing,
});
return api;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class API {
restNumericEnums: boolean;
documentationUri: any;
newIssueUri: string;
enableTelemetryTracing?: boolean;
title?: string;

static isIgnoredService(
Expand Down Expand Up @@ -112,6 +113,7 @@ export class API {
this.documentationUri =
options.serviceYaml?.publishing?.documentation_uri ?? '';
this.newIssueUri = options.serviceYaml?.publishing?.new_issue_uri ?? '';
this.enableTelemetryTracing = options.enableTelemetryTracing ?? false;
this.title = options.serviceYaml?.title;

const [allResourceDatabase, resourceDatabase] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Options {
legacyProtoLoad?: boolean;
restNumericEnums?: boolean;
mixinsOverridden?: boolean;
enableTelemetryTracing?: boolean;
}

export class Naming {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,25 @@ describe('src/schema/api.ts', () => {
assert('.google.cloud.example.v1.MessageB' in secondCallMessages);
});
});

it('should set enableTelemetryTracing option', () => {
const fd = {} as protos.google.protobuf.FileDescriptorProto;
fd.name = 'google/cloud/test/v1/test.proto';
fd.package = 'google.cloud.test.v1';
fd.service = [{} as protos.google.protobuf.ServiceDescriptorProto];
fd.service[0].name = 'ZService';
fd.service[0].options = {
'.google.api.defaultHost': 'hostname.example.com:443',
};
const apiWithTracing = new API([fd], 'google.cloud.test.v1', {
grpcServiceConfig: {} as protos.grpc.service_config.ServiceConfig,
enableTelemetryTracing: true,
});
assert.strictEqual(apiWithTracing.enableTelemetryTracing, true);

const apiWithoutTracing = new API([fd], 'google.cloud.test.v1', {
grpcServiceConfig: {} as protos.grpc.service_config.ServiceConfig,
});
assert.strictEqual(apiWithoutTracing.enableTelemetryTracing, false);
});
});
Loading
Loading