Repository: redpanda-data/connect (language: go)

Issue:
add name to the mongo input/output for tracking w/ mongodb
https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.16.0/mongo/options#ClientOptions.SetAppName


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e977262e4..eed3ae3fe1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
 
 ## 4.32.0 - TBD
 
+### Added
+
+- Field `app_name` added to the MongoDB components. (@mihaitodor)
+
 ### Changed
 
 - The `gcp_pubsub` output now rejects messages with metadata values which contain invalid UTF-8-encoded runes. (@AndreasBergmeier6176)
diff --git a/docs/modules/components/pages/caches/mongodb.adoc b/docs/modules/components/pages/caches/mongodb.adoc
index c07a18b9f6..b689c8d791 100644
--- a/docs/modules/components/pages/caches/mongodb.adoc
+++ b/docs/modules/components/pages/caches/mongodb.adoc
@@ -24,19 +24,48 @@ Use a MongoDB instance as a cache.
 
 Introduced in version 3.43.0.
 
+
+[tabs]
+======
+Common::
++
+--
+
+```yml
+# Common config fields, showing default values
+label: ""
+mongodb:
+  url: mongodb://localhost:27017 # No default (required)
+  database: "" # No default (required)
+  username: ""
+  password: ""
+  collection: "" # No default (required)
+  key_field: "" # No default (required)
+  value_field: "" # No default (required)
+```
+
+--
+Advanced::
++
+--
+
 ```yml
-# Config fields, showing default values
+# All config fields, showing default values
 label: ""
 mongodb:
   url: mongodb://localhost:27017 # No default (required)
   database: "" # No default (required)
   username: ""
   password: ""
+  app_name: benthos
   collection: "" # No default (required)
   key_field: "" # No default (required)
   value_field: "" # No default (required)
 ```
 
+--
+======
+
 == Fields
 
 === `url`
@@ -84,6 +113,15 @@ This field contains sensitive information that usually shouldn't be added to a c
 
 *Default*: `""`
 
+=== `app_name`
+
+The client application name.
+
+
+*Type*: `string`
+
+*Default*: `"benthos"`
+
 === `collection`
 
 The name of the target collection.
diff --git a/docs/modules/components/pages/inputs/mongodb.adoc b/docs/modules/components/pages/inputs/mongodb.adoc
index 1535b871e1..cb7a41bb4b 100644
--- a/docs/modules/components/pages/inputs/mongodb.adoc
+++ b/docs/modules/components/pages/inputs/mongodb.adoc
@@ -65,6 +65,7 @@ input:
     database: "" # No default (required)
     username: ""
     password: ""
+    app_name: benthos
     collection: "" # No default (required)
     operation: find
     json_marshal_mode: canonical
@@ -129,6 +130,15 @@ This field contains sensitive information that usually shouldn't be added to a c
 
 *Default*: `""`
 
+=== `app_name`
+
+The client application name.
+
+
+*Type*: `string`
+
+*Default*: `"benthos"`
+
 === `collection`
 
 The collection to select from.
diff --git a/docs/modules/components/pages/outputs/mongodb.adoc b/docs/modules/components/pages/outputs/mongodb.adoc
index d3fe32535d..c16179cbe1 100644
--- a/docs/modules/components/pages/outputs/mongodb.adoc
+++ b/docs/modules/components/pages/outputs/mongodb.adoc
@@ -73,6 +73,7 @@ output:
     database: "" # No default (required)
     username: ""
     password: ""
+    app_name: benthos
     collection: "" # No default (required)
     operation: update-one
     write_concern:
@@ -149,6 +150,15 @@ This field contains sensitive information that usually shouldn't be added to a c
 
 *Default*: `""`
 
+=== `app_name`
+
+The client application name.
+
+
+*Type*: `string`
+
+*Default*: `"benthos"`
+
 === `collection`
 
 The name of the target collection.
diff --git a/docs/modules/components/pages/processors/mongodb.adoc b/docs/modules/components/pages/processors/mongodb.adoc
index c3f3300bd0..ccf5f2c901 100644
--- a/docs/modules/components/pages/processors/mongodb.adoc
+++ b/docs/modules/components/pages/processors/mongodb.adoc
@@ -65,6 +65,7 @@ mongodb:
   database: "" # No default (required)
   username: ""
   password: ""
+  app_name: benthos
   collection: "" # No default (required)
   operation: insert-one
   write_concern:
@@ -128,6 +129,15 @@ This field contains sensitive information that usually shouldn't be added to a c
 
 *Default*: `""`
 
+=== `app_name`
+
+The client application name.
+
+
+*Type*: `string`
+
+*Default*: `"benthos"`
+
 === `collection`
 
 The name of the target collection.
diff --git a/internal/impl/mongodb/common.go b/internal/impl/mongodb/common.go
index acfc502109..76bf750c06 100644
--- a/internal/impl/mongodb/common.go
+++ b/internal/impl/mongodb/common.go
@@ -48,6 +48,7 @@ const (
 	commonFieldClientDatabase = "database"
 	commonFieldClientUsername = "username"
 	commonFieldClientPassword = "password"
+	commonFieldClientAppName  = "app_name"
 )
 
 func clientFields() []*service.ConfigField {
@@ -64,6 +65,10 @@ func clientFields() []*service.ConfigField {
 			Description("The password to connect to the database.").
 			Default("").
 			Secret(),
+		service.NewURLField(commonFieldClientAppName).
+			Description("The client application name.").
+			Default("benthos").
+			Advanced(),
 	}
 }
 
@@ -81,11 +86,17 @@ func getClient(parsedConf *service.ParsedConfig) (client *mongo.Client, database
 		return
 	}
 
+	var appName string
+	if appName, err = parsedConf.FieldString(commonFieldClientAppName); err != nil {
+		return
+	}
+
 	opt := options.Client().
 		SetConnectTimeout(10 * time.Second).
 		SetSocketTimeout(30 * time.Second).
 		SetServerSelectionTimeout(30 * time.Second).
-		ApplyURI(url)
+		ApplyURI(url).
+		SetAppName(appName)
 
 	if username != "" && password != "" {
 		creds := options.Credential{


Test patch: