Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 44 additions & 1 deletion core/packages/gax/src/createApiCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import {retryable} from './normalCalls/retries';
import {addTimeoutArg} from './normalCalls/timeout';
import {StreamingApiCaller} from './streamingCalls/streamingApiCaller';
import {warn} from './warnings';
import {
traceAttempt,
StaticTraceContext,
DynamicTraceContext,
} from './observability/TracerHelper';
import {checkTelemetryEnabled} from './util';

/**
* Converts an rpc call into an API call governed by the settings.
Expand Down Expand Up @@ -66,6 +72,9 @@ export function createApiCall(
const funcPromise = typeof func === 'function' ? Promise.resolve(func) : func;
// the following apiCaller will be used for all calls of this function...
const apiCaller = createAPICaller(settings, descriptor);

const tracingEnabled = checkTelemetryEnabled(settings);

const invokeCall = (
request: RequestType,
callOptions?: CallOptions,
Expand Down Expand Up @@ -168,5 +177,39 @@ export function createApiCall(
// or to cancel the ongoing call.
return currentApiCaller.result(ongoingCall);
};
return invokeCall;

if (tracingEnabled) {
const staticArgs: StaticTraceContext = {
gcpClientService:
settings.otherArgs.internalTelemetryInfo?.gcpClientService,
gcpVersion: settings.otherArgs.internalTelemetryInfo?.gcpVersion,
gcpRepo: settings.otherArgs.internalTelemetryInfo?.gcpRepo,
gcpArtifact: settings.otherArgs.internalTelemetryInfo?.gcpArtifact,
};

const serviceName = settings.apiName?.split('.').pop() ?? '';
const isFallback = Boolean(_fallback);
const dynamicArgs: DynamicTraceContext = {
clientName: serviceName ? `${serviceName}Client` : '',
methodName: settings.otherArgs?.internalMethodName ?? '',
rpcType: isFallback ? 'http' : 'grpc',
};
const isStreamingCall = apiCaller instanceof StreamingApiCaller;
return (
request: RequestType,
callOptions?: CallOptions,
callback?: APICallback,
) => {
return traceAttempt(
dynamicArgs,
staticArgs,
() => {
return invokeCall(request, callOptions, callback);
},
isStreamingCall,
);
};
} else {
return invokeCall;
}
}
Loading
Loading