jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

Call mongoc_handshake_data_append #225

Closed kevinAlbs closed 2 years ago

kevinAlbs commented 2 years ago

Summary Calls the libmongoc function mongoc_handshake_data_append to add additional metadata to the connection handshake to identify wrapping drivers.

Motivation The MongoDB driver handshake specification Supporting Wrapping Libraries defines an API for wrapping libraries to identify themselves. mongoc_handshake_data_append is utilized by the MongoDB PHP driver and MongoDB C++ driver.

Testing

I am new to R. I was able to build and install locally with:

R CMD BUILD mongolite
R CMD INSTALL mongolite_2_3_1.tar.gz

I tested this by opening a connection with:

library(mongolite)
m <- mongo()

I observed the logs of a local running mongod to see the difference in the handshake metadata.

Before this change:

{"t":{"$date":"2021-08-23T11:56:25.010-04:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn1073","msg":"client metadata","attr":{"remote":"127.0.0.1:60575","client":"conn1072","doc":{"application":{"name":"r/mongolite"},"driver":{"name":"mongoc","version":"1.16.2"},"os":{"type":"Darwin","name":"macOS","version":"20.5.0","architecture":"x86_64"},"platform":"cfg=0x000216aa65 posix=200112 stdc=201710 CC=clang 12.0.5 (clang-1205.0.22.11) CFLAGS=\"\" LDFLAGS=\"\""}}}

After this change:

{"t":{"$date":"2021-08-23T12:15:27.444-04:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn1074","msg":"client metadata","attr":{"remote":"127.0.0.1:61003","client":"conn1074","doc":{"application":{"name":"r/mongolite"},"driver":{"name":"mongoc / mongolite","version":"1.16.2 / "},"os":{"type":"Darwin","name":"macOS","version":"20.5.0","architecture":"x86_64"},"platform":"R=4.1.1 cfg=0x000216aa65 posix=200112 stdc=201710 CC=clang 12.0.5 (clang-1205.0.22.11) CFLAGS=\"\" LDFLAGS=\"\""}}}
jeroen commented 2 years ago

Alternatively we could use the user-agent value that R has built in, similar to: https://github.com/jeroen/curl/blob/master/src/handle.c#L170

This has more details, for example on my machine this is "RStudio Desktop (1.4.1103); R (4.1.1 x86_64-apple-darwin17.0 x86_64 darwin17.0)"