influxdb-client-go icon indicating copy to clipboard operation
influxdb-client-go copied to clipboard

Allow overriding the default User-Agent header

Open dgnorton opened this issue 2 years ago • 7 comments

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.

dgnorton avatar Sep 15 '22 18:09 dgnorton

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.

sranka avatar Sep 15 '22 20:09 sranka

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.

dgnorton avatar Sep 16 '22 00:09 dgnorton

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

vlastahajek avatar Sep 16 '22 10:09 vlastahajek

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 avatar Sep 16 '22 12:09 lesam

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.

lesam avatar Sep 16 '22 12:09 lesam

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.

vlastahajek avatar Sep 16 '22 13:09 vlastahajek

jfyi... the Mongo uses AppName configuration options - https://pkg.go.dev/go.mongodb.org/[email protected]/mongo/options#ClientOptions.SetAppName

bednar avatar Oct 07 '22 08:10 bednar