Repository: googleapis/python-bigquery

Issue:
Warning on OpenTelemetry when some attributes are not set
#### Environment details

  - OS type and version: Windows 10 21H2
  - Python version: `3.9.4`
  - pip version: `22.2.2`
  - `google-cloud-bigquery` version: `3.3.5`

#### Steps to reproduce

  1. Set up a query job with opentelemetry enabled
  2. See warning in the console: `Invalid type NoneType for attribute value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types`

#### Code example

```python
import logging
from google.cloud import bigquery
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
    SimpleSpanProcessor,
    ConsoleSpanExporter,
)

provider = TracerProvider()
simple_processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(simple_processor)
trace.set_tracer_provider(provider)

logging.basicConfig(level=10)

# Construct a BigQuery client object.
client = bigquery.Client()

query = "SELECT 1;"

query_job = client.query(query)
```
#### Stack trace
```
DEBUG:google.auth._default:Checking None for explicit credentials as part of auth process...
DEBUG:google.auth._default:Checking Cloud SDK credentials as part of auth process...
DEBUG:google.auth._default:Checking None for explicit credentials as part of auth process...
DEBUG:google.auth._default:Checking Cloud SDK credentials as part of auth process...
WARNING:opentelemetry.attributes:Invalid type NoneType for attribute value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
WARNING:opentelemetry.attributes:Invalid type NoneType for attribute value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
DEBUG:urllib3.util.retry:Converted retries value: 3 -> Retry(total=3, connect=None, read=None, redirect=None, status=None)
DEBUG:google.auth.transport.requests:Making request: POST https://oauth2.googleapis.com/token
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): oauth2.googleapis.com:443
DEBUG:urllib3.connectionpool:https://oauth2.googleapis.com:443 "POST /token HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): bigquery.googleapis.com:443
DEBUG:urllib3.connectionpool:https://bigquery.googleapis.com:443 "POST /bigquery/v2/projects/my-project/jobs?prettyPrint=false HTTP/1.1" 200 None
{
    "name": "BigQuery.job.begin",
    "context": {
        "trace_id": "0x192a0e4ec554c63f68525922208fed88",
        "span_id": "0xfa29f0363122c4c4",
        "trace_state": "[]"
    },
    "kind": "SpanKind.INTERNAL",
    "parent_id": null,
    "start_time": "2022-10-12T09:41:57.259114Z",
    "end_time": "2022-10-12T09:41:57.934410Z",
    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "db.system": "BigQuery",
        "db.name": "my-project",
        "job_id": "fc1581e3-708b-4b51-9a05-e3ad52c68dec",
        "hasErrors": false,
        "num_child_jobs": 0,
        "path": "/projects/my-project/jobs"
    },
    "events": [],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.13.0",
            "service.name": "unknown_service"
        },
        "schema_url": ""
    }
}
```
#### Analysis

Warnings appear when `location` and job `state` attributes are not set.




Discussion:
I got this warning as well. 

I think the warning disappears after adding similar None handling that was done in https://github.com/googleapis/python-bigquery/pull/1327 for the `location` and `state` fields. 

`location`: https://github.com/googleapis/python-bigquery/blob/main/google/cloud/bigquery/opentelemetry_tracing.py#L104

`state`: https://github.com/googleapis/python-bigquery/blob/main/google/cloud/bigquery/opentelemetry_tracing.py#L111

Resolving patch:
diff --git a/google/cloud/bigquery/opentelemetry_tracing.py b/google/cloud/bigquery/opentelemetry_tracing.py
--- a/google/cloud/bigquery/opentelemetry_tracing.py
+++ b/google/cloud/bigquery/opentelemetry_tracing.py
@@ -97,6 +97,11 @@ def _get_final_span_attributes(attributes=None, client=None, job_ref=None):
         final_attributes.update(job_attributes)
     if attributes:
         final_attributes.update(attributes)
+
+    filtered = {k: v for k, v in final_attributes.items() if v is not None}
+    final_attributes.clear()
+    final_attributes.update(filtered)
+
     return final_attributes
 
 


Test patch: