fix: align HTTP and DB spans with OpenTelemetry Semantic Conventions#18
fix: align HTTP and DB spans with OpenTelemetry Semantic Conventions#18lucas-angeli-gimenes wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request aligns OpenTelemetry instrumentation with the official Semantic Conventions by fixing span naming, attribute usage, and status code handling across HTTP and database instrumentation. The changes remove deprecated attributes, adjust span names to follow spec-compliant formats, and correct conditional attribute inclusion.
Changes:
- HTTP server spans now use
{method} {path}format (e.g., 'GET /users/{number}') - HTTP client spans omit
http.response.status_codeattribute when no response is received - Database spans remove driver/system prefixes and deprecated legacy attributes while adding
DB_QUERY_SUMMARY - MongoDB spans use camelCase operation names and conditionally include
DB_NAMESPACE - Successful spans no longer set explicit
STATUS_OKstatus
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Middleware/TraceMiddleware.php | Updated HTTP server span names to include HTTP method prefix |
| src/Aspect/GuzzleClientAspect.php | Removed HTTP_RESPONSE_STATUS_CODE => 0 from metrics for rejected requests |
| src/Listener/DbQueryExecutedListener.php | Removed driver prefix from span names, added DB_QUERY_SUMMARY attribute, removed legacy attributes |
| src/Aspect/RedisAspect.php | Removed 'Redis ' prefix from span names, removed setStatus(STATUS_OK), removed legacy attributes and unused import |
| src/Aspect/MongoAspect.php | Changed to camelCase operation names, added conditional DB_NAMESPACE attribute, removed setStatus(STATUS_OK), removed legacy attributes and unused imports |
| tests/Unit/Middleware/TraceMiddlewareTest.php | Updated test expectations to match new HTTP server span naming format |
| tests/Unit/Aspect/GuzzleClientAspectTest.php | Updated test to verify HTTP_RESPONSE_STATUS_CODE is not included for rejected requests |
| tests/Unit/Listener/DbQueryExecutedListenerTest.php | Updated test expectations for new span names, added DB_QUERY_SUMMARY verification, removed legacy attributes |
| tests/Unit/Aspect/RedisAspectTest.php | Updated test expectations for new span names, removed setStatus verification, removed legacy attributes, removed unused import |
| tests/Unit/Aspect/MongoAspectTest.php | Updated test expectations for camelCase operation names, removed setStatus verification, removed legacy attributes, removed unused import |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $this->equalTo([ | ||
| DbAttributes::DB_SYSTEM_NAME => DbIncubatingAttributes::DB_SYSTEM_NAME_VALUE_MONGODB, | ||
| DbAttributes::DB_COLLECTION_NAME => 'users', | ||
| DbAttributes::DB_OPERATION_NAME => 'FIND', | ||
| 'db.system' => DbIncubatingAttributes::DB_SYSTEM_NAME_VALUE_MONGODB, | ||
| 'db.operation' => 'FIND', | ||
| 'db.collection' => 'users', | ||
| DbAttributes::DB_OPERATION_NAME => 'find', | ||
| ]) |
There was a problem hiding this comment.
The new getNamespace() method and the conditional inclusion of DB_NAMESPACE attribute lack test coverage. The mock Collection class in the test setup (lines 62-68) only defines a 'collection' property, not a 'database' property. This means getNamespace() will always return null in the current tests, and the happy path where DB_NAMESPACE is successfully extracted and included in span attributes is not verified.
Consider adding a test case that:
- Creates a mock Collection with both 'collection' and 'database' properties
- Verifies that
DB_NAMESPACEis included in the span attributes when successfully extracted - Ensures the existing test continues to verify the behavior when 'database' property is not available
Description
This PR fixes span naming, attributes, and status code handling across HTTP (server/client) and database (SQL, Redis, MongoDB) instrumentation to conform with the OpenTelemetry Semantic Conventions.
HTTP Spans
TraceMiddleware (server spans)
GuzzleClientAspect (client spans)
the attribute must be omitted.
Database Spans
DbQueryExecutedListener (MySQL / PostgreSQL)
RedisAspect
MongoAspect
Type of change
Checklist
feat: add SQS aspect)composer testpasses locally