Skip to content

Commit

Permalink
Merge pull request #96 from NathanielRN/move-instrumentation-asyncpg
Browse files Browse the repository at this point in the history
Move instrumentation asyncpg
  • Loading branch information
alrex authored Nov 2, 2020
2 parents 492ca6b + be6f62a commit 9e1ef99
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api == 0.15.dev0
opentelemetry-instrumentation == 0.15.dev0
opentelemetry-api == 0.15b0
opentelemetry-instrumentation == 0.15b0
asyncpg >= 0.12.0

[options.extras_require]
test =
opentelemetry-test == 0.15.dev0
opentelemetry-test == 0.15b0

[options.packages.find]
where = src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,11 @@
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import unwrap
from opentelemetry.trace import SpanKind
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.trace.status import Status, StatusCode

_APPLIED = "_opentelemetry_tracer"


def _exception_to_canonical_code(exc: Exception) -> StatusCanonicalCode:
if isinstance(
exc, (exceptions.InterfaceError, exceptions.SyntaxOrAccessError),
):
return StatusCanonicalCode.INVALID_ARGUMENT
if isinstance(exc, exceptions.IdleInTransactionSessionTimeoutError):
return StatusCanonicalCode.DEADLINE_EXCEEDED
return StatusCanonicalCode.UNKNOWN


def _hydrate_span_from_args(connection, query, parameters) -> dict:
span_attributes = {"db.type": "sql"}

Expand Down Expand Up @@ -134,12 +124,7 @@ async def _do_execute(self, func, instance, args, kwargs):
exception = exc
raise
finally:
if span.is_recording():
if exception is not None:
span.set_status(
Status(_exception_to_canonical_code(exception))
)
else:
span.set_status(Status(StatusCanonicalCode.OK))
if span.is_recording() and exception is not None:
span.set_status(Status(StatusCode.ERROR))

return result
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.15.dev0"
__version__ = "0.15b0"

0 comments on commit 9e1ef99

Please sign in to comment.