[CDRIVER-4142] Use separate handshake metadata for clients Created: 31/Aug/21  Updated: 27/Feb/23

Status: Backlog
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Andreas Braun Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-1547 Replace global state with context obj... Backlog
is related to CDRIVER-3441 Document mongoc_handshake_data_append Closed

 Description   

Summary

The mongoc_handshake_data_append logic has some limitations as to how much data we can collect about our clients. Since the first call to `mongoc_handshake_data_append` locks in metadata, which is then used for all clients created afterwards, this can cause wrong data to be collected, even when mongoc_cleanup is called correctly.

Motivation

While evaluating the PHP driver usage on Atlas, I noticed that apparently 60% of our users only use the MongoDB extension, but not the high-level API. Based on personal observations, I consider this number to be way too low, which led me to suspecting that we are getting incorrect data.

For one, the amount of data we can send is limited, and I'm not sure we're sending the right data in the right format. However, this is not something that we can fix here, as the handshake spec defines what to do here. I'll file a separate DRIVERS ticket for that effort.

Particularly for PHP, there are multiple places where we need to add info to the metadata. The PHP extension adds its own name and version, as does the PHP library. The Doctrine ODM does this as well, but this doesn't show up at all. There is a separate problem in ODM about this, but we'd expect the PHP library information to show up correctly. However, the following code would report only usage for ext-mongodb, but not for the library when both manager and client connect to the server:

$manager = new MongoDB\Driver\Manager(null, [], ['disableClientPersistence' => true]);
$client = new MongoDB\Client(null, [], ['disableClientPersistence' => true]);

The first instantiation of a Manager object calls `mongoc_handshake_data_append`, which freezes the handshake struct, rendering the second call (when creating a new manager with different app metadata) useless and always reporting `ext-mongodb` usage.

Changing this behaviour would not only help report correct data, but it also solves the issue if we look at the higher-level applications as well: if a customer used Symfony and Laravel and uses the same application server to run both applications, we'd only ever get one usage reported, as PHP processes usually do not terminate (CLI being a notable exception) after serving a request. A PHP process that first handles a script that connects to MongoDB using Laravel, then later handles a script that connects to MongoDB using Symfony, we'd never know the customer was using Symfony at all.


Generated at Wed Feb 07 21:20:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.