Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] improve user agent information for React Native #21644

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export function getDefaultUserAgentKey(): string {
}

export function getPlatformSpecificData(): TelemetryInfo[] {
const { major, minor, patch } = Platform.constants.reactNativeVersion;
const runtimeInfo = {
key: "react-native",
value: Platform.reactNativeVersion,
value: `${major}.${minor}.${patch}`,
};

const osInfo = {
key: "OS",
value: `${Platform.OS}-${String(Platform.Version)}`,
value: `${Platform.OS}-${Platform.Version}`,
};

return [runtimeInfo, osInfo];
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/core-rest-pipeline/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- Exposed type guard for RestError called `isRestError` for typesafe exception handling.

- Improve user agent information for React-Native.

### Breaking Changes

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/*
* NOTE: When moving this file, please update "react-native" section in package.json.
*/
const { Platform } = require("react-native"); // eslint-disable-line import/no-extraneous-dependencies, @typescript-eslint/no-require-imports

/**
* @internal
Expand All @@ -16,8 +17,7 @@ export function getHeaderName(): string {
* @internal
*/
export function setPlatformSpecificData(map: Map<string, string>): void {
// TODO: Investigate using `import { Platform } from "react-native"` to get "OS" and "Version".
// This may bring in a lot of overhead if we have to use this package directly, perhaps we can shim
// types.
map.set("OS", `react-native`);
const { major, minor, patch } = Platform.constants.reactNativeVersion;
map.set("react-native", `${major}.${minor}.${patch}`);
map.set("OS", `${Platform.OS}-${Platform.Version}`);
}