influxdata / influxdb-client-go

InfluxDB 2 Go Client
MIT License
609 stars 116 forks source link

Allow overriding the default User-Agent header #356

Closed dgnorton closed 2 years ago

dgnorton commented 2 years ago

Proposal: Add a feature allowing users of this client library to override the default influxdb-client-go User-Agent HTTP header. This would make it easier to understand which apps are making which requests. E.g., currently, if App1 and App2 use this client, the UA coming from both will read influxdb-client-go. Allowing the apps to override the UA would make it easier to distinguish between the two.

Current behavior: User-Agent header is hard coded to influxdb-client-go

Desired behavior: Add 2 options for users:

  1. Add method to set a field or two (AppName and Version?) for their User-Agent. The client would then construct a User-Agent. Something like influxdb-client-go/2.3 AppName/Version. Mark this in the docs as recommended.
  2. Add a second method that allows completely overriding the User-Agent.
sranka commented 2 years ago

I think that it is a good idea (and already good practice in other databases) to have a simple option to set application name. My preference would be to represent it as one string with documentation saying that it should distinguish applications that connect to the same InfluxDB. The same option should be better present in all InfluxDB clients (python, java, js ...).

It is already possible to customize anything in the request, including User-Agent, see #314.

dgnorton commented 2 years ago

I think that is fine. Also, maybe setting the application name should be required? That would break backwards compatibility but would be a simple update for clients and would encourage a best practice.

vlastahajek commented 2 years ago

Ok. When an application name will be set, it will be added to the end of the current UA string. E.g.: influxdb-client-go/2.10.0 (linux; amd64) IoTHub/1.10

lesam commented 2 years ago

I don't love breaking a ton of users for this - maybe an annoying log message if the application name is unset would be enough?

lesam commented 2 years ago

Also an example of how to set custom headers with Doer might be a good addition to the docs, if it's not there already.

vlastahajek commented 2 years ago

I don't love breaking a ton of users for this - maybe an annoying log message if the application name is unset would be enough?

👍 That's exactly what I wanted to propose - a warning message to set application.

bednar commented 2 years ago

jfyi... the Mongo uses AppName configuration options - https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.10.3/mongo/options#ClientOptions.SetAppName