@opentelemetry/browser-instrumentation 0.4.0 → 0.5.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 CHANGED
@@ -18,6 +18,8 @@ npm install @opentelemetry/browser-instrumentation
18
18
  - [Resource Timing](#resource-timing) — automatic instrumentation for resource timing
19
19
  - [User Action](#user-action) — automatic instrumentation for user actions (clicks)
20
20
  - [Web Vitals](#web-vitals) — automatic instrumentation for Core Web Vitals
21
+ - [Console](#console) — automatic instrumentation for console API calls (log, warn, error, info, debug)
22
+ - [Errors](#errors) — automatic instrumentation for unhandled errors and promise rejections
21
23
 
22
24
  ## Usage
23
25
 
@@ -29,6 +31,7 @@ import {
29
31
  SimpleLogRecordProcessor,
30
32
  } from '@opentelemetry/sdk-logs';
31
33
  import { registerInstrumentations } from '@opentelemetry/instrumentation';
34
+ import { ErrorsInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/errors';
32
35
  import { NavigationInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/navigation';
33
36
  import { NavigationTimingInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/navigation-timing';
34
37
  import { ResourceTimingInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/resource-timing';
@@ -44,6 +47,7 @@ logs.setGlobalLoggerProvider(logProvider);
44
47
 
45
48
  registerInstrumentations({
46
49
  instrumentations: [
50
+ new ErrorsInstrumentation(),
47
51
  new NavigationInstrumentation(),
48
52
  new NavigationTimingInstrumentation(),
49
53
  new ResourceTimingInstrumentation(),
@@ -221,6 +225,67 @@ Provides automatic instrumentation for [Core Web Vitals](https://web.dev/vitals/
221
225
  | `includeRawAttribution` | `boolean` | `false` | When true, sets the log record body to the JSON-stringified `web-vitals` attribution object. |
222
226
  | `applyCustomLogRecordData` | `(logRecord: LogRecord) => void` | — | Hook to modify log records before they are emitted. |
223
227
 
228
+ ### Console
229
+
230
+ ```typescript
231
+ import { ConsoleInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/console';
232
+ ```
233
+
234
+ Provides automatic instrumentation for browser console API calls. By default captures `log`, `warn`, `error`, `info`, and `debug` methods.
235
+
236
+ #### Configuration
237
+
238
+ ```typescript
239
+ new ConsoleInstrumentation({
240
+ // Specify which console methods to capture (default: log, warn, error, info, debug)
241
+ logMethods: ['error', 'warn'],
242
+ });
243
+ ```
244
+ #### Captured Attributes
245
+ Each `browser.console` event includes the following attributes:
246
+
247
+ | Attribute | Description | Example |
248
+ |-----------|-------------|---------|
249
+ | `browser.console.method` | The console method that was called | `error`, `warn`, `log`, `info`, `debug` |
250
+
251
+ ---
252
+
253
+ ### Errors
254
+
255
+ ```typescript
256
+ import { ErrorsInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/errors';
257
+ ```
258
+
259
+ Emits an `exception` event for every uncaught error (`window.addEventListener('error', ...)`) and unhandled promise rejection (`window.addEventListener('unhandledrejection', ...)`).
260
+
261
+ #### Configuration
262
+
263
+ ```typescript
264
+ new ErrorsInstrumentation({
265
+ // Return extra attributes to attach to the emitted log record.
266
+ applyCustomAttributes: (error) => ({
267
+ 'app.error.severity':
268
+ error instanceof Error && error.name === 'ValidationError'
269
+ ? 'warning'
270
+ : 'error',
271
+ }),
272
+ });
273
+ ```
274
+
275
+ | Option | Type | Default | Description |
276
+ |--------|------|---------|-------------|
277
+ | `applyCustomAttributes` | `(error: Error \| string) => Attributes` | — | Returns extra attributes to merge onto the emitted log record. Errors thrown from this hook are caught and logged via the instrumentation diag logger. |
278
+
279
+ #### Captured Attributes
280
+
281
+ Each `exception` event includes:
282
+
283
+ | Attribute | Description |
284
+ |-----------|-------------|
285
+ | `exception.type` | The error's `name` (omitted when the thrown value is a string). |
286
+ | `exception.message` | The error's `message`, or the thrown string itself. |
287
+ | `exception.stacktrace` | The error's `stack` (omitted when the thrown value is a string). |
288
+
224
289
  ## Useful links
225
290
 
226
291
  - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
@@ -0,0 +1,3 @@
1
+ import { ApplyCustomAttributesFunction, ErrorsInstrumentationConfig } from "./types.js";
2
+ import { ErrorsInstrumentation } from "./instrumentation.js";
3
+ export { type ApplyCustomAttributesFunction, ErrorsInstrumentation, type ErrorsInstrumentationConfig };
@@ -0,0 +1,2 @@
1
+ import { ErrorsInstrumentation } from "./instrumentation.js";
2
+ export { ErrorsInstrumentation };
@@ -0,0 +1,17 @@
1
+ import { ErrorsInstrumentationConfig } from "./types.js";
2
+ import { InstrumentationBase } from "@opentelemetry/instrumentation";
3
+
4
+ //#region src/errors/instrumentation.d.ts
5
+ declare class ErrorsInstrumentation extends InstrumentationBase<ErrorsInstrumentationConfig> {
6
+ private _isEnabled;
7
+ private _onErrorHandler?;
8
+ constructor(config?: ErrorsInstrumentationConfig);
9
+ protected init(): never[];
10
+ enable(): void;
11
+ disable(): void;
12
+ private _onError;
13
+ private _applyCustomAttributes;
14
+ }
15
+ //#endregion
16
+ export { ErrorsInstrumentation };
17
+ //# sourceMappingURL=instrumentation.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { version } from "../package.js";
2
+ import { SeverityNumber } from "@opentelemetry/api-logs";
3
+ import { InstrumentationBase, safeExecuteInTheMiddle } from "@opentelemetry/instrumentation";
4
+ import { ATTR_EXCEPTION_MESSAGE, ATTR_EXCEPTION_STACKTRACE, ATTR_EXCEPTION_TYPE } from "@opentelemetry/semantic-conventions";
5
+ //#region src/errors/instrumentation.ts
6
+ const EXCEPTION_EVENT_NAME = "exception";
7
+ var ErrorsInstrumentation = class extends InstrumentationBase {
8
+ constructor(config = {}) {
9
+ super("@opentelemetry/browser-instrumentation/errors", version, config);
10
+ }
11
+ init() {
12
+ return [];
13
+ }
14
+ enable() {
15
+ if (this._isEnabled) return;
16
+ this._isEnabled = true;
17
+ this._onErrorHandler = (event) => this._onError(event);
18
+ window.addEventListener("error", this._onErrorHandler);
19
+ window.addEventListener("unhandledrejection", this._onErrorHandler);
20
+ }
21
+ disable() {
22
+ if (!this._isEnabled) return;
23
+ this._isEnabled = false;
24
+ if (this._onErrorHandler) {
25
+ window.removeEventListener("error", this._onErrorHandler);
26
+ window.removeEventListener("unhandledrejection", this._onErrorHandler);
27
+ this._onErrorHandler = void 0;
28
+ }
29
+ }
30
+ _onError(event) {
31
+ const error = "reason" in event ? event.reason : event.error;
32
+ if (error == null) return;
33
+ let errorAttributes;
34
+ if (typeof error === "string") errorAttributes = { [ATTR_EXCEPTION_MESSAGE]: error };
35
+ else errorAttributes = {
36
+ [ATTR_EXCEPTION_TYPE]: error.name,
37
+ [ATTR_EXCEPTION_MESSAGE]: error.message,
38
+ [ATTR_EXCEPTION_STACKTRACE]: error.stack
39
+ };
40
+ const customAttributes = this._applyCustomAttributes(error);
41
+ const logRecord = {
42
+ eventName: EXCEPTION_EVENT_NAME,
43
+ severityNumber: SeverityNumber.ERROR,
44
+ attributes: {
45
+ ...errorAttributes,
46
+ ...customAttributes
47
+ }
48
+ };
49
+ this.logger.emit(logRecord);
50
+ }
51
+ _applyCustomAttributes(error) {
52
+ const hook = this.getConfig().applyCustomAttributes;
53
+ if (!hook) return {};
54
+ let result = {};
55
+ safeExecuteInTheMiddle(() => {
56
+ result = hook(error);
57
+ }, (err) => {
58
+ if (err) this._diag.error("applyCustomAttributes hook failed", err);
59
+ }, true);
60
+ return result;
61
+ }
62
+ };
63
+ //#endregion
64
+ export { ErrorsInstrumentation };
65
+
66
+ //# sourceMappingURL=instrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentation.js","names":[],"sources":["../../src/errors/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport type { AnyValueMap, LogRecord } from '@opentelemetry/api-logs';\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport {\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n ATTR_EXCEPTION_MESSAGE,\n ATTR_EXCEPTION_STACKTRACE,\n ATTR_EXCEPTION_TYPE,\n} from '@opentelemetry/semantic-conventions';\nimport { version } from '../../package.json' with { type: 'json' };\nimport type { ErrorsInstrumentationConfig } from './types.ts';\n\nconst EXCEPTION_EVENT_NAME = 'exception';\n\nexport class ErrorsInstrumentation extends InstrumentationBase<ErrorsInstrumentationConfig> {\n // Use `declare` to prevent JS class field initializers from running after\n // super(), which would reset values set by the enable() call that\n // InstrumentationBase makes during its constructor.\n private declare _isEnabled: boolean;\n private declare _onErrorHandler?: (\n event: ErrorEvent | PromiseRejectionEvent,\n ) => void;\n\n constructor(config: ErrorsInstrumentationConfig = {}) {\n super('@opentelemetry/browser-instrumentation/errors', version, config);\n }\n\n protected override init() {\n return [];\n }\n\n override enable(): void {\n if (this._isEnabled) {\n return;\n }\n this._isEnabled = true;\n\n this._onErrorHandler = (event) => this._onError(event);\n window.addEventListener('error', this._onErrorHandler);\n window.addEventListener('unhandledrejection', this._onErrorHandler);\n }\n\n override disable(): void {\n if (!this._isEnabled) {\n return;\n }\n this._isEnabled = false;\n\n if (this._onErrorHandler) {\n window.removeEventListener('error', this._onErrorHandler);\n window.removeEventListener('unhandledrejection', this._onErrorHandler);\n this._onErrorHandler = undefined;\n }\n }\n\n private _onError(event: ErrorEvent | PromiseRejectionEvent): void {\n const error: Error | string | null | undefined =\n 'reason' in event ? event.reason : event.error;\n\n if (error == null) {\n return;\n }\n\n let errorAttributes: AnyValueMap;\n if (typeof error === 'string') {\n errorAttributes = { [ATTR_EXCEPTION_MESSAGE]: error };\n } else {\n errorAttributes = {\n [ATTR_EXCEPTION_TYPE]: error.name,\n [ATTR_EXCEPTION_MESSAGE]: error.message,\n [ATTR_EXCEPTION_STACKTRACE]: error.stack,\n };\n }\n\n const customAttributes = this._applyCustomAttributes(error);\n\n const logRecord: LogRecord = {\n eventName: EXCEPTION_EVENT_NAME,\n severityNumber: SeverityNumber.ERROR,\n attributes: { ...errorAttributes, ...customAttributes },\n };\n\n this.logger.emit(logRecord);\n }\n\n private _applyCustomAttributes(error: Error | string): Attributes {\n const hook = this.getConfig().applyCustomAttributes;\n if (!hook) {\n return {};\n }\n let result: Attributes = {};\n safeExecuteInTheMiddle(\n () => {\n result = hook(error);\n },\n (err) => {\n if (err) {\n this._diag.error('applyCustomAttributes hook failed', err);\n }\n },\n true,\n );\n return result;\n }\n}\n"],"mappings":";;;;;AAoBA,MAAM,uBAAuB;AAE7B,IAAa,wBAAb,cAA2C,oBAAiD;CAS1F,YAAY,SAAsC,EAAE,EAAE;AACpD,QAAM,iDAAiD,SAAS,OAAO;;CAGzE,OAA0B;AACxB,SAAO,EAAE;;CAGX,SAAwB;AACtB,MAAI,KAAK,WACP;AAEF,OAAK,aAAa;AAElB,OAAK,mBAAmB,UAAU,KAAK,SAAS,MAAM;AACtD,SAAO,iBAAiB,SAAS,KAAK,gBAAgB;AACtD,SAAO,iBAAiB,sBAAsB,KAAK,gBAAgB;;CAGrE,UAAyB;AACvB,MAAI,CAAC,KAAK,WACR;AAEF,OAAK,aAAa;AAElB,MAAI,KAAK,iBAAiB;AACxB,UAAO,oBAAoB,SAAS,KAAK,gBAAgB;AACzD,UAAO,oBAAoB,sBAAsB,KAAK,gBAAgB;AACtE,QAAK,kBAAkB,KAAA;;;CAI3B,SAAiB,OAAiD;EAChE,MAAM,QACJ,YAAY,QAAQ,MAAM,SAAS,MAAM;AAE3C,MAAI,SAAS,KACX;EAGF,IAAI;AACJ,MAAI,OAAO,UAAU,SACnB,mBAAkB,GAAG,yBAAyB,OAAO;MAErD,mBAAkB;IACf,sBAAsB,MAAM;IAC5B,yBAAyB,MAAM;IAC/B,4BAA4B,MAAM;GACpC;EAGH,MAAM,mBAAmB,KAAK,uBAAuB,MAAM;EAE3D,MAAM,YAAuB;GAC3B,WAAW;GACX,gBAAgB,eAAe;GAC/B,YAAY;IAAE,GAAG;IAAiB,GAAG;IAAkB;GACxD;AAED,OAAK,OAAO,KAAK,UAAU;;CAG7B,uBAA+B,OAAmC;EAChE,MAAM,OAAO,KAAK,WAAW,CAAC;AAC9B,MAAI,CAAC,KACH,QAAO,EAAE;EAEX,IAAI,SAAqB,EAAE;AAC3B,+BACQ;AACJ,YAAS,KAAK,MAAM;MAErB,QAAQ;AACP,OAAI,IACF,MAAK,MAAM,MAAM,qCAAqC,IAAI;KAG9D,KACD;AACD,SAAO"}
@@ -0,0 +1,19 @@
1
+ import { Attributes } from "@opentelemetry/api";
2
+ import { InstrumentationConfig } from "@opentelemetry/instrumentation";
3
+
4
+ //#region src/errors/types.d.ts
5
+ type ApplyCustomAttributesFunction = (error: Error | string) => Attributes;
6
+ /**
7
+ * ErrorsInstrumentation Configuration
8
+ */
9
+ interface ErrorsInstrumentationConfig extends InstrumentationConfig {
10
+ /**
11
+ * Optional callback invoked for each captured error or unhandled rejection.
12
+ * Returned attributes are merged onto the emitted log record (after the
13
+ * standard `exception.*` attributes, so they may override them).
14
+ */
15
+ applyCustomAttributes?: ApplyCustomAttributesFunction;
16
+ }
17
+ //#endregion
18
+ export { ApplyCustomAttributesFunction, ErrorsInstrumentationConfig };
19
+ //# sourceMappingURL=types.d.ts.map
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.4.0";
2
+ var version = "0.5.0";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","names":[],"sources":["../../src/user-action/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport { getElementCSSSelector } from '#instrumentation-utils';\nimport { version } from '../../package.json' with { type: 'json' };\nimport {\n ATTR_CSS_SELECTOR,\n ATTR_MOUSE_EVENT_BUTTON,\n ATTR_PAGE_X,\n ATTR_PAGE_Y,\n ATTR_TAG_NAME,\n ATTR_TAGS,\n CLICK_EVENT_NAME,\n} from './semconv.ts';\nimport type {\n AutoCapturedUserAction,\n MouseButton,\n UserActionInstrumentationConfig,\n} from './types.ts';\n\nconst DEFAULT_AUTO_CAPTURED_ACTIONS: AutoCapturedUserAction[] = ['click'];\nconst OTEL_ELEMENT_ATTRIBUTE_PREFIX = 'data-otel-';\n\n/**\n * This class automatically instruments different User Actions within the browser.\n */\nexport class UserActionInstrumentation extends InstrumentationBase<UserActionInstrumentationConfig> {\n private declare _onClickHandler?: (event: MouseEvent) => void;\n\n constructor(config: UserActionInstrumentationConfig = {}) {\n super(\n '@opentelemetry/browser-instrumentation/user-action',\n version,\n config,\n );\n }\n\n protected override init() {\n return [];\n }\n\n private _getMouseButtonFromMouseEvent(event: MouseEvent): MouseButton {\n switch (event.button) {\n case 0:\n return 'left';\n case 1:\n return 'middle';\n case 2:\n return 'right';\n default:\n return 'left';\n }\n }\n\n private onClick(event: MouseEvent) {\n const element = event.target;\n\n if (!(element instanceof HTMLElement)) {\n return;\n }\n\n if (element.hasAttribute('disabled')) {\n return;\n }\n\n const cssSelector = getElementCSSSelector(element, {\n useIdForTargetElement: true,\n useIdForAncestors: true,\n });\n const otelPrefixedAttributes: Record<string, string> = {};\n\n // Grab all the attributes in the element that start with data-otel-*\n for (const attr of element.attributes) {\n if (attr.name.startsWith(OTEL_ELEMENT_ATTRIBUTE_PREFIX)) {\n otelPrefixedAttributes[\n attr.name.slice(OTEL_ELEMENT_ATTRIBUTE_PREFIX.length)\n ] = attr.value;\n }\n }\n\n this.logger.emit({\n severityNumber: SeverityNumber.INFO,\n eventName: CLICK_EVENT_NAME,\n attributes: {\n [ATTR_PAGE_X]: event.pageX,\n [ATTR_PAGE_Y]: event.pageY,\n [ATTR_TAG_NAME]: element.tagName,\n [ATTR_TAGS]: otelPrefixedAttributes,\n [ATTR_MOUSE_EVENT_BUTTON]: this._getMouseButtonFromMouseEvent(event),\n [ATTR_CSS_SELECTOR]: cssSelector,\n },\n });\n }\n\n override enable(): void {\n const autoCapturedActions =\n this._config.autoCapturedActions ?? DEFAULT_AUTO_CAPTURED_ACTIONS;\n if (!this._onClickHandler) {\n this._onClickHandler = this.onClick.bind(this);\n }\n\n if (autoCapturedActions.includes('click')) {\n document.addEventListener('click', this._onClickHandler, true);\n }\n }\n\n override disable(): void {\n if (this._onClickHandler) {\n document.removeEventListener('click', this._onClickHandler, true);\n }\n }\n}\n"],"mappings":";;;;;;AAwBA,MAAM,gCAA0D,CAAC,QAAQ;AACzE,MAAM,gCAAgC;;;;AAKtC,IAAa,4BAAb,cAA+C,oBAAqD;CAGlG,YAAY,SAA0C,EAAE,EAAE;AACxD,QACE,sDACA,SACA,OACD;;CAGH,OAA0B;AACxB,SAAO,EAAE;;CAGX,8BAAsC,OAAgC;AACpE,UAAQ,MAAM,QAAd;GACE,KAAK,EACH,QAAO;GACT,KAAK,EACH,QAAO;GACT,KAAK,EACH,QAAO;GACT,QACE,QAAO;;;CAIb,QAAgB,OAAmB;EACjC,MAAM,UAAU,MAAM;AAEtB,MAAI,EAAE,mBAAmB,aACvB;AAGF,MAAI,QAAQ,aAAa,WAAW,CAClC;EAGF,MAAM,cAAc,sBAAsB,SAAS;GACjD,uBAAuB;GACvB,mBAAmB;GACpB,CAAC;EACF,MAAM,yBAAiD,EAAE;AAGzD,OAAK,MAAM,QAAQ,QAAQ,WACzB,KAAI,KAAK,KAAK,WAAW,8BAA8B,CACrD,wBACE,KAAK,KAAK,MAAM,GAAqC,IACnD,KAAK;AAIb,OAAK,OAAO,KAAK;GACf,gBAAgB,eAAe;GAC/B,WAAW;GACX,YAAY;KACT,cAAc,MAAM;KACpB,cAAc,MAAM;KACpB,gBAAgB,QAAQ;KACxB,YAAY;KACZ,0BAA0B,KAAK,8BAA8B,MAAM;KACnE,oBAAoB;IACtB;GACF,CAAC;;CAGJ,SAAwB;EACtB,MAAM,sBACJ,KAAK,QAAQ,uBAAuB;AACtC,MAAI,CAAC,KAAK,gBACR,MAAK,kBAAkB,KAAK,QAAQ,KAAK,KAAK;AAGhD,MAAI,oBAAoB,SAAS,QAAQ,CACvC,UAAS,iBAAiB,SAAS,KAAK,iBAAiB,KAAK;;CAIlE,UAAyB;AACvB,MAAI,KAAK,gBACP,UAAS,oBAAoB,SAAS,KAAK,iBAAiB,KAAK"}
1
+ {"version":3,"file":"instrumentation.js","names":[],"sources":["../../src/user-action/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport { getElementCSSSelector } from '#utils';\nimport { version } from '../../package.json' with { type: 'json' };\nimport {\n ATTR_CSS_SELECTOR,\n ATTR_MOUSE_EVENT_BUTTON,\n ATTR_PAGE_X,\n ATTR_PAGE_Y,\n ATTR_TAG_NAME,\n ATTR_TAGS,\n CLICK_EVENT_NAME,\n} from './semconv.ts';\nimport type {\n AutoCapturedUserAction,\n MouseButton,\n UserActionInstrumentationConfig,\n} from './types.ts';\n\nconst DEFAULT_AUTO_CAPTURED_ACTIONS: AutoCapturedUserAction[] = ['click'];\nconst OTEL_ELEMENT_ATTRIBUTE_PREFIX = 'data-otel-';\n\n/**\n * This class automatically instruments different User Actions within the browser.\n */\nexport class UserActionInstrumentation extends InstrumentationBase<UserActionInstrumentationConfig> {\n private declare _onClickHandler?: (event: MouseEvent) => void;\n\n constructor(config: UserActionInstrumentationConfig = {}) {\n super(\n '@opentelemetry/browser-instrumentation/user-action',\n version,\n config,\n );\n }\n\n protected override init() {\n return [];\n }\n\n private _getMouseButtonFromMouseEvent(event: MouseEvent): MouseButton {\n switch (event.button) {\n case 0:\n return 'left';\n case 1:\n return 'middle';\n case 2:\n return 'right';\n default:\n return 'left';\n }\n }\n\n private onClick(event: MouseEvent) {\n const element = event.target;\n\n if (!(element instanceof HTMLElement)) {\n return;\n }\n\n if (element.hasAttribute('disabled')) {\n return;\n }\n\n const cssSelector = getElementCSSSelector(element, {\n useIdForTargetElement: true,\n useIdForAncestors: true,\n });\n const otelPrefixedAttributes: Record<string, string> = {};\n\n // Grab all the attributes in the element that start with data-otel-*\n for (const attr of element.attributes) {\n if (attr.name.startsWith(OTEL_ELEMENT_ATTRIBUTE_PREFIX)) {\n otelPrefixedAttributes[\n attr.name.slice(OTEL_ELEMENT_ATTRIBUTE_PREFIX.length)\n ] = attr.value;\n }\n }\n\n this.logger.emit({\n severityNumber: SeverityNumber.INFO,\n eventName: CLICK_EVENT_NAME,\n attributes: {\n [ATTR_PAGE_X]: event.pageX,\n [ATTR_PAGE_Y]: event.pageY,\n [ATTR_TAG_NAME]: element.tagName,\n [ATTR_TAGS]: otelPrefixedAttributes,\n [ATTR_MOUSE_EVENT_BUTTON]: this._getMouseButtonFromMouseEvent(event),\n [ATTR_CSS_SELECTOR]: cssSelector,\n },\n });\n }\n\n override enable(): void {\n const autoCapturedActions =\n this._config.autoCapturedActions ?? DEFAULT_AUTO_CAPTURED_ACTIONS;\n if (!this._onClickHandler) {\n this._onClickHandler = this.onClick.bind(this);\n }\n\n if (autoCapturedActions.includes('click')) {\n document.addEventListener('click', this._onClickHandler, true);\n }\n }\n\n override disable(): void {\n if (this._onClickHandler) {\n document.removeEventListener('click', this._onClickHandler, true);\n }\n }\n}\n"],"mappings":";;;;;;AAwBA,MAAM,gCAA0D,CAAC,QAAQ;AACzE,MAAM,gCAAgC;;;;AAKtC,IAAa,4BAAb,cAA+C,oBAAqD;CAGlG,YAAY,SAA0C,EAAE,EAAE;AACxD,QACE,sDACA,SACA,OACD;;CAGH,OAA0B;AACxB,SAAO,EAAE;;CAGX,8BAAsC,OAAgC;AACpE,UAAQ,MAAM,QAAd;GACE,KAAK,EACH,QAAO;GACT,KAAK,EACH,QAAO;GACT,KAAK,EACH,QAAO;GACT,QACE,QAAO;;;CAIb,QAAgB,OAAmB;EACjC,MAAM,UAAU,MAAM;AAEtB,MAAI,EAAE,mBAAmB,aACvB;AAGF,MAAI,QAAQ,aAAa,WAAW,CAClC;EAGF,MAAM,cAAc,sBAAsB,SAAS;GACjD,uBAAuB;GACvB,mBAAmB;GACpB,CAAC;EACF,MAAM,yBAAiD,EAAE;AAGzD,OAAK,MAAM,QAAQ,QAAQ,WACzB,KAAI,KAAK,KAAK,WAAW,8BAA8B,CACrD,wBACE,KAAK,KAAK,MAAM,GAAqC,IACnD,KAAK;AAIb,OAAK,OAAO,KAAK;GACf,gBAAgB,eAAe;GAC/B,WAAW;GACX,YAAY;KACT,cAAc,MAAM;KACpB,cAAc,MAAM;KACpB,gBAAgB,QAAQ;KACxB,YAAY;KACZ,0BAA0B,KAAK,8BAA8B,MAAM;KACnE,oBAAoB;IACtB;GACF,CAAC;;CAGJ,SAAwB;EACtB,MAAM,sBACJ,KAAK,QAAQ,uBAAuB;AACtC,MAAI,CAAC,KAAK,gBACR,MAAK,kBAAkB,KAAK,QAAQ,KAAK,KAAK;AAGhD,MAAI,oBAAoB,SAAS,QAAQ,CACvC,UAAS,iBAAiB,SAAS,KAAK,iBAAiB,KAAK;;CAIlE,UAAyB;AACvB,MAAI,KAAK,gBACP,UAAS,oBAAoB,SAAS,KAAK,iBAAiB,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/browser-instrumentation",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "OpenTelemetry browser instrumentations.",
5
5
  "keywords": [
6
6
  "opentelemetry",
@@ -8,11 +8,12 @@
8
8
  "web",
9
9
  "instrumentation",
10
10
  "console",
11
+ "errors",
12
+ "navigation",
11
13
  "navigation-timing",
12
- "user-action",
13
- "web-vitals",
14
14
  "resource-timing",
15
- "navigation"
15
+ "user-action",
16
+ "web-vitals"
16
17
  ],
17
18
  "homepage": "https://github.com/open-telemetry/opentelemetry-browser",
18
19
  "bugs": "https://github.com/open-telemetry/opentelemetry-browser/issues",
@@ -25,16 +26,17 @@
25
26
  },
26
27
  "type": "module",
27
28
  "imports": {
28
- "#instrumentation-utils": "./src/utils/index.ts",
29
- "#instrumentation-test-utils": "./src/test-utils/index.ts"
29
+ "#utils": "./src/utils/index.ts",
30
+ "#utils/test": "./src/utils/test/index.ts"
30
31
  },
31
32
  "exports": {
32
- "./experimental/navigation": "./dist/navigation/index.js",
33
33
  "./experimental/console": "./dist/console/index.js",
34
+ "./experimental/errors": "./dist/errors/index.js",
35
+ "./experimental/navigation": "./dist/navigation/index.js",
34
36
  "./experimental/navigation-timing": "./dist/navigation-timing/index.js",
37
+ "./experimental/resource-timing": "./dist/resource-timing/index.js",
35
38
  "./experimental/user-action": "./dist/user-action/index.js",
36
- "./experimental/web-vitals": "./dist/web-vitals/index.js",
37
- "./experimental/resource-timing": "./dist/resource-timing/index.js"
39
+ "./experimental/web-vitals": "./dist/web-vitals/index.js"
38
40
  },
39
41
  "files": [
40
42
  "dist"
@@ -48,15 +50,16 @@
48
50
  "test:coverage": "vitest --coverage"
49
51
  },
50
52
  "dependencies": {
51
- "@opentelemetry/api-logs": "^0.216.0",
52
- "@opentelemetry/instrumentation": "^0.216.0",
53
+ "@opentelemetry/api-logs": "^0.217.0",
54
+ "@opentelemetry/instrumentation": "^0.217.0",
55
+ "@opentelemetry/semantic-conventions": "^1.40.0",
53
56
  "web-vitals": "^5.2.0"
54
57
  },
55
58
  "peerDependencies": {
56
59
  "@opentelemetry/api": "^1.9.1"
57
60
  },
58
61
  "devDependencies": {
59
- "@opentelemetry/sdk-logs": "0.216.0"
62
+ "@opentelemetry/sdk-logs": "0.217.0"
60
63
  },
61
64
  "publishConfig": {
62
65
  "access": "public"