@@ -102,3 +102,41 @@ Perform a query
|
102 | 102 |
|
103 | 103 | for row in rows:
|
104 | 104 | print(row.name)
|
| 105 | +
|
| 106 | +Instrumenting With OpenTelemetry |
| 107 | +-------------------------------- |
| 108 | + |
| 109 | +This application uses `OpenTelemetry`_ to output tracing data from |
| 110 | +API calls to BigQuery. To enable OpenTelemetry tracing in |
| 111 | +the BigQuery client the following PyPI packages need to be installed: |
| 112 | + |
| 113 | +.. _OpenTelemetry: https://opentelemetry.io |
| 114 | + |
| 115 | +.. code-block:: console |
| 116 | +
|
| 117 | +pip install google-cloud-bigquery[opentelemetry] opentelemetry-exporter-google-cloud |
| 118 | +
|
| 119 | +After installation, OpenTelemetry can be used in the BigQuery |
| 120 | +client and in BigQuery jobs. First, however, an exporter must be |
| 121 | +specified for where the trace data will be outputted to. An |
| 122 | +example of this can be found here: |
| 123 | + |
| 124 | +.. code-block:: python |
| 125 | +
|
| 126 | +from opentelemetry import trace |
| 127 | +from opentelemetry.sdk.trace import TracerProvider |
| 128 | +from opentelemetry.sdk.trace.export import BatchExportSpanProcessor |
| 129 | +from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter |
| 130 | +trace.set_tracer_provider(TracerProvider()) |
| 131 | +trace.get_tracer_provider().add_span_processor( |
| 132 | +BatchExportSpanProcessor(CloudTraceSpanExporter()) |
| 133 | +) |
| 134 | +
|
| 135 | +In this example all tracing data will be published to the Google |
| 136 | +`Cloud Trace`_ console. For more information on OpenTelemetry, please consult the `OpenTelemetry documentation`_. |
| 137 | + |
| 138 | +.. _OpenTelemetry documentation: https://opentelemetry-python.readthedocs.io |
| 139 | +.. _Cloud Trace: https://cloud.google.com/trace |
| 140 | + |
| 141 | + |
| 142 | + |
0 commit comments