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

Flask sqlalchemy psycopg2 integration #1224

Conversation

Thiyagu55
Copy link
Contributor

@Thiyagu55 Thiyagu55 commented Aug 9, 2022

Description

Integrating flask sqlcommenter into psycopg2 and sqlalchemy

This can be achieved by enabling enable_commenter flag inside Flask instrument initialization and also in SQLAlchemy Instrumentation or psycopg2 instrumentation

FlaskInstrumentor().instrument_app(app, tracer_provider=provider, enable_commenter=True)

# For sqlalchemy
SQLAlchemyInstrumentor().instrument( enable_commenter=True, engine=engine)

# For psycopg2
Psycopg2Instrumentor().instrument(tracer_provider=tracer_provider, enable_commenter=True)
  • The flask instrumentation will append the metrics in opentelemetry context in key name SQLCOMMENTER_VALUES
  • The SQLAlchemy ORM or psycopg2 driver will read the context and then append these info to the sql query logs whenever the sql query is made

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • instrumentation/opentelemetry-instrumentation-flask/tests/test_sqlcommenter.py
  • instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py test_executemany_flask_integration_comment
  • instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py test_sqlcommenter_flask_integration

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@Thiyagu55 Thiyagu55 requested a review from a team as a code owner August 9, 2022 06:54
@Thiyagu55
Copy link
Contributor Author

@srikanthccv For your visibility

@srikanthccv
Copy link
Member

I like the updated approach better. I will take a closer look again.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@srikanthccv srikanthccv enabled auto-merge (squash) September 8, 2022 20:05
@srikanthccv srikanthccv merged commit 32d7ff4 into open-telemetry:main Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants