GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Integration between Spanner SqlAlchemy and OpenTelemetry is generating a lot of warnings · Issue #345 · googleapis/python-spanner-sqlalchemy

This repository was archived by the owner on May 14, 2026. It is now read-only.
This repository was archived by the owner on May 14, 2026. It is now read-only.

Integration between Spanner SqlAlchemy and OpenTelemetry is generating a lot of warnings #345

Copy link
Copy link
Closed
#346
Closed
Integration between Spanner SqlAlchemy and OpenTelemetry is generating a lot of warnings#345
#346
Copy link
Assignees
harshachinta
Labels
api: spannerIssues related to the googleapis/python-spanner-sqlalchemy API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@gilles-leblanc
gilles-leblanc
opened on Oct 6, 2023
Issue body actions

We have an issue where integration between this package and OpenTelemetry is generating a lot of warnings.

In google.cloud.sqlalchemy_spanner sqlalchemy_spanner.py when it executes do_execute it calls trace_call but before doing so it sets the trace_attributes including db.params which are the values of the SQL query.

In trace_call, it checks if HAS_OPENTELEMETRY_INSTALLED and if so it will add these db.params atttributes to the trace and performs the trace.

But, in the OpenTelemetry Python package, it will check all attributes. One of the check that is performed on the attributes is that if an attribute is a Sequence type, all elements of the sequence must be of the same type. If not, it will throw a warning. This checks happens in the Python OpenTelemetry (external to Google) package in file attributes/__init__.py in the function _clean_attribute (see checks and _logger.warning calls).

The issue is that the Google Spanner SQLAlchemy package will store it’s db.params in the various types that they represent (which is good on it's own). It will then send these to the OpenTelemetry package who will check they’re all of the same type and throw a warning if not. So for all SQL queries that contain multiple datatype, OpenTelemetry will generate a warning.

This results in a huge number of these warnings in our GCP Log Explorer.
This could be fixed in a number of ways including sending these values as strings when sending them to OpenTelemetry.

I've made some tests and if I change this package sqlalchemy_spanner/_opentelemetry_tracing.py file to use the following code:

if extra_attributes:
        if isinstance(extra_attributes, dict):
            for k, v in extra_attributes.items():
                if isinstance(v, collections.abc.Sequence):
                    extra_attributes[k] = [str(e) for e in v]

        attributes.update(extra_attributes)

I'm no longer receiving any warnings as all sequences values are converted to string before tracing.

Reacted by Fredo

Activity

  1. gilles-leblanc
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Oct 6, 2023
  2. blunderbuss-gcf
    assigned
    harshachinta
    on Oct 6, 2023
  3. product-auto-label
    added
    api: spannerIssues related to the googleapis/python-spanner-sqlalchemy API.
    on Oct 6, 2023
  4. gilles-leblanc commented on Oct 6, 2023

    @gilles-leblanc
    gilles-leblanc
    on Oct 6, 2023
    Author
    More actions

    If my proposed solution is deemed acceptable, I could submit a pull request if you require.

  5. olavloite commented on Oct 10, 2023

    @olavloite
    olavloite
    on Oct 10, 2023
    Contributor
    More actions

    @gilles-leblanc Thanks for reporting this, and thank you for the detailed explanation of the issue. That made it possible for a non-Python expert like me to understand what is going on 👍

    I think that your suggestion makes sense. However; I think that if we're going to make a change to this, that I would prefer that we also make the logging of the actual query parameters itself optional. Query parameters could contain sensitive data, and I can imagine users wanting to trace queries, but not the query parameters of those queries to prevent sensitive data leaking into logs that can be viewed by different people.

    Would you be up for creating a pull request that does both? So your suggestion + making the inclusion of query parameters in the tracing optional. Suggestion for requirements:

    1. Logging of query parameters is enabled by default (I would have preferred disabled by default, but as it is already there, we need it enabled by default to avoid making a breaking change)
    2. Logging of query parameters in tracing can be switched on/off with an environment variable: SQLALCHEMY_SPANNER_TRACE_HIDE_QUERY_PARAMETERS (set to true to disable query parameter logging)
    3. The option can be checked in the trace_call function. Remove the db.params attributes before tracing if the above option has been set.
    4. I would also prefer that the stringification of the other trace attributes is done only for db.params and not for all extra_attributes that happen to be an instance of Sequence. That prevents any surprises if someone later adds other trace attributes that are also a Sequence, and where all the elements of that Sequence happen to be of the same (non-string) type.
  6. gilles-leblanc commented on Oct 10, 2023

    @gilles-leblanc
    gilles-leblanc
    on Oct 10, 2023
    Author
    More actions

    Yes I'll do it like you suggested.
    I need to get approval from my employer to do so. I've sent in the request.

    Reacted by Knut Olav Løite
  7. gillesleblanc commented on Oct 11, 2023

    @gillesleblanc
    gillesleblanc
    on Oct 11, 2023
    Contributor
    More actions

    Submitted a PR under my work account which is under the CLA.

    Reacted by Fredo
  8. olavloite
    closed this as completedin #346on Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @harshachinta
    harshachinta

Labels

api: spannerIssues related to the googleapis/python-spanner-sqlalchemy API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.