grpc / grpc-swift

The Swift language implementation of gRPC.
Apache License 2.0
2.03k stars 420 forks source link

Programmatically Query Library Version #1339

Open rlasante opened 2 years ago

rlasante commented 2 years ago

What are you trying to achieve?

I'm attempting to get the grpc-swift library version programmatically to include it in my user-agent headers for grpc requests.

Using a customMetadata header with the key user-agent properly overrides the default user-agent passed by the framework. However I'm attempting to follow the format defined in the gRPC core user-agent definition

User Agents

While the protocol does not require a user-agent to function it is recommended that clients provide a structured user-agent string that provides a basic description of the calling library, version & platform to facilitate issue diagnosis in heterogeneous environments. The following structure is recommended to library developers User-Agent → "grpc-" Language ?("-" Variant) "/" Version ?( " (" *(AdditionalProperty ";") ")" )

E.g. grpc-java/1.2.3 grpc-ruby/1.2.3 grpc-ruby-jruby/1.3.4 grpc-java-android/0.9.1 (gingerbread/1.2.4; nexus5; tmobile)

so my example would be grpc-swift/1.6.0 (com.company.MyApp/1.0; iOS/15)

What have you tried so far?

I am unable to access the current version information stored here due to internal level visibility: Version

I am unable to use the library's own user-agent due to it being private.

I really would prefer not to have to either

  1. write a script to pull what version I'm using
  2. manually update a constant

Any help or suggestions would be greatly appreciated.

glbrntt commented 2 years ago

I am unable to access the current version information stored here due to internal level visibility: Version

We would accept a PR to make this public (although it would need to be renamed GRPCVersion because of https://github.com/grpc/grpc-swift/blob/main/docs/api.md).

If you were motivated enough, an additional object which provided a way to generate a user-agent string with additional properties could be a nice addition as well.