A number of environment variables can be used to configure the behavior of the library. There are also functions to configure this behavior in code. The environment variables are convenient when troubleshooting problems.
Endpoint Overrides
GOOGLE_CLOUD_CPP_SPANNER_DEFAULT_ENDPOINT=...: changes the default endpoint (spanner.googleapis.com) for the library. Intended for testing only.
SPANNER_EMULATOR_HOST=host:port: tells the library to connect to the specified emulator rather than the default endpoint. Intended for testing only.
GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc: turns on tracing for most gRPC calls. The library injects an additional Stub decorator that prints each gRPC request and response. Unless you have configured your own logging backend, you should also setGOOGLE_CLOUD_CPP_ENABLE_CLOGto produce any output on the program's console.
See Also
google::cloud::LoggingComponentsOptionGOOGLE_CLOUD_CPP_TRACING_OPTIONS=...: modifies the behavior of gRPC tracing, including whether messages will be output on multiple lines, or whether string/bytes fields will be truncated.
See Also
google::cloud::GrpcTracingOptionsOptionGOOGLE_CLOUD_CPP_ENABLE_CLOG=yes: turns on logging in the library, basically the library always "logs" but the logging infrastructure has no backend to actually print anything until the application sets a backend or they set this environment variable.
GOOGLE_CLOUD_PROJECT=...: is used in examples and integration tests to configure the GCP project. This has no effect in the library.
GOOGLE_CLOUD_CPP_SPANNER_TEST_INSTANCE_ID=...is used in examples and integration tests to, well, configure the spanner instance. This has no effect in the library.
GOOGLE_CLOUD_CPP_SPANNER_TEST_SERVICE_ACCOUNT=...: is used in examples and integration tests to set the service account for testing IAM operations. This has no effect in the library.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThis page details environment variables that can configure the behavior of the Spanner C++ client library, along with links to relevant documentation.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the Spanner C++ client library is 2.37.0-rc, and the page lists past versions ranging from 2.36.0 back to 2.11.0, all available for browsing via provided links.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment variables such as \u003ccode\u003eGOOGLE_CLOUD_CPP_SPANNER_DEFAULT_ENDPOINT\u003c/code\u003e and \u003ccode\u003eSPANNER_EMULATOR_HOST\u003c/code\u003e can be set to override the default endpoint, primarily for testing.\u003c/p\u003e\n"],["\u003cp\u003eVariables like \u003ccode\u003eSPANNER_OPTIMIZER_VERSION\u003c/code\u003e and \u003ccode\u003eSPANNER_OPTIMIZER_STATISTICS_PACKAGE\u003c/code\u003e allow for the configuration of default behaviors related to query optimization.\u003c/p\u003e\n"],["\u003cp\u003eTracing and logging can be configured using \u003ccode\u003eGOOGLE_CLOUD_CPP_ENABLE_TRACING\u003c/code\u003e, \u003ccode\u003eGOOGLE_CLOUD_CPP_TRACING_OPTIONS\u003c/code\u003e, and \u003ccode\u003eGOOGLE_CLOUD_CPP_ENABLE_CLOG\u003c/code\u003e, which will help debug and monitor the behavior of the application.\u003c/p\u003e\n"]]],[],null,["Version 2.27.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/spanner/latest/spanner-env)\n- [2.41.0](/cpp/docs/reference/spanner/2.41.0/spanner-env)\n- [2.40.0](/cpp/docs/reference/spanner/2.40.0/spanner-env)\n- [2.39.0](/cpp/docs/reference/spanner/2.39.0/spanner-env)\n- [2.38.0](/cpp/docs/reference/spanner/2.38.0/spanner-env)\n- [2.37.0](/cpp/docs/reference/spanner/2.37.0/spanner-env)\n- [2.36.0](/cpp/docs/reference/spanner/2.36.0/spanner-env)\n- [2.35.0](/cpp/docs/reference/spanner/2.35.0/spanner-env)\n- [2.34.0](/cpp/docs/reference/spanner/2.34.0/spanner-env)\n- [2.33.0](/cpp/docs/reference/spanner/2.33.0/spanner-env)\n- [2.32.0](/cpp/docs/reference/spanner/2.32.0/spanner-env)\n- [2.31.0](/cpp/docs/reference/spanner/2.31.0/spanner-env)\n- [2.30.0](/cpp/docs/reference/spanner/2.30.0/spanner-env)\n- [2.29.0](/cpp/docs/reference/spanner/2.29.0/spanner-env)\n- [2.28.0](/cpp/docs/reference/spanner/2.28.0/spanner-env)\n- [2.27.0](/cpp/docs/reference/spanner/2.27.0/spanner-env)\n- [2.26.0](/cpp/docs/reference/spanner/2.26.0/spanner-env)\n- [2.25.1](/cpp/docs/reference/spanner/2.25.1/spanner-env)\n- [2.24.0](/cpp/docs/reference/spanner/2.24.0/spanner-env)\n- [2.23.0](/cpp/docs/reference/spanner/2.23.0/spanner-env)\n- [2.22.1](/cpp/docs/reference/spanner/2.22.1/spanner-env)\n- [2.21.0](/cpp/docs/reference/spanner/2.21.0/spanner-env)\n- [2.20.0](/cpp/docs/reference/spanner/2.20.0/spanner-env)\n- [2.19.0](/cpp/docs/reference/spanner/2.19.0/spanner-env)\n- [2.18.0](/cpp/docs/reference/spanner/2.18.0/spanner-env)\n- [2.17.0](/cpp/docs/reference/spanner/2.17.0/spanner-env)\n- [2.16.0](/cpp/docs/reference/spanner/2.16.0/spanner-env)\n- [2.15.1](/cpp/docs/reference/spanner/2.15.1/spanner-env)\n- [2.14.0](/cpp/docs/reference/spanner/2.14.0/spanner-env)\n- [2.13.0](/cpp/docs/reference/spanner/2.13.0/spanner-env)\n- [2.12.0](/cpp/docs/reference/spanner/2.12.0/spanner-env)\n- [2.11.0](/cpp/docs/reference/spanner/2.11.0/spanner-env) \n\nEnvironment Variables\n=====================\n\nA number of environment variables can be used to configure the behavior of the library. There are also functions to configure this behavior in code. The environment variables are convenient when troubleshooting problems.\n\nEndpoint Overrides\n------------------\n\n`GOOGLE_CLOUD_CPP_SPANNER_DEFAULT_ENDPOINT=...`: changes the default endpoint (spanner.googleapis.com) for the library. Intended for testing only.\n\n`SPANNER_EMULATOR_HOST=host:port`: tells the library to connect to the specified emulator rather than the default endpoint. Intended for testing only.\n\n###### See Also\n\n[`google::cloud::EndpointOption`](https://cloud.google.com/cpp/docs/reference/common/latest/structgoogle_1_1cloud_1_1EndpointOption.html)\n\nDefault behaviors\n-----------------\n\n`SPANNER_OPTIMIZER_VERSION=n`: sets the default query optimizer version to use in `Client::ExecuteQuery()` calls.\n\n###### See Also\n\n[`google::cloud::spanner::QueryOptimizerVersionOption`](/cpp/docs/reference/spanner/2.27.0/structgoogle_1_1cloud_1_1spanner_1_1QueryOptimizerVersionOption)`SPANNER_OPTIMIZER_STATISTICS_PACKAGE=...`: specifies a statistics package for the query optimizer to use when compiling a SQL query.\n\n###### See Also\n\n[`google::cloud::spanner::QueryOptimizerStatisticsPackageOption`](/cpp/docs/reference/spanner/2.27.0/structgoogle_1_1cloud_1_1spanner_1_1QueryOptimizerStatisticsPackageOption)\n\nLogging\n-------\n\n`GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc`: turns on tracing for most gRPC calls. The library injects an additional Stub decorator that prints each gRPC request and response. Unless you have configured your own logging backend, you should also set `GOOGLE_CLOUD_CPP_ENABLE_CLOG` to produce any output on the program's console.\n\n###### See Also\n\n[`google::cloud::LoggingComponentsOption`](https://cloud.google.com/cpp/docs/reference/common/latest/structgoogle_1_1cloud_1_1LoggingComponentsOption.html)`GOOGLE_CLOUD_CPP_TRACING_OPTIONS=...`: modifies the behavior of gRPC tracing, including whether messages will be output on multiple lines, or whether string/bytes fields will be truncated.\n\n###### See Also\n\n[`google::cloud::GrpcTracingOptionsOption`](https://cloud.google.com/cpp/docs/reference/common/latest/structgoogle_1_1cloud_1_1GrpcTracingOptionsOption.html)`GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes`: turns on logging in the library, basically the library always \"logs\" but the logging infrastructure has no backend to actually print anything until the application sets a backend or they set this environment variable.\n\n###### See Also\n\n[`google::cloud::LogBackend`](https://cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1LogBackend.html)\n\n###### See Also\n\n[`google::cloud::LogSink`](https://cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1LogSink.html)\n\nOther Environment Variables\n---------------------------\n\n`GOOGLE_CLOUD_PROJECT=...`: is used in examples and integration tests to configure the GCP project. This has no effect in the library.\n\n`GOOGLE_CLOUD_CPP_SPANNER_TEST_INSTANCE_ID=...` is used in examples and integration tests to, well, configure the spanner instance. This has no effect in the library.\n\n`GOOGLE_CLOUD_CPP_SPANNER_TEST_SERVICE_ACCOUNT=...`: is used in examples and integration tests to set the service account for testing IAM operations. This has no effect in the library."]]