-
Notifications
You must be signed in to change notification settings - Fork 650
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
ext: Expect tracer provider instead of tracer in integrations #602
Changes from 5 commits
867fd1c
6224f6e
cf91cf9
0ee0459
e060376
81add89
ef40abd
c762992
e9ec330
92560cf
6897dd1
eefb621
3bb242a
528ef1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,11 @@ | |
# pylint:disable=no-name-in-module | ||
# pylint:disable=relative-beyond-top-level | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.ext.grpc.version import __version__ | ||
|
||
def client_interceptor(tracer): | ||
|
||
def client_interceptor(tracer_provider=None): | ||
"""Create a gRPC client channel interceptor. | ||
|
||
Args: | ||
|
@@ -29,10 +32,15 @@ def client_interceptor(tracer): | |
""" | ||
from . import _client | ||
|
||
if tracer_provider is None: | ||
tracer_provider = trace.get_tracer_provider() | ||
|
||
tracer = tracer_provider.get_tracer(__name__, __version__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this pattern will occur more often, would it make sense to add an utility function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking if it could make sense to add an optional |
||
|
||
return _client.OpenTelemetryClientInterceptor(tracer) | ||
|
||
|
||
def server_interceptor(tracer): | ||
def server_interceptor(tracer_provider=None): | ||
"""Create a gRPC server interceptor. | ||
|
||
Args: | ||
|
@@ -43,4 +51,9 @@ def server_interceptor(tracer): | |
""" | ||
from . import _server | ||
|
||
if tracer_provider is None: | ||
tracer_provider = trace.get_tracer_provider() | ||
|
||
tracer = tracer_provider.get_tracer(__name__, __version__) | ||
|
||
return _server.OpenTelemetryServerInterceptor(tracer) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
trace.set_tracer_provider(TracerProvider()) | ||
tracer = trace.get_tracer(__name__) | ||
|
||
trace_integration(tracer) | ||
trace_integration() | ||
cnx = mysql.connector.connect(database='MySQL_Database') | ||
cursor = cnx.cursor() | ||
cursor.execute("INSERT INTO test (testField) VALUES (123)" | ||
|
@@ -41,23 +41,32 @@ | |
--- | ||
""" | ||
|
||
import typing | ||
|
||
import mysql.connector | ||
|
||
from opentelemetry.ext.dbapi import trace_integration as db_integration | ||
from opentelemetry.trace import Tracer | ||
from opentelemetry.ext.dbapi import wrap_connect | ||
from opentelemetry.ext.mysql.version import __version__ | ||
from opentelemetry.trace import TracerProvider, get_tracer_provider | ||
|
||
|
||
def trace_integration(tracer: Tracer): | ||
def trace_integration(tracer_provider: typing.Optional[TracerProvider] = None): | ||
"""Integrate with MySQL Connector/Python library. | ||
https://dev.mysql.com/doc/connector-python/en/ | ||
""" | ||
|
||
if tracer_provider is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason not to call the original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that it'll create the tracer with the version and name from the db-api module. I had to split the logic from |
||
tracer_provider = get_tracer_provider() | ||
|
||
tracer = tracer_provider.get_tracer(__name__, __version__) | ||
|
||
connection_attributes = { | ||
"database": "database", | ||
"port": "server_port", | ||
"host": "server_host", | ||
"user": "user", | ||
} | ||
db_integration( | ||
wrap_connect( | ||
tracer, | ||
mysql.connector, | ||
"connect", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a slight style thing, but it's a little harder for me to spot a trailing underscore rather than a leading underscore.