Skip to content

Commit 6bce1bc

Browse files
committed
Browser resource attributes
1 parent 478e045 commit 6bce1bc

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/logfire-browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"eslint": "^9.22.0",
6666
"prettier": "3.5.3",
6767
"typescript": "^5.8.2",
68+
"user-agent-data-types": "^0.4.2",
6869
"vite": "^6.2.0",
6970
"vite-plugin-dts": "^4.5.3",
7071
"vitest": "^3.1.1"

packages/logfire-browser/src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ import {
1010
ATTR_TELEMETRY_SDK_LANGUAGE,
1111
ATTR_TELEMETRY_SDK_NAME,
1212
ATTR_TELEMETRY_SDK_VERSION,
13+
ATTR_USER_AGENT_ORIGINAL,
1314
TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,
1415
} from '@opentelemetry/semantic-conventions'
16+
import {
17+
ATTR_BROWSER_BRANDS,
18+
ATTR_BROWSER_LANGUAGE,
19+
ATTR_BROWSER_MOBILE,
20+
ATTR_BROWSER_PLATFORM,
21+
} from '@opentelemetry/semantic-conventions/incubating'
1522
import { ULIDGenerator } from '@pydantic/logfire-api'
1623
import * as logfireApi from '@pydantic/logfire-api'
1724
export { DiagLogLevel } from '@opentelemetry/api'
@@ -64,12 +71,22 @@ export function configure(options: LogfireConfigOptions) {
6471
}
6572

6673
const resource = resourceFromAttributes({
74+
[ATTR_BROWSER_LANGUAGE]: navigator.language,
6775
[ATTR_SERVICE_NAME]: options.serviceName ?? 'logfire-browser',
6876
[ATTR_SERVICE_VERSION]: options.serviceVersion ?? '0.0.1',
6977
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,
7078
[ATTR_TELEMETRY_SDK_NAME]: 'logfire-browser',
7179
// eslint-disable-next-line no-undef
7280
[ATTR_TELEMETRY_SDK_VERSION]: PACKAGE_VERSION,
81+
...(navigator.userAgentData
82+
? {
83+
[ATTR_BROWSER_BRANDS]: navigator.userAgentData.brands.map((brand) => `${brand.brand} ${brand.version}`),
84+
[ATTR_BROWSER_MOBILE]: navigator.userAgentData.mobile,
85+
[ATTR_BROWSER_PLATFORM]: navigator.userAgentData.platform,
86+
}
87+
: {
88+
[ATTR_USER_AGENT_ORIGINAL]: navigator.userAgent,
89+
}),
7390
})
7491

7592
diag.info('logfire-browser: starting')
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"extends": "@pydantic/logfire-tooling-config/tsconfig.base.json",
4-
"include": ["src", "vite.config.ts", "eslint.config.mjs", "prettier.config.mjs"]
4+
"include": ["src", "vite.config.ts", "eslint.config.mjs", "prettier.config.mjs"],
5+
"compilerOptions": {
6+
"types": ["../../node_modules/user-agent-data-types"]
7+
}
58
}

0 commit comments

Comments
 (0)