The YAML and JSON files in this directory are platform-independent tests meant to exercise a driver's implementation of the OpenTelemetry specification. These tests utilize the Unified Test Format.
For each test, create a MongoClient, configure it to enable tracing.
createEntities:
- client:
id: client0
observeTracingMessages:
enableCommandPayload: trueThese tests require the ability to collect tracing spans data in a structured form as described in the Unified Test Format specification.expectTracingMessages. For example the Java driver uses Micrometer to collect tracing spans.
expectTracingMessages:
client: client0
ignoreExtraSpans: false
spans:
...Test 1: Tracing Enable/Disable via Environment Variable
- Set the environment variable
OTEL_#{LANG}_INSTRUMENTATION_MONGODB_ENABLEDtofalse. - Create a
MongoClientwithout explicitly enabling tracing. - Perform a database operation (e.g.,
find()on a test collection). - Assert that no OpenTelemetry tracing spans are emitted for the operation.
- Set the environment variable
OTEL_#{LANG}_INSTRUMENTATION_MONGODB_ENABLEDtotrue. - Create a new
MongoClientwithout explicitly enabling tracing. - Perform the same database operation.
- Assert that OpenTelemetry tracing spans are emitted for the operation.
Test 2: Command Payload Emission via Environment Variable
- Set the environment variable
OTEL_#{LANG}_INSTRUMENTATION_MONGODB_ENABLEDtotrue. - Set the environment variable
OTEL_#{LANG}_INSTRUMENTATION_MONGODB_QUERY_TEXT_MAX_LENGTHto a positive integer (e.g., 1024). - Create a
MongoClientwithout explicitly enabling command payload emission. - Perform a database operation (e.g.,
find()). - Assert that the emitted tracing span includes the
db.query.textattribute. - Unset the environment variable
OTEL_#{LANG}_INSTRUMENTATION_MONGODB_QUERY_TEXT_MAX_LENGTH. - Create a new
MongoClient. - Perform the same database operation.
- Assert that the emitted tracing span does not include the
db.query.textattribute.