Skip to content

Commit

Permalink
Pymongo capture collection name (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
avzis committed Jan 11, 2023
1 parent d1dec92 commit 70187ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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)

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

0 comments on commit 70187ff

Please sign in to comment.