Skip to content

Commit

Permalink
[core] add EdgeRuntime telemetry info (#30239)
Browse files Browse the repository at this point in the history
currently the property only holds a string `edge-runtime` but in the
future
hopefully it would contain more useful info.

while at it also port PR
#30194 to ts-http-runtime

-------

### Packages impacted by this PR
`@azure/core-rest-pipeline`, `@typespec/ts-http-runtime`
  • Loading branch information
jeremymeng authored Jul 8, 2024
1 parent d133eaf commit c29b8f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ interface NavigatorEx extends Navigator {
};
}

declare const globalThis: {
navigator?: NavigatorEx;
EdgeRuntime?: unknown;
};

function getBrowserInfo(userAgent: string): BrowserBrand | undefined {
const browserRegexes = [
{ name: "Firefox", regex: /Firefox\/([\d.]+)/ },
Expand Down Expand Up @@ -84,6 +89,8 @@ export async function setPlatformSpecificData(map: Map<string, string>): Promise
if (brand) {
map.set(brand.brand, brand.version);
}
} else if (typeof globalThis.EdgeRuntime === "string") {
map.set("EdgeRuntime", globalThis.EdgeRuntime);
}

map.set("OS", osPlatform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ interface NavigatorEx extends Navigator {
};
}

declare const globalThis: {
navigator?: NavigatorEx;
EdgeRuntime?: unknown;
};

function getBrowserInfo(userAgent: string): BrowserBrand | undefined {
const browserRegexes = [
{ name: "Firefox", regex: /Firefox\/([\d.]+)/ },
Expand Down Expand Up @@ -66,7 +71,7 @@ function getBrandVersionString(brands: BrowserBrand[]): BrowserBrand | undefined
export async function setPlatformSpecificData(map: Map<string, string>): Promise<void> {
const localNavigator = globalThis.navigator as NavigatorEx;
let osPlatform = "unknown";
if (localNavigator.userAgentData) {
if (localNavigator?.userAgentData) {
const entropyValues = await localNavigator.userAgentData.getHighEntropyValues([
"architecture",
"platformVersion",
Expand All @@ -84,6 +89,8 @@ export async function setPlatformSpecificData(map: Map<string, string>): Promise
if (brand) {
map.set(brand.brand, brand.version);
}
} else if (typeof globalThis.EdgeRuntime === "string") {
map.set("EdgeRuntime", globalThis.EdgeRuntime);
}

map.set("OS", osPlatform);
Expand Down

0 comments on commit c29b8f7

Please sign in to comment.