@opentelemetry/opentelemetry-browser-detector 0.222.0 → 0.300.0-development.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/dist/BrowserDetector.cjs +45 -0
- package/dist/BrowserDetector.cjs.map +1 -0
- package/dist/BrowserDetector.d.cts +20 -0
- package/dist/BrowserDetector.d.cts.map +1 -0
- package/dist/BrowserDetector.d.mts +20 -0
- package/dist/BrowserDetector.d.mts.map +1 -0
- package/dist/BrowserDetector.mjs +45 -0
- package/dist/BrowserDetector.mjs.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/semconv.cjs +52 -0
- package/dist/semconv.cjs.map +1 -0
- package/dist/semconv.mjs +49 -0
- package/dist/semconv.mjs.map +1 -0
- package/package.json +28 -26
- package/build/esm/BrowserDetector.d.ts +0 -18
- package/build/esm/BrowserDetector.js +0 -53
- package/build/esm/BrowserDetector.js.map +0 -1
- package/build/esm/index.d.ts +0 -2
- package/build/esm/index.js +0 -6
- package/build/esm/index.js.map +0 -1
- package/build/esm/semconv.d.ts +0 -45
- package/build/esm/semconv.js +0 -49
- package/build/esm/semconv.js.map +0 -1
- package/build/esm/types.d.ts +0 -9
- package/build/esm/types.js +0 -6
- package/build/esm/types.js.map +0 -1
- package/build/esm/version.d.ts +0 -2
- package/build/esm/version.js +0 -7
- package/build/esm/version.js.map +0 -1
- package/build/esnext/BrowserDetector.d.ts +0 -18
- package/build/esnext/BrowserDetector.js +0 -53
- package/build/esnext/BrowserDetector.js.map +0 -1
- package/build/esnext/index.d.ts +0 -2
- package/build/esnext/index.js +0 -6
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/semconv.d.ts +0 -45
- package/build/esnext/semconv.js +0 -49
- package/build/esnext/semconv.js.map +0 -1
- package/build/esnext/types.d.ts +0 -9
- package/build/esnext/types.js +0 -6
- package/build/esnext/types.js.map +0 -1
- package/build/esnext/version.d.ts +0 -2
- package/build/esnext/version.js +0 -7
- package/build/esnext/version.js.map +0 -1
- package/build/src/BrowserDetector.d.ts +0 -18
- package/build/src/BrowserDetector.js +0 -56
- package/build/src/BrowserDetector.js.map +0 -1
- package/build/src/index.d.ts +0 -2
- package/build/src/index.js +0 -10
- package/build/src/index.js.map +0 -1
- package/build/src/semconv.d.ts +0 -45
- package/build/src/semconv.js +0 -52
- package/build/src/semconv.js.map +0 -1
- package/build/src/types.d.ts +0 -9
- package/build/src/types.js +0 -7
- package/build/src/types.js.map +0 -1
- package/build/src/version.d.ts +0 -2
- package/build/src/version.js +0 -10
- package/build/src/version.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,6 +13,9 @@ npm install --save @opentelemetry/opentelemetry-browser-detector
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
|
+
import { context, trace } from '@opentelemetry/api';
|
|
17
|
+
import { TracerProvider } from '@opentelemetry/trace-sdk';
|
|
18
|
+
import { ZoneContextManager } = from '@opentelemetry/context-zone';
|
|
16
19
|
import { resourceFromAttributes, detectResources } from '@opentelemetry/resources';
|
|
17
20
|
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
18
21
|
import { browserDetector } from '@opentelemetry/opentelemetry-browser-detector';
|
|
@@ -21,9 +24,9 @@ async function start(){
|
|
|
21
24
|
let resource = resourceFromAttributes({
|
|
22
25
|
[ATTR_SERVICE_NAME]: 'Test App Name',
|
|
23
26
|
});
|
|
24
|
-
let detectedResources= await detectResources({detectors:[browserDetector]});
|
|
25
|
-
resource=resource.merge(detectedResources);
|
|
26
|
-
const provider = new
|
|
27
|
+
let detectedResources = await detectResources({detectors:[browserDetector]});
|
|
28
|
+
resource = resource.merge(detectedResources);
|
|
29
|
+
const provider = new TracerProvider({
|
|
27
30
|
resource,
|
|
28
31
|
spanProcessors: [
|
|
29
32
|
new BatchSpanProcessor(
|
|
@@ -36,13 +39,11 @@ async function start(){
|
|
|
36
39
|
]
|
|
37
40
|
});
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Registering instrumentations
|
|
42
|
+
// Changing default contextManager to use ZoneContextManager - supports asynchronous operations - optional
|
|
43
|
+
context.setGlobalContextManager(new ZoneContextManager().enable());
|
|
44
|
+
trace.setGlobalTracerProvider(provider);
|
|
45
45
|
|
|
46
|
+
// Registering instrumentations
|
|
46
47
|
registerInstrumentations({
|
|
47
48
|
instrumentations: [
|
|
48
49
|
new DocumentLoadInstrumentation(),
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_semconv = require("./semconv.cjs");
|
|
2
|
+
let _opentelemetry_api = require("@opentelemetry/api");
|
|
3
|
+
let _opentelemetry_resources = require("@opentelemetry/resources");
|
|
4
|
+
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
5
|
+
//#region src/BrowserDetector.ts
|
|
6
|
+
/**
|
|
7
|
+
* BrowserDetector will be used to detect the resources related to browser.
|
|
8
|
+
*/
|
|
9
|
+
var BrowserDetector = class {
|
|
10
|
+
detect(config) {
|
|
11
|
+
if (!(typeof window !== "undefined" && typeof document !== "undefined")) return (0, _opentelemetry_resources.emptyResource)();
|
|
12
|
+
const browserResource = getBrowserAttributes();
|
|
13
|
+
return this._getResourceAttributes(browserResource, config);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates browser resource attribute map from browser variables
|
|
17
|
+
*
|
|
18
|
+
* @param browserResource The un-sanitized resource attributes from browser as key/value pairs.
|
|
19
|
+
* @param config: Config
|
|
20
|
+
* @returns The sanitized resource attributes.
|
|
21
|
+
*/
|
|
22
|
+
_getResourceAttributes(browserResource, _config) {
|
|
23
|
+
if (!browserResource[_opentelemetry_semantic_conventions.ATTR_USER_AGENT_ORIGINAL] && !browserResource["browser.platform"]) {
|
|
24
|
+
_opentelemetry_api.diag.debug("BrowserDetector failed: Unable to find required browser resources. ");
|
|
25
|
+
return (0, _opentelemetry_resources.emptyResource)();
|
|
26
|
+
} else return { attributes: browserResource };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function getBrowserAttributes() {
|
|
30
|
+
const browserAttribs = {};
|
|
31
|
+
const userAgentData = navigator.userAgentData;
|
|
32
|
+
if (userAgentData) {
|
|
33
|
+
browserAttribs[require_semconv.ATTR_BROWSER_PLATFORM] = userAgentData.platform;
|
|
34
|
+
browserAttribs[require_semconv.ATTR_BROWSER_BRANDS] = userAgentData.brands.map((b) => `${b.brand} ${b.version}`);
|
|
35
|
+
browserAttribs[require_semconv.ATTR_BROWSER_MOBILE] = userAgentData.mobile;
|
|
36
|
+
}
|
|
37
|
+
browserAttribs[_opentelemetry_semantic_conventions.ATTR_USER_AGENT_ORIGINAL] = navigator.userAgent;
|
|
38
|
+
browserAttribs[require_semconv.ATTR_BROWSER_LANGUAGE] = navigator.language;
|
|
39
|
+
return browserAttribs;
|
|
40
|
+
}
|
|
41
|
+
const browserDetector = new BrowserDetector();
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.browserDetector = browserDetector;
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=BrowserDetector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserDetector.cjs","names":["emptyResource","ATTR_USER_AGENT_ORIGINAL","ATTR_BROWSER_PLATFORM","ATTR_BROWSER_BRANDS","ATTR_BROWSER_MOBILE","ATTR_BROWSER_LANGUAGE"],"sources":["../src/BrowserDetector.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\nimport type {\n DetectedResource,\n ResourceDetector,\n ResourceDetectionConfig,\n} from '@opentelemetry/resources';\nimport { emptyResource } from '@opentelemetry/resources';\nimport { ATTR_USER_AGENT_ORIGINAL } from '@opentelemetry/semantic-conventions';\nimport type { UserAgentData } from './types';\nimport {\n ATTR_BROWSER_LANGUAGE,\n ATTR_BROWSER_PLATFORM,\n ATTR_BROWSER_BRANDS,\n ATTR_BROWSER_MOBILE,\n} from './semconv';\n\n/**\n * BrowserDetector will be used to detect the resources related to browser.\n */\nclass BrowserDetector implements ResourceDetector {\n detect(config?: ResourceDetectionConfig): DetectedResource {\n const isBrowser =\n typeof window !== 'undefined' && typeof document !== 'undefined';\n\n if (!isBrowser) {\n return emptyResource();\n }\n const browserResource: Attributes = getBrowserAttributes();\n return this._getResourceAttributes(browserResource, config);\n }\n /**\n * Validates browser resource attribute map from browser variables\n *\n * @param browserResource The un-sanitized resource attributes from browser as key/value pairs.\n * @param config: Config\n * @returns The sanitized resource attributes.\n */\n private _getResourceAttributes(\n browserResource: Attributes,\n _config?: ResourceDetectionConfig\n ): DetectedResource {\n if (\n !browserResource[ATTR_USER_AGENT_ORIGINAL] &&\n !browserResource[ATTR_BROWSER_PLATFORM]\n ) {\n diag.debug(\n 'BrowserDetector failed: Unable to find required browser resources. '\n );\n return emptyResource();\n } else {\n return { attributes: browserResource };\n }\n }\n}\n\n// Add Browser related attributes to resources\nfunction getBrowserAttributes(): Attributes {\n const browserAttribs: Attributes = {};\n const userAgentData = (\n navigator as Navigator & { userAgentData?: UserAgentData }\n ).userAgentData;\n if (userAgentData) {\n browserAttribs[ATTR_BROWSER_PLATFORM] = userAgentData.platform;\n browserAttribs[ATTR_BROWSER_BRANDS] = userAgentData.brands.map(\n b => `${b.brand} ${b.version}`\n );\n browserAttribs[ATTR_BROWSER_MOBILE] = userAgentData.mobile;\n }\n browserAttribs[ATTR_USER_AGENT_ORIGINAL] = navigator.userAgent;\n browserAttribs[ATTR_BROWSER_LANGUAGE] = navigator.language;\n return browserAttribs;\n}\n\nexport const browserDetector = new BrowserDetector();\n"],"mappings":";;;;;;;;AAyBA,IAAM,kBAAN,MAAkD;CAChD,OAAO,QAAoD;EAIzD,IAAI,EAFF,OAAO,WAAW,eAAe,OAAO,aAAa,cAGrD,QAAA,GAAOA,yBAAAA,cAAAA,CAAc;EAEvB,MAAM,kBAA8B,qBAAqB;EACzD,OAAO,KAAK,uBAAuB,iBAAiB,MAAM;CAC5D;;;;;;;;CAQA,uBACE,iBACA,SACkB;EAClB,IACE,CAAC,gBAAgBC,oCAAAA,6BACjB,CAAC,gBAAA,qBACD;GACA,mBAAA,KAAK,MACH,qEACF;GACA,QAAA,GAAOD,yBAAAA,cAAAA,CAAc;EACvB,OACE,OAAO,EAAE,YAAY,gBAAgB;CAEzC;AACF;AAGA,SAAS,uBAAmC;CAC1C,MAAM,iBAA6B,CAAC;CACpC,MAAM,gBACJ,UACA;CACF,IAAI,eAAe;EACjB,eAAeE,gBAAAA,yBAAyB,cAAc;EACtD,eAAeC,gBAAAA,uBAAuB,cAAc,OAAO,KACzD,MAAK,GAAG,EAAE,MAAM,GAAG,EAAE,SACvB;EACA,eAAeC,gBAAAA,uBAAuB,cAAc;CACtD;CACA,eAAeH,oCAAAA,4BAA4B,UAAU;CACrD,eAAeI,gBAAAA,yBAAyB,UAAU;CAClD,OAAO;AACT;AAEA,MAAa,kBAAkB,IAAI,gBAAgB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DetectedResource, ResourceDetectionConfig, ResourceDetector } from "@opentelemetry/resources";
|
|
2
|
+
//#region src/BrowserDetector.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* BrowserDetector will be used to detect the resources related to browser.
|
|
5
|
+
*/
|
|
6
|
+
declare class BrowserDetector implements ResourceDetector {
|
|
7
|
+
detect(config?: ResourceDetectionConfig): DetectedResource;
|
|
8
|
+
/**
|
|
9
|
+
* Validates browser resource attribute map from browser variables
|
|
10
|
+
*
|
|
11
|
+
* @param browserResource The un-sanitized resource attributes from browser as key/value pairs.
|
|
12
|
+
* @param config: Config
|
|
13
|
+
* @returns The sanitized resource attributes.
|
|
14
|
+
*/
|
|
15
|
+
private _getResourceAttributes;
|
|
16
|
+
}
|
|
17
|
+
declare const browserDetector: BrowserDetector;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { browserDetector };
|
|
20
|
+
//# sourceMappingURL=BrowserDetector.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserDetector.d.cts","names":[],"sources":["../src/BrowserDetector.d.ts"],"mappings":";;;;;cAIc,2BAA2B;EACrC,OAAO,SAAS,0BAA0B;;;;;;;;UAQlC;;cAES,iBAAiB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DetectedResource, ResourceDetectionConfig, ResourceDetector } from "@opentelemetry/resources";
|
|
2
|
+
//#region src/BrowserDetector.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* BrowserDetector will be used to detect the resources related to browser.
|
|
5
|
+
*/
|
|
6
|
+
declare class BrowserDetector implements ResourceDetector {
|
|
7
|
+
detect(config?: ResourceDetectionConfig): DetectedResource;
|
|
8
|
+
/**
|
|
9
|
+
* Validates browser resource attribute map from browser variables
|
|
10
|
+
*
|
|
11
|
+
* @param browserResource The un-sanitized resource attributes from browser as key/value pairs.
|
|
12
|
+
* @param config: Config
|
|
13
|
+
* @returns The sanitized resource attributes.
|
|
14
|
+
*/
|
|
15
|
+
private _getResourceAttributes;
|
|
16
|
+
}
|
|
17
|
+
declare const browserDetector: BrowserDetector;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { browserDetector };
|
|
20
|
+
//# sourceMappingURL=BrowserDetector.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserDetector.d.mts","names":[],"sources":["../src/BrowserDetector.d.ts"],"mappings":";;;;;cAIc,2BAA2B;EACrC,OAAO,SAAS,0BAA0B;;;;;;;;UAQlC;;cAES,iBAAiB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ATTR_BROWSER_BRANDS, ATTR_BROWSER_LANGUAGE, ATTR_BROWSER_MOBILE, ATTR_BROWSER_PLATFORM } from "./semconv.mjs";
|
|
2
|
+
import { diag } from "@opentelemetry/api";
|
|
3
|
+
import { emptyResource } from "@opentelemetry/resources";
|
|
4
|
+
import { ATTR_USER_AGENT_ORIGINAL } from "@opentelemetry/semantic-conventions";
|
|
5
|
+
//#region src/BrowserDetector.ts
|
|
6
|
+
/**
|
|
7
|
+
* BrowserDetector will be used to detect the resources related to browser.
|
|
8
|
+
*/
|
|
9
|
+
var BrowserDetector = class {
|
|
10
|
+
detect(config) {
|
|
11
|
+
if (!(typeof window !== "undefined" && typeof document !== "undefined")) return emptyResource();
|
|
12
|
+
const browserResource = getBrowserAttributes();
|
|
13
|
+
return this._getResourceAttributes(browserResource, config);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates browser resource attribute map from browser variables
|
|
17
|
+
*
|
|
18
|
+
* @param browserResource The un-sanitized resource attributes from browser as key/value pairs.
|
|
19
|
+
* @param config: Config
|
|
20
|
+
* @returns The sanitized resource attributes.
|
|
21
|
+
*/
|
|
22
|
+
_getResourceAttributes(browserResource, _config) {
|
|
23
|
+
if (!browserResource[ATTR_USER_AGENT_ORIGINAL] && !browserResource["browser.platform"]) {
|
|
24
|
+
diag.debug("BrowserDetector failed: Unable to find required browser resources. ");
|
|
25
|
+
return emptyResource();
|
|
26
|
+
} else return { attributes: browserResource };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function getBrowserAttributes() {
|
|
30
|
+
const browserAttribs = {};
|
|
31
|
+
const userAgentData = navigator.userAgentData;
|
|
32
|
+
if (userAgentData) {
|
|
33
|
+
browserAttribs[ATTR_BROWSER_PLATFORM] = userAgentData.platform;
|
|
34
|
+
browserAttribs[ATTR_BROWSER_BRANDS] = userAgentData.brands.map((b) => `${b.brand} ${b.version}`);
|
|
35
|
+
browserAttribs[ATTR_BROWSER_MOBILE] = userAgentData.mobile;
|
|
36
|
+
}
|
|
37
|
+
browserAttribs[ATTR_USER_AGENT_ORIGINAL] = navigator.userAgent;
|
|
38
|
+
browserAttribs[ATTR_BROWSER_LANGUAGE] = navigator.language;
|
|
39
|
+
return browserAttribs;
|
|
40
|
+
}
|
|
41
|
+
const browserDetector = new BrowserDetector();
|
|
42
|
+
//#endregion
|
|
43
|
+
export { browserDetector };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=BrowserDetector.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserDetector.mjs","names":[],"sources":["../src/BrowserDetector.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\nimport type {\n DetectedResource,\n ResourceDetector,\n ResourceDetectionConfig,\n} from '@opentelemetry/resources';\nimport { emptyResource } from '@opentelemetry/resources';\nimport { ATTR_USER_AGENT_ORIGINAL } from '@opentelemetry/semantic-conventions';\nimport type { UserAgentData } from './types';\nimport {\n ATTR_BROWSER_LANGUAGE,\n ATTR_BROWSER_PLATFORM,\n ATTR_BROWSER_BRANDS,\n ATTR_BROWSER_MOBILE,\n} from './semconv';\n\n/**\n * BrowserDetector will be used to detect the resources related to browser.\n */\nclass BrowserDetector implements ResourceDetector {\n detect(config?: ResourceDetectionConfig): DetectedResource {\n const isBrowser =\n typeof window !== 'undefined' && typeof document !== 'undefined';\n\n if (!isBrowser) {\n return emptyResource();\n }\n const browserResource: Attributes = getBrowserAttributes();\n return this._getResourceAttributes(browserResource, config);\n }\n /**\n * Validates browser resource attribute map from browser variables\n *\n * @param browserResource The un-sanitized resource attributes from browser as key/value pairs.\n * @param config: Config\n * @returns The sanitized resource attributes.\n */\n private _getResourceAttributes(\n browserResource: Attributes,\n _config?: ResourceDetectionConfig\n ): DetectedResource {\n if (\n !browserResource[ATTR_USER_AGENT_ORIGINAL] &&\n !browserResource[ATTR_BROWSER_PLATFORM]\n ) {\n diag.debug(\n 'BrowserDetector failed: Unable to find required browser resources. '\n );\n return emptyResource();\n } else {\n return { attributes: browserResource };\n }\n }\n}\n\n// Add Browser related attributes to resources\nfunction getBrowserAttributes(): Attributes {\n const browserAttribs: Attributes = {};\n const userAgentData = (\n navigator as Navigator & { userAgentData?: UserAgentData }\n ).userAgentData;\n if (userAgentData) {\n browserAttribs[ATTR_BROWSER_PLATFORM] = userAgentData.platform;\n browserAttribs[ATTR_BROWSER_BRANDS] = userAgentData.brands.map(\n b => `${b.brand} ${b.version}`\n );\n browserAttribs[ATTR_BROWSER_MOBILE] = userAgentData.mobile;\n }\n browserAttribs[ATTR_USER_AGENT_ORIGINAL] = navigator.userAgent;\n browserAttribs[ATTR_BROWSER_LANGUAGE] = navigator.language;\n return browserAttribs;\n}\n\nexport const browserDetector = new BrowserDetector();\n"],"mappings":";;;;;;;;AAyBA,IAAM,kBAAN,MAAkD;CAChD,OAAO,QAAoD;EAIzD,IAAI,EAFF,OAAO,WAAW,eAAe,OAAO,aAAa,cAGrD,OAAO,cAAc;EAEvB,MAAM,kBAA8B,qBAAqB;EACzD,OAAO,KAAK,uBAAuB,iBAAiB,MAAM;CAC5D;;;;;;;;CAQA,uBACE,iBACA,SACkB;EAClB,IACE,CAAC,gBAAgB,6BACjB,CAAC,gBAAA,qBACD;GACA,KAAK,MACH,qEACF;GACA,OAAO,cAAc;EACvB,OACE,OAAO,EAAE,YAAY,gBAAgB;CAEzC;AACF;AAGA,SAAS,uBAAmC;CAC1C,MAAM,iBAA6B,CAAC;CACpC,MAAM,gBACJ,UACA;CACF,IAAI,eAAe;EACjB,eAAe,yBAAyB,cAAc;EACtD,eAAe,uBAAuB,cAAc,OAAO,KACzD,MAAK,GAAG,EAAE,MAAM,GAAG,EAAE,SACvB;EACA,eAAe,uBAAuB,cAAc;CACtD;CACA,eAAe,4BAA4B,UAAU;CACrD,eAAe,yBAAyB,UAAU;CAClD,OAAO;AACT;AAEA,MAAa,kBAAkB,IAAI,gBAAgB"}
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
package/dist/semconv.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/semconv.ts
|
|
2
|
+
/**
|
|
3
|
+
* Array of brand name and version separated by a space
|
|
4
|
+
*
|
|
5
|
+
* @example [" Not A;Brand 99", "Chromium 99", "Chrome 99"]
|
|
6
|
+
*
|
|
7
|
+
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.brands`).
|
|
8
|
+
*
|
|
9
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
10
|
+
*/
|
|
11
|
+
const ATTR_BROWSER_BRANDS = "browser.brands";
|
|
12
|
+
/**
|
|
13
|
+
* Preferred language of the user using the browser
|
|
14
|
+
*
|
|
15
|
+
* @example en
|
|
16
|
+
* @example en-US
|
|
17
|
+
* @example fr
|
|
18
|
+
* @example fr-FR
|
|
19
|
+
*
|
|
20
|
+
* @note This value is intended to be taken from the Navigator API `navigator.language`.
|
|
21
|
+
*
|
|
22
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
23
|
+
*/
|
|
24
|
+
const ATTR_BROWSER_LANGUAGE = "browser.language";
|
|
25
|
+
/**
|
|
26
|
+
* A boolean that is true if the browser is running on a mobile device
|
|
27
|
+
*
|
|
28
|
+
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.mobile`). If unavailable, this attribute **SHOULD** be left unset.
|
|
29
|
+
*
|
|
30
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
31
|
+
*/
|
|
32
|
+
const ATTR_BROWSER_MOBILE = "browser.mobile";
|
|
33
|
+
/**
|
|
34
|
+
* The platform on which the browser is running
|
|
35
|
+
*
|
|
36
|
+
* @example Windows
|
|
37
|
+
* @example macOS
|
|
38
|
+
* @example Android
|
|
39
|
+
*
|
|
40
|
+
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.platform`). If unavailable, the legacy `navigator.platform` API **SHOULD NOT** be used instead and this attribute **SHOULD** be left unset in order for the values to be consistent.
|
|
41
|
+
* The list of possible values is defined in the [W3C User-Agent Client Hints specification](https://wicg.github.io/ua-client-hints/#sec-ch-ua-platform). Note that some (but not all) of these values can overlap with values in the [`os.type` and `os.name` attributes](./os.md). However, for consistency, the values in the `browser.platform` attribute should capture the exact value that the user agent provides.
|
|
42
|
+
*
|
|
43
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
44
|
+
*/
|
|
45
|
+
const ATTR_BROWSER_PLATFORM = "browser.platform";
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.ATTR_BROWSER_BRANDS = ATTR_BROWSER_BRANDS;
|
|
48
|
+
exports.ATTR_BROWSER_LANGUAGE = ATTR_BROWSER_LANGUAGE;
|
|
49
|
+
exports.ATTR_BROWSER_MOBILE = ATTR_BROWSER_MOBILE;
|
|
50
|
+
exports.ATTR_BROWSER_PLATFORM = ATTR_BROWSER_PLATFORM;
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=semconv.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semconv.cjs","names":[],"sources":["../src/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * Array of brand name and version separated by a space\n *\n * @example [\" Not A;Brand 99\", \"Chromium 99\", \"Chrome 99\"]\n *\n * @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.brands`).\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_BRANDS = 'browser.brands' as const;\n\n/**\n * Preferred language of the user using the browser\n *\n * @example en\n * @example en-US\n * @example fr\n * @example fr-FR\n *\n * @note This value is intended to be taken from the Navigator API `navigator.language`.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_LANGUAGE = 'browser.language' as const;\n\n/**\n * A boolean that is true if the browser is running on a mobile device\n *\n * @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.mobile`). If unavailable, this attribute **SHOULD** be left unset.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_MOBILE = 'browser.mobile' as const;\n\n/**\n * The platform on which the browser is running\n *\n * @example Windows\n * @example macOS\n * @example Android\n *\n * @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.platform`). If unavailable, the legacy `navigator.platform` API **SHOULD NOT** be used instead and this attribute **SHOULD** be left unset in order for the values to be consistent.\n * The list of possible values is defined in the [W3C User-Agent Client Hints specification](https://wicg.github.io/ua-client-hints/#sec-ch-ua-platform). Note that some (but not all) of these values can overlap with values in the [`os.type` and `os.name` attributes](./os.md). However, for consistency, the values in the `browser.platform` attribute should capture the exact value that the user agent provides.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_PLATFORM = 'browser.platform' as const;\n"],"mappings":";;;;;;;;;;AAcA,MAAa,sBAAsB;;;;;;;;;;;;;AAcnC,MAAa,wBAAwB;;;;;;;;AASrC,MAAa,sBAAsB;;;;;;;;;;;;;AAcnC,MAAa,wBAAwB"}
|
package/dist/semconv.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/semconv.ts
|
|
2
|
+
/**
|
|
3
|
+
* Array of brand name and version separated by a space
|
|
4
|
+
*
|
|
5
|
+
* @example [" Not A;Brand 99", "Chromium 99", "Chrome 99"]
|
|
6
|
+
*
|
|
7
|
+
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.brands`).
|
|
8
|
+
*
|
|
9
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
10
|
+
*/
|
|
11
|
+
const ATTR_BROWSER_BRANDS = "browser.brands";
|
|
12
|
+
/**
|
|
13
|
+
* Preferred language of the user using the browser
|
|
14
|
+
*
|
|
15
|
+
* @example en
|
|
16
|
+
* @example en-US
|
|
17
|
+
* @example fr
|
|
18
|
+
* @example fr-FR
|
|
19
|
+
*
|
|
20
|
+
* @note This value is intended to be taken from the Navigator API `navigator.language`.
|
|
21
|
+
*
|
|
22
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
23
|
+
*/
|
|
24
|
+
const ATTR_BROWSER_LANGUAGE = "browser.language";
|
|
25
|
+
/**
|
|
26
|
+
* A boolean that is true if the browser is running on a mobile device
|
|
27
|
+
*
|
|
28
|
+
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.mobile`). If unavailable, this attribute **SHOULD** be left unset.
|
|
29
|
+
*
|
|
30
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
31
|
+
*/
|
|
32
|
+
const ATTR_BROWSER_MOBILE = "browser.mobile";
|
|
33
|
+
/**
|
|
34
|
+
* The platform on which the browser is running
|
|
35
|
+
*
|
|
36
|
+
* @example Windows
|
|
37
|
+
* @example macOS
|
|
38
|
+
* @example Android
|
|
39
|
+
*
|
|
40
|
+
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.platform`). If unavailable, the legacy `navigator.platform` API **SHOULD NOT** be used instead and this attribute **SHOULD** be left unset in order for the values to be consistent.
|
|
41
|
+
* The list of possible values is defined in the [W3C User-Agent Client Hints specification](https://wicg.github.io/ua-client-hints/#sec-ch-ua-platform). Note that some (but not all) of these values can overlap with values in the [`os.type` and `os.name` attributes](./os.md). However, for consistency, the values in the `browser.platform` attribute should capture the exact value that the user agent provides.
|
|
42
|
+
*
|
|
43
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
44
|
+
*/
|
|
45
|
+
const ATTR_BROWSER_PLATFORM = "browser.platform";
|
|
46
|
+
//#endregion
|
|
47
|
+
export { ATTR_BROWSER_BRANDS, ATTR_BROWSER_LANGUAGE, ATTR_BROWSER_MOBILE, ATTR_BROWSER_PLATFORM };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=semconv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semconv.mjs","names":[],"sources":["../src/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * Array of brand name and version separated by a space\n *\n * @example [\" Not A;Brand 99\", \"Chromium 99\", \"Chrome 99\"]\n *\n * @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.brands`).\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_BRANDS = 'browser.brands' as const;\n\n/**\n * Preferred language of the user using the browser\n *\n * @example en\n * @example en-US\n * @example fr\n * @example fr-FR\n *\n * @note This value is intended to be taken from the Navigator API `navigator.language`.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_LANGUAGE = 'browser.language' as const;\n\n/**\n * A boolean that is true if the browser is running on a mobile device\n *\n * @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.mobile`). If unavailable, this attribute **SHOULD** be left unset.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_MOBILE = 'browser.mobile' as const;\n\n/**\n * The platform on which the browser is running\n *\n * @example Windows\n * @example macOS\n * @example Android\n *\n * @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.platform`). If unavailable, the legacy `navigator.platform` API **SHOULD NOT** be used instead and this attribute **SHOULD** be left unset in order for the values to be consistent.\n * The list of possible values is defined in the [W3C User-Agent Client Hints specification](https://wicg.github.io/ua-client-hints/#sec-ch-ua-platform). Note that some (but not all) of these values can overlap with values in the [`os.type` and `os.name` attributes](./os.md). However, for consistency, the values in the `browser.platform` attribute should capture the exact value that the user agent provides.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_BROWSER_PLATFORM = 'browser.platform' as const;\n"],"mappings":";;;;;;;;;;AAcA,MAAa,sBAAsB;;;;;;;;;;;;;AAcnC,MAAa,wBAAwB;;;;;;;;AASrC,MAAa,sBAAsB;;;;;;;;;;;;;AAcnC,MAAa,wBAAwB"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/opentelemetry-browser-detector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.300.0-development.0",
|
|
4
4
|
"description": "OpenTelemetry Resource Detector for Browser",
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.cts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
9
20
|
"repository": "open-telemetry/opentelemetry-js",
|
|
10
21
|
"scripts": {
|
|
11
22
|
"prepublishOnly": "npm run compile",
|
|
12
|
-
"compile": "
|
|
13
|
-
"clean": "
|
|
23
|
+
"compile": "tsdown",
|
|
24
|
+
"clean": "rimraf dist build",
|
|
14
25
|
"lint": "eslint .",
|
|
15
26
|
"lint:fix": "eslint . --fix",
|
|
16
27
|
"test": "nyc mocha 'test/**/*.test.ts'",
|
|
@@ -18,10 +29,9 @@
|
|
|
18
29
|
"tdd": "npm run test -- --watch-extensions ts --watch",
|
|
19
30
|
"tdd:browser": "karma start",
|
|
20
31
|
"version": "node ../../../scripts/version-update.js",
|
|
21
|
-
"watch": "
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"align-api-deps": "node ../../../scripts/align-api-deps.js"
|
|
32
|
+
"watch": "tsdown --watch --no-clean",
|
|
33
|
+
"peer-api-check": "node ../../../scripts/peer-api-check.mjs",
|
|
34
|
+
"align-api-deps": "node ../../../scripts/align-api-deps.mjs"
|
|
25
35
|
},
|
|
26
36
|
"keywords": [
|
|
27
37
|
"opentelemetry",
|
|
@@ -32,21 +42,13 @@
|
|
|
32
42
|
"author": "OpenTelemetry Authors",
|
|
33
43
|
"license": "Apache-2.0",
|
|
34
44
|
"engines": {
|
|
35
|
-
"node": "
|
|
45
|
+
"node": ">=22.15.0"
|
|
36
46
|
},
|
|
37
47
|
"files": [
|
|
38
|
-
"build/esm/**/*.js",
|
|
39
|
-
"build/esm/**/*.js.map",
|
|
40
|
-
"build/esm/**/*.d.ts",
|
|
41
|
-
"build/esnext/**/*.js",
|
|
42
|
-
"build/esnext/**/*.js.map",
|
|
43
|
-
"build/esnext/**/*.d.ts",
|
|
44
|
-
"build/src/**/*.js",
|
|
45
|
-
"build/src/**/*.js.map",
|
|
46
|
-
"build/src/**/*.d.ts",
|
|
47
48
|
"doc",
|
|
48
49
|
"LICENSE",
|
|
49
|
-
"README.md"
|
|
50
|
+
"README.md",
|
|
51
|
+
"dist"
|
|
50
52
|
],
|
|
51
53
|
"publishConfig": {
|
|
52
54
|
"access": "public"
|
|
@@ -63,7 +65,7 @@
|
|
|
63
65
|
"karma-chrome-launcher": "3.2.0",
|
|
64
66
|
"karma-coverage": "2.2.1",
|
|
65
67
|
"karma-mocha": "2.0.1",
|
|
66
|
-
"karma-spec-reporter": "0.0.
|
|
68
|
+
"karma-spec-reporter": "0.0.37",
|
|
67
69
|
"karma-webpack": "5.0.1",
|
|
68
70
|
"mocha": "11.8.0",
|
|
69
71
|
"nyc": "17.1.0",
|
|
@@ -71,15 +73,15 @@
|
|
|
71
73
|
"ts-loader": "9.5.7",
|
|
72
74
|
"typescript": "5.2.2",
|
|
73
75
|
"webpack": "5.108.4",
|
|
74
|
-
"webpack-cli": "7.2.
|
|
76
|
+
"webpack-cli": "7.2.3"
|
|
75
77
|
},
|
|
76
78
|
"peerDependencies": {
|
|
77
79
|
"@opentelemetry/api": "^1.3.0"
|
|
78
80
|
},
|
|
79
81
|
"dependencies": {
|
|
80
|
-
"@opentelemetry/resources": "
|
|
82
|
+
"@opentelemetry/resources": "3.0.0-development.0",
|
|
81
83
|
"@opentelemetry/semantic-conventions": "^1.29.0"
|
|
82
84
|
},
|
|
83
85
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/browser-detector",
|
|
84
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "ad3499bf70ee996f5565e5cd00f2c5fcb2e87042"
|
|
85
87
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { DetectedResource, ResourceDetector, ResourceDetectionConfig } from '@opentelemetry/resources';
|
|
2
|
-
/**
|
|
3
|
-
* BrowserDetector will be used to detect the resources related to browser.
|
|
4
|
-
*/
|
|
5
|
-
declare class BrowserDetector implements ResourceDetector {
|
|
6
|
-
detect(config?: ResourceDetectionConfig): DetectedResource;
|
|
7
|
-
/**
|
|
8
|
-
* Validates browser resource attribute map from browser variables
|
|
9
|
-
*
|
|
10
|
-
* @param browserResource The un-sanitized resource attributes from browser as key/value pairs.
|
|
11
|
-
* @param config: Config
|
|
12
|
-
* @returns The sanitized resource attributes.
|
|
13
|
-
*/
|
|
14
|
-
private _getResourceAttributes;
|
|
15
|
-
}
|
|
16
|
-
export declare const browserDetector: BrowserDetector;
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=BrowserDetector.d.ts.map
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright The OpenTelemetry Authors
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { diag } from '@opentelemetry/api';
|
|
6
|
-
import { emptyResource } from '@opentelemetry/resources';
|
|
7
|
-
import { ATTR_USER_AGENT_ORIGINAL } from '@opentelemetry/semantic-conventions';
|
|
8
|
-
import { ATTR_BROWSER_LANGUAGE, ATTR_BROWSER_PLATFORM, ATTR_BROWSER_BRANDS, ATTR_BROWSER_MOBILE, } from './semconv';
|
|
9
|
-
/**
|
|
10
|
-
* BrowserDetector will be used to detect the resources related to browser.
|
|
11
|
-
*/
|
|
12
|
-
class BrowserDetector {
|
|
13
|
-
detect(config) {
|
|
14
|
-
const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
15
|
-
if (!isBrowser) {
|
|
16
|
-
return emptyResource();
|
|
17
|
-
}
|
|
18
|
-
const browserResource = getBrowserAttributes();
|
|
19
|
-
return this._getResourceAttributes(browserResource, config);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Validates browser resource attribute map from browser variables
|
|
23
|
-
*
|
|
24
|
-
* @param browserResource The un-sanitized resource attributes from browser as key/value pairs.
|
|
25
|
-
* @param config: Config
|
|
26
|
-
* @returns The sanitized resource attributes.
|
|
27
|
-
*/
|
|
28
|
-
_getResourceAttributes(browserResource, _config) {
|
|
29
|
-
if (!browserResource[ATTR_USER_AGENT_ORIGINAL] &&
|
|
30
|
-
!browserResource[ATTR_BROWSER_PLATFORM]) {
|
|
31
|
-
diag.debug('BrowserDetector failed: Unable to find required browser resources. ');
|
|
32
|
-
return emptyResource();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return { attributes: browserResource };
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Add Browser related attributes to resources
|
|
40
|
-
function getBrowserAttributes() {
|
|
41
|
-
const browserAttribs = {};
|
|
42
|
-
const userAgentData = navigator.userAgentData;
|
|
43
|
-
if (userAgentData) {
|
|
44
|
-
browserAttribs[ATTR_BROWSER_PLATFORM] = userAgentData.platform;
|
|
45
|
-
browserAttribs[ATTR_BROWSER_BRANDS] = userAgentData.brands.map(b => `${b.brand} ${b.version}`);
|
|
46
|
-
browserAttribs[ATTR_BROWSER_MOBILE] = userAgentData.mobile;
|
|
47
|
-
}
|
|
48
|
-
browserAttribs[ATTR_USER_AGENT_ORIGINAL] = navigator.userAgent;
|
|
49
|
-
browserAttribs[ATTR_BROWSER_LANGUAGE] = navigator.language;
|
|
50
|
-
return browserAttribs;
|
|
51
|
-
}
|
|
52
|
-
export const browserDetector = new BrowserDetector();
|
|
53
|
-
//# sourceMappingURL=BrowserDetector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserDetector.js","sourceRoot":"","sources":["../../src/BrowserDetector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAM1C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAE/E,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AAEnB;;GAEG;AACH,MAAM,eAAe;IACnB,MAAM,CAAC,MAAgC;QACrC,MAAM,SAAS,GACb,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,CAAC;QAEnE,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,aAAa,EAAE,CAAC;SACxB;QACD,MAAM,eAAe,GAAe,oBAAoB,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC,sBAAsB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD;;;;;;OAMG;IACK,sBAAsB,CAC5B,eAA2B,EAC3B,OAAiC;QAEjC,IACE,CAAC,eAAe,CAAC,wBAAwB,CAAC;YAC1C,CAAC,eAAe,CAAC,qBAAqB,CAAC,EACvC;YACA,IAAI,CAAC,KAAK,CACR,qEAAqE,CACtE,CAAC;YACF,OAAO,aAAa,EAAE,CAAC;SACxB;aAAM;YACL,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;SACxC;IACH,CAAC;CACF;AAED,8CAA8C;AAC9C,SAAS,oBAAoB;IAC3B,MAAM,cAAc,GAAe,EAAE,CAAC;IACtC,MAAM,aAAa,GACjB,SACD,CAAC,aAAa,CAAC;IAChB,IAAI,aAAa,EAAE;QACjB,cAAc,CAAC,qBAAqB,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC;QAC/D,cAAc,CAAC,mBAAmB,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,CAC5D,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAC/B,CAAC;QACF,cAAc,CAAC,mBAAmB,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC;KAC5D;IACD,cAAc,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC;IAC/D,cAAc,CAAC,qBAAqB,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC;IAC3D,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\nimport type {\n DetectedResource,\n ResourceDetector,\n ResourceDetectionConfig,\n} from '@opentelemetry/resources';\nimport { emptyResource } from '@opentelemetry/resources';\nimport { ATTR_USER_AGENT_ORIGINAL } from '@opentelemetry/semantic-conventions';\nimport type { UserAgentData } from './types';\nimport {\n ATTR_BROWSER_LANGUAGE,\n ATTR_BROWSER_PLATFORM,\n ATTR_BROWSER_BRANDS,\n ATTR_BROWSER_MOBILE,\n} from './semconv';\n\n/**\n * BrowserDetector will be used to detect the resources related to browser.\n */\nclass BrowserDetector implements ResourceDetector {\n detect(config?: ResourceDetectionConfig): DetectedResource {\n const isBrowser =\n typeof window !== 'undefined' && typeof document !== 'undefined';\n\n if (!isBrowser) {\n return emptyResource();\n }\n const browserResource: Attributes = getBrowserAttributes();\n return this._getResourceAttributes(browserResource, config);\n }\n /**\n * Validates browser resource attribute map from browser variables\n *\n * @param browserResource The un-sanitized resource attributes from browser as key/value pairs.\n * @param config: Config\n * @returns The sanitized resource attributes.\n */\n private _getResourceAttributes(\n browserResource: Attributes,\n _config?: ResourceDetectionConfig\n ): DetectedResource {\n if (\n !browserResource[ATTR_USER_AGENT_ORIGINAL] &&\n !browserResource[ATTR_BROWSER_PLATFORM]\n ) {\n diag.debug(\n 'BrowserDetector failed: Unable to find required browser resources. '\n );\n return emptyResource();\n } else {\n return { attributes: browserResource };\n }\n }\n}\n\n// Add Browser related attributes to resources\nfunction getBrowserAttributes(): Attributes {\n const browserAttribs: Attributes = {};\n const userAgentData = (\n navigator as Navigator & { userAgentData?: UserAgentData }\n ).userAgentData;\n if (userAgentData) {\n browserAttribs[ATTR_BROWSER_PLATFORM] = userAgentData.platform;\n browserAttribs[ATTR_BROWSER_BRANDS] = userAgentData.brands.map(\n b => `${b.brand} ${b.version}`\n );\n browserAttribs[ATTR_BROWSER_MOBILE] = userAgentData.mobile;\n }\n browserAttribs[ATTR_USER_AGENT_ORIGINAL] = navigator.userAgent;\n browserAttribs[ATTR_BROWSER_LANGUAGE] = navigator.language;\n return browserAttribs;\n}\n\nexport const browserDetector = new BrowserDetector();\n"]}
|
package/build/esm/index.d.ts
DELETED
package/build/esm/index.js
DELETED
package/build/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport { browserDetector } from './BrowserDetector';\n"]}
|
package/build/esm/semconv.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Array of brand name and version separated by a space
|
|
3
|
-
*
|
|
4
|
-
* @example [" Not A;Brand 99", "Chromium 99", "Chrome 99"]
|
|
5
|
-
*
|
|
6
|
-
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.brands`).
|
|
7
|
-
*
|
|
8
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
9
|
-
*/
|
|
10
|
-
export declare const ATTR_BROWSER_BRANDS: "browser.brands";
|
|
11
|
-
/**
|
|
12
|
-
* Preferred language of the user using the browser
|
|
13
|
-
*
|
|
14
|
-
* @example en
|
|
15
|
-
* @example en-US
|
|
16
|
-
* @example fr
|
|
17
|
-
* @example fr-FR
|
|
18
|
-
*
|
|
19
|
-
* @note This value is intended to be taken from the Navigator API `navigator.language`.
|
|
20
|
-
*
|
|
21
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
22
|
-
*/
|
|
23
|
-
export declare const ATTR_BROWSER_LANGUAGE: "browser.language";
|
|
24
|
-
/**
|
|
25
|
-
* A boolean that is true if the browser is running on a mobile device
|
|
26
|
-
*
|
|
27
|
-
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.mobile`). If unavailable, this attribute **SHOULD** be left unset.
|
|
28
|
-
*
|
|
29
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
30
|
-
*/
|
|
31
|
-
export declare const ATTR_BROWSER_MOBILE: "browser.mobile";
|
|
32
|
-
/**
|
|
33
|
-
* The platform on which the browser is running
|
|
34
|
-
*
|
|
35
|
-
* @example Windows
|
|
36
|
-
* @example macOS
|
|
37
|
-
* @example Android
|
|
38
|
-
*
|
|
39
|
-
* @note This value is intended to be taken from the [UA client hints API](https://wicg.github.io/ua-client-hints/#interface) (`navigator.userAgentData.platform`). If unavailable, the legacy `navigator.platform` API **SHOULD NOT** be used instead and this attribute **SHOULD** be left unset in order for the values to be consistent.
|
|
40
|
-
* The list of possible values is defined in the [W3C User-Agent Client Hints specification](https://wicg.github.io/ua-client-hints/#sec-ch-ua-platform). Note that some (but not all) of these values can overlap with values in the [`os.type` and `os.name` attributes](./os.md). However, for consistency, the values in the `browser.platform` attribute should capture the exact value that the user agent provides.
|
|
41
|
-
*
|
|
42
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
43
|
-
*/
|
|
44
|
-
export declare const ATTR_BROWSER_PLATFORM: "browser.platform";
|
|
45
|
-
//# sourceMappingURL=semconv.d.ts.map
|