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

work around issue on pymongo < 3.0 #814

Merged
merged 1 commit into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion elasticapm/instrumentation/packages/pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def call(self, module, method, wrapped, instance, args, kwargs):
extra={"destination": {"service": {"name": "mongodb", "resource": "mongodb", "type": "db"}}},
) as span:
response = wrapped(*args, **kwargs)
if span.context:
if span.context and instance.address:
host, port = instance.address
span.context["destination"]["address"] = host
span.context["destination"]["port"] = port
Expand Down
11 changes: 6 additions & 5 deletions tests/instrumentation/pymongo_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ def test_collection_find(instrument, elasticapm_client, mongo_database):
assert span["subtype"] == "mongodb"
assert span["action"] == "query"
assert span["name"] == "elasticapm_test.blogposts.cursor.refresh"
assert span["context"]["destination"] == {
"address": os.environ.get("MONGODB_HOST", "localhost"),
"port": int(os.environ.get("MONGODB_PORT", 27017)),
"service": {"name": "mongodb", "resource": "mongodb", "type": "db"},
}
if not pymongo.version_tuple < (3, 0):
assert span["context"]["destination"] == {
"address": os.environ.get("MONGODB_HOST", "localhost"),
"port": int(os.environ.get("MONGODB_PORT", 27017)),
"service": {"name": "mongodb", "resource": "mongodb", "type": "db"},
}


@pytest.mark.integrationtest
Expand Down