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

Sqlcommenter integration into SQLAlchemy #924

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c3b2c73
Integrating sqlcommenter into psycopg2
Thiyagu55 Feb 16, 2022
1abb7c8
Merge remote-tracking branch 'origin/sqlcommenter-psycopg2-integratio…
Thiyagu55 Feb 16, 2022
1183572
Merge branch 'open-telemetry:main' into sqlcommenter-psycopg2-integra…
Thiyagu55 Feb 16, 2022
703bde9
Integrating sqlcommenter into psycopg2 - Converted public local varia…
Thiyagu55 Feb 16, 2022
75d75bd
Merge remote-tracking branch 'origin/sqlcommenter-psycopg2-integratio…
Thiyagu55 Feb 16, 2022
7142254
Merge branch 'open-telemetry:main' into sqlcommenter-psycopg2-integra…
Thiyagu55 Feb 18, 2022
40384ef
Added test cases for sqlcommenter & PR Changes
Thiyagu55 Feb 18, 2022
354634a
Merge remote-tracking branch 'origin/sqlcommenter-psycopg2-integratio…
Thiyagu55 Feb 18, 2022
23933b9
Merge branch 'open-telemetry:main' into sqlcommenter-psycopg2-integra…
Thiyagu55 Feb 21, 2022
a7fef30
Code refactoring for generate sqlcommenter
Thiyagu55 Feb 22, 2022
0aff6b7
Added testcase for sqlcommenter integration into sqlalchemy
Thiyagu55 Feb 22, 2022
df8050b
updated change log
Thiyagu55 Feb 22, 2022
b0b07dd
updated to accept latest logs
Thiyagu55 Feb 22, 2022
756b836
Updated lint changes
Thiyagu55 Feb 23, 2022
069a497
Fixed errors due to linting
Thiyagu55 Feb 23, 2022
0764a41
Fixed linting errors
Thiyagu55 Feb 23, 2022
55d65b1
Fixed linting errors
Thiyagu55 Feb 23, 2022
4607b46
Fixed linting errors
Thiyagu55 Feb 23, 2022
feece49
Merge branch 'main' into sqlcommenter-psycopg2-integration
srikanthccv Mar 1, 2022
27365e6
Update CHANGELOG.md
Thiyagu55 Mar 2, 2022
0773f2e
Update CHANGELOG.md
Thiyagu55 Mar 2, 2022
81cf6a7
Merge branch 'main' into sqlcommenter-psycopg2-integration
srikanthccv Mar 3, 2022
ed6eee2
Merge branch 'main' into sqlcommenter-psycopg2-integration
srikanthccv Mar 4, 2022
7e69999
Merge branch 'main' into sqlcommenter-psycopg2-integration
srikanthccv Mar 7, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _instrument(self, **kwargs):
if kwargs.get("engine") is not None:
return EngineTracer(
_get_tracer(kwargs.get("engine"), tracer_provider),
kwargs.get("engine"),
kwargs.get("engine"), kwargs.get("enable_commenter", False)
)
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import os

import opentelemetry.trace
from sqlalchemy.event import listen # pylint: disable=no-name-in-module

from opentelemetry import trace
Expand Down Expand Up @@ -70,12 +71,13 @@ def _wrap_create_engine_internal(func, module, args, kwargs):


class EngineTracer:
def __init__(self, tracer, engine):
def __init__(self, tracer, engine, enable_commenter):
self.tracer = tracer
self.engine = engine
self.vendor = _normalize_vendor(engine.name)
self.enable_commenter = enable_commenter

listen(engine, "before_cursor_execute", self._before_cur_exec)
listen(engine, "before_cursor_execute", self._before_cur_exec, retval=True)
listen(engine, "after_cursor_execute", _after_cur_exec)
listen(engine, "handle_error", _handle_error)

Expand Down Expand Up @@ -115,6 +117,13 @@ def _before_cur_exec(
span.set_attribute(key, value)

context._otel_span = span
if self.enable_commenter:
_version = '00'
_span_id = opentelemetry.trace.format_span_id(span.context.span_id)
_trace_id = opentelemetry.trace.format_trace_id(span.context.trace_id)
_flags = str(opentelemetry.trace.TraceFlags.SAMPLED)
statement = statement + "/*traceparent=" + _version + '-' + _trace_id + '-' + _span_id + '-' + _flags + "*/"
return statement, params


# pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.28b1"
__version__ = "0.28b2"