@elastic/opentelemetry-browser 0.1.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/CHANGELOG.md +6 -0
- package/LICENSE +202 -0
- package/NOTICE.md +5765 -0
- package/README.md +22 -0
- package/build/elastic-otel-browser.js +11593 -0
- package/build/elastic-otel-browser.js.map +7 -0
- package/build/elastic-otel-browser.min.js +14 -0
- package/build/elastic-otel-browser.min.js.map +7 -0
- package/lib/bundle.js +8 -0
- package/lib/context.js +347 -0
- package/lib/detector.js +226 -0
- package/lib/index.js +6 -0
- package/lib/logging.js +67 -0
- package/lib/sdk.js +232 -0
- package/lib/semconv.js +68 -0
- package/lib/version.js +6 -0
- package/package.json +81 -0
- package/types/bundle.d.ts +1 -0
- package/types/context.d.ts +2 -0
- package/types/detector.d.ts +47 -0
- package/types/index.d.ts +1 -0
- package/types/logging.d.ts +9 -0
- package/types/sdk.d.ts +32 -0
- package/types/semconv.d.ts +58 -0
- package/types/version.d.ts +1 -0
package/lib/sdk.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and contributors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {diag, DiagLogLevel, metrics} from '@opentelemetry/api';
|
|
7
|
+
import {logs} from '@opentelemetry/api-logs';
|
|
8
|
+
import {OTLPLogExporter} from '@opentelemetry/exporter-logs-otlp-http';
|
|
9
|
+
import {OTLPMetricExporter} from '@opentelemetry/exporter-metrics-otlp-http';
|
|
10
|
+
import {OTLPTraceExporter} from '@opentelemetry/exporter-trace-otlp-http';
|
|
11
|
+
import {BatchLogRecordProcessor, LoggerProvider} from '@opentelemetry/sdk-logs';
|
|
12
|
+
import {
|
|
13
|
+
MeterProvider,
|
|
14
|
+
PeriodicExportingMetricReader,
|
|
15
|
+
} from '@opentelemetry/sdk-metrics';
|
|
16
|
+
import {
|
|
17
|
+
BatchSpanProcessor,
|
|
18
|
+
TraceIdRatioBasedSampler,
|
|
19
|
+
} from '@opentelemetry/sdk-trace-base';
|
|
20
|
+
import {WebTracerProvider} from '@opentelemetry/sdk-trace-web';
|
|
21
|
+
|
|
22
|
+
import {registerInstrumentations} from '@opentelemetry/instrumentation';
|
|
23
|
+
import {DocumentLoadInstrumentation} from '@opentelemetry/instrumentation-document-load';
|
|
24
|
+
import {FetchInstrumentation} from '@opentelemetry/instrumentation-fetch';
|
|
25
|
+
import {LongTaskInstrumentation} from '@opentelemetry/instrumentation-long-task';
|
|
26
|
+
import {UserInteractionInstrumentation} from '@opentelemetry/instrumentation-user-interaction';
|
|
27
|
+
import {XMLHttpRequestInstrumentation} from '@opentelemetry/instrumentation-xml-http-request';
|
|
28
|
+
import {ExceptionInstrumentation} from '@opentelemetry/instrumentation-web-exception';
|
|
29
|
+
import {WebVitalsInstrumentation} from '@opentelemetry/browser-instrumentation/experimental/web-vitals';
|
|
30
|
+
|
|
31
|
+
import {AsyncApisContextManager} from './context.js';
|
|
32
|
+
import {createLogger} from './logging.js';
|
|
33
|
+
import {detectResource} from './detector.js';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {{
|
|
37
|
+
* "@opentelemetry/instrumentation-document-load": import('@opentelemetry/instrumentation-document-load').DocumentLoadInstrumentationConfig;
|
|
38
|
+
* "@opentelemetry/instrumentation-fetch": import('@opentelemetry/instrumentation-fetch').FetchInstrumentationConfig;
|
|
39
|
+
* "@opentelemetry/instrumentation-long-task": import('@opentelemetry/instrumentation-long-task').LongtaskInstrumentationConfig;
|
|
40
|
+
* "@opentelemetry/instrumentation-user-interaction": import('@opentelemetry/instrumentation-user-interaction').UserInteractionInstrumentationConfig;
|
|
41
|
+
* "@opentelemetry/instrumentation-xml-http-request": import('@opentelemetry/instrumentation-xml-http-request').XMLHttpRequestInstrumentationConfig;
|
|
42
|
+
* "@opentelemetry/instrumentation-web-exception": import('@opentelemetry/instrumentation-web-exception').GlobalErrorsInstrumentationConfig;
|
|
43
|
+
* "@opentelemetry/instrumentation-web-vitals": import('@opentelemetry/browser-instrumentation/experimental/web-vitals').WebVitalsInstrumentationConfig;
|
|
44
|
+
* }} InstrumentationsConfigMap
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {Object} BrowserSdkConfiguration
|
|
49
|
+
* @property {boolean} [disabled]
|
|
50
|
+
* @property {string} [serviceName]
|
|
51
|
+
* @property {string} [serviceVersion]
|
|
52
|
+
* @property {string} [logLevel] // defaults to 'info'
|
|
53
|
+
* @property {number} [sampleRate] // defaults to 1
|
|
54
|
+
* @property {Record<string, import('./detector.js').AttributeValue>} [resourceAttributes]
|
|
55
|
+
* @property {string} [otlpEndpoint] // defaults to 'http://localhost:4318'
|
|
56
|
+
* @property {Record<string, string>} [exportHeaders] // defaults to {}
|
|
57
|
+
*
|
|
58
|
+
* // other options
|
|
59
|
+
* @property {Partial<InstrumentationsConfigMap>} [instrumentations]
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
// To control multiple calls to `startBrowserSdk`
|
|
63
|
+
let sdkStarted = false;
|
|
64
|
+
|
|
65
|
+
/** @type {BrowserSdkConfiguration} */
|
|
66
|
+
const defaultConfig = {
|
|
67
|
+
logLevel: 'info',
|
|
68
|
+
sampleRate: 1,
|
|
69
|
+
serviceName: 'unknown_service:web',
|
|
70
|
+
resourceAttributes: {},
|
|
71
|
+
otlpEndpoint: 'http://localhost:4318',
|
|
72
|
+
exportHeaders: {},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {BrowserSdkConfiguration} cfg
|
|
77
|
+
* @returns {{
|
|
78
|
+
* forceFlush: () => Promise<void>
|
|
79
|
+
* }}
|
|
80
|
+
*/
|
|
81
|
+
export function startBrowserSdk(cfg = {}) {
|
|
82
|
+
if (sdkStarted || cfg.disabled) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const logLevel = cfg.logLevel ?? defaultConfig.logLevel;
|
|
87
|
+
diag.setLogger(createLogger({logLevel}), {logLevel: DiagLogLevel.ALL});
|
|
88
|
+
diag.debug(`Browser SDK intialization`, cfg);
|
|
89
|
+
|
|
90
|
+
const {serviceName, serviceVersion} = cfg;
|
|
91
|
+
const config = {...defaultConfig, ...cfg};
|
|
92
|
+
|
|
93
|
+
// Input validation
|
|
94
|
+
/** @type {URL} */
|
|
95
|
+
let endpointUrl;
|
|
96
|
+
try {
|
|
97
|
+
endpointUrl = new URL(config.otlpEndpoint);
|
|
98
|
+
} catch (urlErr) {
|
|
99
|
+
diag.error(
|
|
100
|
+
`The value "${config.otlpEndpoint}" for "otlpEndpoint" configuration is not an URL. SDK won't start.`
|
|
101
|
+
);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Detect resource
|
|
106
|
+
const resource = detectResource(
|
|
107
|
+
config.resourceAttributes,
|
|
108
|
+
serviceName,
|
|
109
|
+
serviceVersion
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// NOTE: export payloads can be seen in DevTools network tab in JSON format
|
|
113
|
+
// so IMHO it would be redundant to use console exporters
|
|
114
|
+
|
|
115
|
+
// traces signal configuration
|
|
116
|
+
const tracesEndpoint = appendPath(endpointUrl, 'v1/traces').href;
|
|
117
|
+
const spanProcessor = new BatchSpanProcessor(
|
|
118
|
+
new OTLPTraceExporter({
|
|
119
|
+
url: tracesEndpoint,
|
|
120
|
+
headers: config.exportHeaders,
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
const tracerProvider = new WebTracerProvider({
|
|
124
|
+
resource,
|
|
125
|
+
sampler: new TraceIdRatioBasedSampler(config.sampleRate),
|
|
126
|
+
spanProcessors: [spanProcessor],
|
|
127
|
+
});
|
|
128
|
+
// TODO: WebTracerProvider comes with
|
|
129
|
+
// - a composite propagator [W3C, Baggage]
|
|
130
|
+
// - a context manager (Stack, which has issues with exporters)
|
|
131
|
+
// Should we allow users to pass their own propagator, contextmanager?
|
|
132
|
+
tracerProvider.register({
|
|
133
|
+
contextManager: AsyncApisContextManager,
|
|
134
|
+
});
|
|
135
|
+
// ideally it shoud be
|
|
136
|
+
// trace.setGlobalTracerProvider(tracerProvider);
|
|
137
|
+
// but there is no way to set propagators and context manager
|
|
138
|
+
|
|
139
|
+
// metrics signal configuration
|
|
140
|
+
const metricsEndpoint = appendPath(endpointUrl, 'v1/metrics').href;
|
|
141
|
+
const metricsReader = new PeriodicExportingMetricReader({
|
|
142
|
+
exporter: new OTLPMetricExporter({
|
|
143
|
+
url: metricsEndpoint,
|
|
144
|
+
headers: config.exportHeaders,
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
const meterProvider = new MeterProvider({
|
|
148
|
+
resource,
|
|
149
|
+
readers: [metricsReader],
|
|
150
|
+
});
|
|
151
|
+
metrics.setGlobalMeterProvider(meterProvider);
|
|
152
|
+
|
|
153
|
+
// logs signal configuration
|
|
154
|
+
const logsEndpoint = appendPath(endpointUrl, 'v1/logs').href;
|
|
155
|
+
const logsProcessor = new BatchLogRecordProcessor(
|
|
156
|
+
new OTLPLogExporter({
|
|
157
|
+
url: logsEndpoint,
|
|
158
|
+
headers: config.exportHeaders,
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
const loggerProvider = new LoggerProvider({
|
|
162
|
+
resource,
|
|
163
|
+
processors: [logsProcessor],
|
|
164
|
+
});
|
|
165
|
+
logs.setGlobalLoggerProvider(loggerProvider);
|
|
166
|
+
|
|
167
|
+
// Resgister instrumentations. The `registerInstrumentations` enabled all of them
|
|
168
|
+
// regardless of the configuration so EDOT only add the ones that are not disabled
|
|
169
|
+
// by configuration
|
|
170
|
+
/** @type {Record<keyof InstrumentationsConfigMap, (cfg: any) => any>} */
|
|
171
|
+
const instrFactories = {
|
|
172
|
+
'@opentelemetry/instrumentation-document-load': (cfg) =>
|
|
173
|
+
new DocumentLoadInstrumentation(cfg),
|
|
174
|
+
'@opentelemetry/instrumentation-fetch': (cfg) =>
|
|
175
|
+
new FetchInstrumentation(cfg),
|
|
176
|
+
'@opentelemetry/instrumentation-long-task': (cfg) =>
|
|
177
|
+
new LongTaskInstrumentation(cfg),
|
|
178
|
+
'@opentelemetry/instrumentation-user-interaction': (cfg) =>
|
|
179
|
+
new UserInteractionInstrumentation(cfg),
|
|
180
|
+
'@opentelemetry/instrumentation-xml-http-request': (cfg) =>
|
|
181
|
+
new XMLHttpRequestInstrumentation(cfg),
|
|
182
|
+
'@opentelemetry/instrumentation-web-exception': (cfg) =>
|
|
183
|
+
new ExceptionInstrumentation(cfg),
|
|
184
|
+
'@opentelemetry/instrumentation-web-vitals': (cfg) =>
|
|
185
|
+
new WebVitalsInstrumentation(cfg),
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const httpSemconvConfig = {semconvStabilityOptIn: 'http'};
|
|
189
|
+
const instrumentations = config.instrumentations || {};
|
|
190
|
+
const enabledInstrumentations = [];
|
|
191
|
+
for (const key of Object.keys(instrFactories)) {
|
|
192
|
+
let instrConfig = instrumentations[key];
|
|
193
|
+
if (
|
|
194
|
+
key === '@opentelemetry/instrumentation-fetch' ||
|
|
195
|
+
key === '@opentelemetry/instrumentation-xml-http-request'
|
|
196
|
+
) {
|
|
197
|
+
instrConfig = {...httpSemconvConfig, ...instrConfig};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const isDisabled = instrConfig?.enabled === false;
|
|
201
|
+
if (!isDisabled) {
|
|
202
|
+
enabledInstrumentations.push(instrFactories[key](instrConfig));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
registerInstrumentations({instrumentations: enabledInstrumentations});
|
|
206
|
+
|
|
207
|
+
// Flag as started
|
|
208
|
+
sdkStarted = true;
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
forceFlush() {
|
|
212
|
+
return Promise.all([
|
|
213
|
+
tracerProvider.forceFlush(),
|
|
214
|
+
meterProvider.forceFlush(),
|
|
215
|
+
loggerProvider.forceFlush(),
|
|
216
|
+
]).then(() => {});
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// -- helper functions
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Returns a new URL with the path appended. Avoiding double slash
|
|
225
|
+
* @param {URL} url
|
|
226
|
+
* @param {string} path
|
|
227
|
+
*/
|
|
228
|
+
function appendPath(url, path) {
|
|
229
|
+
const result = new URL(url.href);
|
|
230
|
+
result.pathname = (result.pathname + path).replace('//', '/');
|
|
231
|
+
return result;
|
|
232
|
+
}
|
package/lib/semconv.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and contributors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Array of brand name and version separated by a space
|
|
8
|
+
*
|
|
9
|
+
* @example [" Not A;Brand 99", "Chromium 99", "Chrome 99"]
|
|
10
|
+
*
|
|
11
|
+
* @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`).
|
|
12
|
+
*
|
|
13
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
14
|
+
*/
|
|
15
|
+
export const ATTR_BROWSER_BRANDS = 'browser.brands';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Preferred language of the user using the browser
|
|
19
|
+
*
|
|
20
|
+
* @example en
|
|
21
|
+
* @example en-US
|
|
22
|
+
* @example fr
|
|
23
|
+
* @example fr-FR
|
|
24
|
+
*
|
|
25
|
+
* @note This value is intended to be taken from the Navigator API `navigator.language`.
|
|
26
|
+
*
|
|
27
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
28
|
+
*/
|
|
29
|
+
export const ATTR_BROWSER_LANGUAGE = 'browser.language';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A boolean that is true if the browser is running on a mobile device
|
|
33
|
+
*
|
|
34
|
+
* @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.
|
|
35
|
+
*
|
|
36
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
37
|
+
*/
|
|
38
|
+
export const ATTR_BROWSER_MOBILE = 'browser.mobile';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The platform on which the browser is running
|
|
42
|
+
*
|
|
43
|
+
* @example Windows
|
|
44
|
+
* @example macOS
|
|
45
|
+
* @example Android
|
|
46
|
+
*
|
|
47
|
+
* @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.
|
|
48
|
+
* 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.
|
|
49
|
+
*
|
|
50
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
51
|
+
*/
|
|
52
|
+
export const ATTR_BROWSER_PLATFORM = 'browser.platform';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* This event describes the website performance metrics introduced by Google, See [web vitals](https://web.dev/vitals).
|
|
56
|
+
*
|
|
57
|
+
* @experimental This event is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
58
|
+
*/
|
|
59
|
+
export const EVENT_BROWSER_WEB_VITAL = 'browser.web_vital';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Value of the [HTTP User-Agent](https://www.rfc-editor.org/rfc/rfc9110.html#field.user-agent) header sent by the client.
|
|
63
|
+
*
|
|
64
|
+
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
65
|
+
* @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
|
|
66
|
+
* @example YourApp/1.0.0 grpc-java-okhttp/1.27.2
|
|
67
|
+
*/
|
|
68
|
+
export const ATTR_USER_AGENT_ORIGINAL = 'user_agent.original';
|
package/lib/version.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elastic/opentelemetry-browser",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"provenance": true
|
|
8
|
+
},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/elastic/elastic-otel-rum-js.git",
|
|
13
|
+
"directory": "packages/opentelemetry-browser"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"opentelemetry",
|
|
17
|
+
"telemetry",
|
|
18
|
+
"apm",
|
|
19
|
+
"tracing",
|
|
20
|
+
"metrics",
|
|
21
|
+
"logs",
|
|
22
|
+
"rum",
|
|
23
|
+
"browser"
|
|
24
|
+
],
|
|
25
|
+
"author": "Elastic Observability <https://www.elastic.co/observability>",
|
|
26
|
+
"files": [
|
|
27
|
+
"build",
|
|
28
|
+
"lib",
|
|
29
|
+
"types",
|
|
30
|
+
"CHANGELOG.md",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"NOTICE.md",
|
|
33
|
+
"README.md",
|
|
34
|
+
"package.json"
|
|
35
|
+
],
|
|
36
|
+
"main": "./lib/index.js",
|
|
37
|
+
"types": "./types/index.d.ts",
|
|
38
|
+
"scripts": {
|
|
39
|
+
"prepublishOnly": "npm run build",
|
|
40
|
+
"clean": "rm -rf build",
|
|
41
|
+
"build:version": "CODE=\"export const EDOT_VERSION = '$(npx json -f package.json version)';\"; awk -v code=\"$CODE\" '/^export/ { print code; next } { print }' lib/version.js > tmp && mv tmp lib/version.js",
|
|
42
|
+
"build:iife": "esbuild ./lib/bundle.js --bundle --conditions=esnext,module --sourcemap --platform=browser --target=es2022 --outfile=build/elastic-otel-browser.js",
|
|
43
|
+
"build:min": "esbuild ./lib/bundle.js --bundle --conditions=esnext,module --minify --sourcemap --platform=browser --target=es2022 --outfile=build/elastic-otel-browser.min.js",
|
|
44
|
+
"build": "npm run clean && npm run build:version && npm run build:iife && npm run build:min",
|
|
45
|
+
"gen:types": "rm -rf types && tsc # TODO: would be nice to tree-shake the *.d.ts files",
|
|
46
|
+
"lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:licenses && npm run lint:version && npm run lint:types",
|
|
47
|
+
"lint:eslint": "eslint .",
|
|
48
|
+
"lint:prettier": "(cd ../../; prettier --check $npm_config_local_prefix)",
|
|
49
|
+
"lint:licenses": "../../scripts/gen-notice.sh --lint .",
|
|
50
|
+
"lint:version": "EDOT_VERSION=$(npx json -f package.json version); grep -Fq \"$EDOT_VERSION\" lib/version.js || { echo \"::error::Version $EDOT_VERSION not set in lib/version.js\"; exit 1; }",
|
|
51
|
+
"lint:types": "rm -rf build/lint-types && tsc --outDir build/lint-types && diff -ur types build/lint-types && rm -rf build/lint-types",
|
|
52
|
+
"lint:fix": "eslint --fix . && (cd ../../; prettier --list-different --write $npm_config_local_prefix)",
|
|
53
|
+
"lint:ci": " npm run lint:licenses && npm run lint:version && npm run lint:types # eslint/prettier ran in repo root",
|
|
54
|
+
"test:smoke": "npm run build && cp build/* ./test/smoke/assets && playwright test",
|
|
55
|
+
"test:unit": "node --test test/unit/*.spec.js",
|
|
56
|
+
"test:bundle": "set -e; for d in ./test/bundle/*/; do (cd \"$d\" && npm run test:bundle); done"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@opentelemetry/api": "^1.9.0",
|
|
60
|
+
"@opentelemetry/api-logs": "^0.213.0",
|
|
61
|
+
"@opentelemetry/browser-instrumentation": "^0.1.0",
|
|
62
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.213.0",
|
|
63
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.213.0",
|
|
64
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
|
65
|
+
"@opentelemetry/instrumentation": "^0.213.0",
|
|
66
|
+
"@opentelemetry/instrumentation-document-load": "^0.58.0",
|
|
67
|
+
"@opentelemetry/instrumentation-fetch": "^0.213.0",
|
|
68
|
+
"@opentelemetry/instrumentation-long-task": "^0.57.0",
|
|
69
|
+
"@opentelemetry/instrumentation-user-interaction": "^0.57.0",
|
|
70
|
+
"@opentelemetry/instrumentation-web-exception": "^0.6.0",
|
|
71
|
+
"@opentelemetry/instrumentation-xml-http-request": "^0.213.0",
|
|
72
|
+
"@opentelemetry/resources": "^2.2.0",
|
|
73
|
+
"@opentelemetry/sdk-logs": "^0.213.0",
|
|
74
|
+
"@opentelemetry/sdk-metrics": "^2.2.0",
|
|
75
|
+
"@opentelemetry/sdk-trace-web": "^2.2.0"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@playwright/test": "^1.57.0",
|
|
79
|
+
"esbuild": "0.27.1"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} UserAgentData
|
|
3
|
+
* @property {{brand: string; version: string}[]} brands
|
|
4
|
+
* @property {string} platform
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @template T
|
|
8
|
+
* @typedef {T | Array<T | undefined | null>} MaybeArray<T>
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {MaybeArray<number> | MaybeArray<boolean> | MaybeArray<string>} AttributeValue
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @param {Record<string, AttributeValue>} attribs
|
|
15
|
+
* @param {string | undefined} serviceName
|
|
16
|
+
* @param {string | undefined} serviceVersion
|
|
17
|
+
* @returns {import('@opentelemetry/resources').Resource}
|
|
18
|
+
*/
|
|
19
|
+
export function detectResource(attribs: Record<string, AttributeValue>, serviceName: string | undefined, serviceVersion: string | undefined): import('@opentelemetry/resources').Resource;
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} userAgent
|
|
22
|
+
* @returns {{name: string; version: string} | undefined}
|
|
23
|
+
*/
|
|
24
|
+
export function getPlatformInfo(userAgent: string): {
|
|
25
|
+
name: string;
|
|
26
|
+
version: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} userAgent
|
|
30
|
+
* @returns {{name: string; version: string | undefined} | undefined}
|
|
31
|
+
*/
|
|
32
|
+
export function getBrowserInfo(userAgent: string): {
|
|
33
|
+
name: string;
|
|
34
|
+
version: string | undefined;
|
|
35
|
+
} | undefined;
|
|
36
|
+
export type UserAgentData = {
|
|
37
|
+
brands: {
|
|
38
|
+
brand: string;
|
|
39
|
+
version: string;
|
|
40
|
+
}[];
|
|
41
|
+
platform: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* <T>
|
|
45
|
+
*/
|
|
46
|
+
export type MaybeArray<T> = T | Array<T | undefined | null>;
|
|
47
|
+
export type AttributeValue = MaybeArray<number> | MaybeArray<boolean> | MaybeArray<string>;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { startBrowserSdk } from "./sdk.js";
|
package/types/sdk.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {BrowserSdkConfiguration} cfg
|
|
3
|
+
* @returns {{
|
|
4
|
+
* forceFlush: () => Promise<void>
|
|
5
|
+
* }}
|
|
6
|
+
*/
|
|
7
|
+
export function startBrowserSdk(cfg?: BrowserSdkConfiguration): {
|
|
8
|
+
forceFlush: () => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export type InstrumentationsConfigMap = {
|
|
11
|
+
"@opentelemetry/instrumentation-document-load": import('@opentelemetry/instrumentation-document-load').DocumentLoadInstrumentationConfig;
|
|
12
|
+
"@opentelemetry/instrumentation-fetch": import('@opentelemetry/instrumentation-fetch').FetchInstrumentationConfig;
|
|
13
|
+
"@opentelemetry/instrumentation-long-task": import('@opentelemetry/instrumentation-long-task').LongtaskInstrumentationConfig;
|
|
14
|
+
"@opentelemetry/instrumentation-user-interaction": import('@opentelemetry/instrumentation-user-interaction').UserInteractionInstrumentationConfig;
|
|
15
|
+
"@opentelemetry/instrumentation-xml-http-request": import('@opentelemetry/instrumentation-xml-http-request').XMLHttpRequestInstrumentationConfig;
|
|
16
|
+
"@opentelemetry/instrumentation-web-exception": import('@opentelemetry/instrumentation-web-exception').GlobalErrorsInstrumentationConfig;
|
|
17
|
+
"@opentelemetry/instrumentation-web-vitals": import('@opentelemetry/browser-instrumentation/experimental/web-vitals').WebVitalsInstrumentationConfig;
|
|
18
|
+
};
|
|
19
|
+
export type BrowserSdkConfiguration = {
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
serviceName?: string;
|
|
22
|
+
serviceVersion?: string;
|
|
23
|
+
logLevel?: string;
|
|
24
|
+
sampleRate?: number;
|
|
25
|
+
resourceAttributes?: Record<string, import('./detector.js').AttributeValue>;
|
|
26
|
+
otlpEndpoint?: string;
|
|
27
|
+
/**
|
|
28
|
+
* // other options
|
|
29
|
+
*/
|
|
30
|
+
exportHeaders?: Record<string, string>;
|
|
31
|
+
instrumentations?: Partial<InstrumentationsConfigMap>;
|
|
32
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
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 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 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 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 const ATTR_BROWSER_PLATFORM: "browser.platform";
|
|
45
|
+
/**
|
|
46
|
+
* This event describes the website performance metrics introduced by Google, See [web vitals](https://web.dev/vitals).
|
|
47
|
+
*
|
|
48
|
+
* @experimental This event is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
49
|
+
*/
|
|
50
|
+
export const EVENT_BROWSER_WEB_VITAL: "browser.web_vital";
|
|
51
|
+
/**
|
|
52
|
+
* Value of the [HTTP User-Agent](https://www.rfc-editor.org/rfc/rfc9110.html#field.user-agent) header sent by the client.
|
|
53
|
+
*
|
|
54
|
+
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
55
|
+
* @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
|
|
56
|
+
* @example YourApp/1.0.0 grpc-java-okhttp/1.27.2
|
|
57
|
+
*/
|
|
58
|
+
export const ATTR_USER_AGENT_ORIGINAL: "user_agent.original";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const EDOT_VERSION: "0.1.0";
|