This document describes how to diagnose and resolve issues with distributed tracing when using Cloud Trace and telemetry policies with Secure Web Proxy.
Traces don't appear in Trace
If trace spans generated by Secure Web Proxy don't appear in the Trace Explorer, check the following items:
Verify that the Cloud Trace API is enabled: make sure that the Trace API (
cloudtrace.googleapis.com) is enabled in the Google Cloud project that hosts your Secure Web Proxy gateway.<pre class="devsite-click-to-copy"> gcloud services enable cloudtrace.googleapis.com </pre>Verify the telemetry policy exists and is active: use the
gcloud beta network-services telemetry-policies describecommand to check that your telemetry policy exists in the correct region and references the appropriate Secure Web Proxy gateway:gcloud beta network-services telemetry-policies describe POLICY_NAME \ --location=REGIONReplace the following:
POLICY_NAME: name of your telemetry policy, such asmy-swp-tracing-policyREGION: region where your telemetry policy is deployed, such asus-central1
Check the sampling rate: if your policy's
samplingRateis low (for example,0.01for 1% or0.001for 0.1%), individual manual test requests might not be sampled. To confirm that tracing is functioning, temporarily update your policy to use 100% sampling (samplingRate: 1.00) and then restore your production rate.Validate the target gateway resource URI: verify that the
telemetryTarget.resourcesfield in the telemetry policy specifies the exact, fully qualified resource URL or short name of the Secure Web Proxy gateway.//networkservices.googleapis.com/projects/PROJECT_ID/locations/REGION/gateways/GATEWAY_NAME
Replace the following:
PROJECT_ID: ID of your Google Cloud projectREGION: region where your Secure Web Proxy gateway is deployed, such asus-central1GATEWAY_NAME: name of your Secure Web Proxy gateway instance
Any mismatch in the project ID, region, or gateway name prevents the proxy from receiving the policy configuration.
Check Identity and Access Management (IAM) permissions:
- Make sure that you've granted your user account or service account the
Cloud Trace User
role
(
roles/cloudtrace.user) role to view spans in the Google Cloud console. - Make sure that you've granted the Cloud Trace Agent
role
(
roles/cloudtrace.agent) to the following service accounts:service-PROJECT_NUMBER@compute-system.iam.gserviceaccount.comservice-PROJECT_NUMBER@gcp-sa-networksecurity.iam.gserviceaccount.com- Client virtual machine (VM) service accounts, if client applications generate or propagate spans
- Make sure that you've granted your user account or service account the
Cloud Trace User
role
(
Missing child spans or broken trace graphs
If Secure Web Proxy proxy spans appear as independent or disconnected root traces instead of child spans of your application requests, then do the following:
Enable parent-based sampling: in your telemetry policy YAML file, verify that
parentBasedSampling.enabledis set totrue.tracingConfiguration: samplingRate: 0.01 parentBasedSampling: enabled: trueWhen parent-based sampling is disabled, Secure Web Proxy might drop traces that were sampled upstream if they don't match the local
samplingRate.Check the OpenTelemetry instrumentation: verify that your application uses an OpenTelemetry SDK that has distributed tracing context propagation enabled. For more information, see the OpenTelemetry TraceContext propagator documentation.
Unexpectedly high trace ingestion volume
If you observe higher-than-expected trace ingestion volume or costs in Trace, then do the following:
- Reduce the baseline sampling rate: in high-traffic production
environments, set
samplingRateto a smaller fraction, such as0.01(1%) or0.001(0.1%). - Rely on parent-based sampling: keep the gateway baseline
samplingRatelow and enableparentBasedSampling. This combination helps ensure that the proxy samples only the requests that upstream applications specifically select. - Remove temporary debug policies: if you had applied 100% sampling
(
samplingRate: 1.00) during troubleshooting, then remove the policy or revert to your previous configuration after the debugging process is complete.