Skip to content

add database as a dependency in asyncpg instrumentation #1115

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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add database as a dependency in asyncpg instrumentation
  • Loading branch information
ajaygupta2790 committed Apr 26, 2021
commit a9df55f3ef593e71055027c4ab341d03f1fd819b
7 changes: 7 additions & 0 deletions elasticapm/instrumentation/packages/asyncio/asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from elasticapm.contrib.asyncio.traces import async_capture_span
from elasticapm.instrumentation.packages.asyncio.base import AsyncAbstractInstrumentedModule
from elasticapm.instrumentation.packages.dbapi2 import extract_signature
from elasticapm.utils import default_ports


class AsyncPGInstrumentation(AsyncAbstractInstrumentedModule):
Expand All @@ -56,6 +57,12 @@ async def call(self, module, method, wrapped, instance, args, kwargs):
name = extract_signature(query)
context = {"db": {"type": "sql", "statement": query}}
action = "query"
destination_info = {
"address": kwargs.get("host", "localhost"),
"port": int(kwargs.get("port", default_ports.get("postgresql"))),
"service": {"name": "postgres", "resource": "postgres", "type": "db"},
}
context['destination'] = destination_info
async with async_capture_span(
name, leaf=True, span_type="db", span_subtype="postgres", span_action=action, extra=context
):
Expand Down