Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: db.params OpenTelemetry integration issue #346

Merged
merged 2 commits into from
Oct 25, 2023
Merged
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
13 changes: 13 additions & 0 deletions google/cloud/sqlalchemy_spanner/_opentelemetry_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

"""Manages OpenTelemetry trace creation and handling"""

import collections
import os

from contextlib import contextmanager

from google.api_core.exceptions import GoogleAPICallError
Expand Down Expand Up @@ -46,6 +49,16 @@ def trace_call(name, extra_attributes=None):
}

if extra_attributes:
if os.environ.get("SQLALCHEMY_SPANNER_TRACE_HIDE_QUERY_PARAMETERS"):
extra_attributes.pop("db.params", None)

# Stringify "db.params" sequence values before sending to OpenTelemetry,
# otherwise OpenTelemetry may log a Warning if types differ.
if isinstance(extra_attributes, dict):
for k, v in extra_attributes.items():
if k == "db.params" and isinstance(v, collections.abc.Sequence):
extra_attributes[k] = [str(e) for e in v]

attributes.update(extra_attributes)

with tracer.start_as_current_span(
Expand Down
Loading