Skip to content

fix: update default user-agent to grpc-dart/<version> (dart/<sdk>) - #838

Open
kevmoo wants to merge 6 commits into
masterfrom
fix-user-agent
Open

kevmoo wants to merge 6 commits into
masterfrom
fix-user-agent

Conversation

@kevmoo

@kevmoo kevmoo commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Updates defaultUserAgent in package:grpc from the hardcoded dart-grpc/2.0.0 string (originally set in 2019) to the standard gRPC over HTTP/2 specification format (grpc-dart/<package_version> (dart/<sdk_version>) on dart:io and grpc-dart/<package_version> on web), and updates X-User-Agent in XhrClientConnection (xhr_transport.dart) from 'grpc-web-dart/0.1' to 'grpc-web-dart/<package_version>'.

Background & Motivation

  1. Reversed Product Token (dart-grpc vs grpc-dart): The gRPC over HTTP/2 protocol specification defines the User-Agent grammar as:
    User-Agent -> "grpc-" Language "-" ?Variant "/" Version ?( " (" *(AdditionalProperty ";") ")" )
    
    Every other gRPC implementation (grpc-go/<ver>, grpc-java/<ver>, grpc-python/<ver>, grpc-node/<ver>, grpc-c++/<ver>) emits grpc-<lang>/<ver>. Because package:grpc emitted dart-grpc/2.0.0, Google Cloud / OnePlatform telemetry extractors matching \bgrpc-<lang>/([0-9A-Za-z.-]+) failed to recognize Dart gRPC requests as a gRPC client library (unknown-grpc-client) or extract the version.
  2. Frozen Version (2.0.0): defaultUserAgent was frozen at 2.0.0 across all 2.x5.x releases, making it impossible to distinguish package:grpc versions or Dart SDK runtime versions (dart/<sdk_version>) in backend diagnostics.

Changes

  • Added lib/src/version.dart (const packageVersion = '5.2.0';) verified against pubspec.yaml in test/version_test.dart.
  • Added conditional platform helpers (user_agent_io.dart if dart.library.js_interop user_agent_web.dart) so defaultUserAgent includes (dart/<sdk_version>) on dart:io and grpc-dart/5.2.0 on web.
  • Updated XhrClientConnection (lib/src/client/transport/xhr_transport.dart) to send X-User-Agent: grpc-web-dart/$packageVersion.
  • Updated ChannelOptions({String? userAgent}) to remain const while resolving userAgent ?? defaultUserAgent.
  • Added VM (test/version_test.dart) and browser (test/version_web_test.dart) unit tests.

Align defaultUserAgent with the gRPC over HTTP/2 User-Agent specification (grpc-<lang>/<version>):
- Emit 'grpc-dart/<packageVersion> (dart/<sdkVersion>)' on dart:io and 'grpc-dart/<packageVersion>' on web.
- Keep ChannelOptions() const-constructible while resolving defaultUserAgent dynamically when userAgent is omitted.
- Add test/version_test.dart to ensure packageVersion stays synchronized with pubspec.yaml.
@kevmoo
kevmoo requested a review from mosuem September 17, 2026 15:11
@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
grpc Non-Breaking 5.1.0 5.2.0 5.2.0 ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

Package publishing

If you have publishing permissions, you can use the links below to publish the changes after merging this PR.

Package Version Status Publish tag (post-merge)
package:grpc 5.2.0 ready to publish v5.2.0

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@mosuem mosuem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI-agent] Overall LGTM! A few minor comments inline.

Comment thread lib/src/client/options.dart Outdated
Comment thread test/version_test.dart
Comment thread lib/src/client/user_agent_web.dart
Comment thread pubspec.yaml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants