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

Pymongo capture collection name #1555

Merged
merged 14 commits into from
Jan 11, 2023
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-aws-lambda` Adds an option to configure `disable_aws_context_propagation` by
environment variable: `OTEL_LAMBDA_DISABLE_AWS_CONTEXT_PROPAGATION`
([#1507](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1507))

- Fix pymongo to collect the property DB_MONGODB_COLLECTION
([#1555](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1555))

## Version 1.15.0/0.36b0 (2022-12-10)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def started(self, event: monitoring.CommandStartedEvent):
statement = event.command_name
if command:
statement += " " + str(command)
collection = event.command.get(event.command_name)
avzis marked this conversation as resolved.
Show resolved Hide resolved

try:
span = self._tracer.start_span(name, kind=SpanKind.CLIENT)
Expand All @@ -135,6 +136,10 @@ def started(self, event: monitoring.CommandStartedEvent):
)
span.set_attribute(SpanAttributes.DB_NAME, event.database_name)
span.set_attribute(SpanAttributes.DB_STATEMENT, statement)
if collection:
span.set_attribute(
SpanAttributes.DB_MONGODB_COLLECTION, collection
)
if event.connection_id is not None:
span.set_attribute(
SpanAttributes.NET_PEER_NAME, event.connection_id[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def validate_spans(self):
self.assertEqual(
pymongo_span.attributes[SpanAttributes.NET_PEER_PORT], MONGODB_PORT
)
self.assertEqual(
pymongo_span.attributes[SpanAttributes.DB_MONGODB_COLLECTION],
MONGODB_COLLECTION_NAME,
)

def test_insert(self):
"""Should create a child span for insert"""
Expand Down