Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@honeycombio/opentelemetry-web

Package Overview
Dependencies
Maintainers
21
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@honeycombio/opentelemetry-web - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+147
dist/cjs/user-interaction-instrumentation-BgsIo2V3.js
'use strict';
var api = require('@opentelemetry/api');
var instrumentation = require('@opentelemetry/instrumentation');
var sdkTraceWeb = require('@opentelemetry/sdk-trace-web');
const VERSION = '1.2.0';
const INSTRUMENTATION_NAME = '@honeycombio/user-instrumentation';
const DEFAULT_EVENT_NAMES = ['click'];
class UserInteractionInstrumentation extends instrumentation.InstrumentationBase {
constructor(config = {}) {
var _a, _b;
super(INSTRUMENTATION_NAME, VERSION, config);
this._config = config;
this._isEnabled = (_a = this._config.enabled) !== null && _a !== void 0 ? _a : false;
// enable() gets called by our superclass constructor
// @ts-expect-error this may get set in enable()
this._listeners = (_b = this._listeners) !== null && _b !== void 0 ? _b : [];
}
init() {}
static handleEndSpan(ev) {
var _a;
(_a = UserInteractionInstrumentation._eventMap.get(ev)) === null || _a === void 0 ? void 0 : _a.end();
}
static createGlobalEventListener(eventName, rootNodeId, isInstrumentationEnabled) {
return event => {
const element = event.target;
if (isInstrumentationEnabled() === false) return;
if (UserInteractionInstrumentation._eventMap.has(event)) return;
if (!shouldCreateSpan(event, element, eventName, rootNodeId)) return;
const xpath = sdkTraceWeb.getElementXPath(element);
const tracer = api.trace.getTracer(INSTRUMENTATION_NAME);
api.context.with(api.context.active(), () => {
tracer.startActiveSpan(eventName, {
attributes: {
event_type: eventName,
target_element: element.tagName,
target_xpath: xpath,
'http.url': window.location.href
}
}, span => {
// if user space code calls stopPropagation, we'll never see it again
// so let's monkey patch those funcs to end the span if they do kill it
wrapEventPropagationCb(event, 'stopPropagation', span);
wrapEventPropagationCb(event, 'stopImmediatePropagation', span);
UserInteractionInstrumentation._eventMap.set(event, span);
});
});
};
}
enable() {
var _a;
if (this._isEnabled) {
return;
}
const rootNode = this.getRootNode();
// enable() gets called by our superclass constructor
// meaning our private fields aren't initialized yet!!
this._listeners = [];
//
const eventNames = (_a = this._config.eventNames) !== null && _a !== void 0 ? _a : DEFAULT_EVENT_NAMES;
eventNames.forEach(eventName => {
// we need a stable reference to this handler so that we can remove it later
const handler = UserInteractionInstrumentation.createGlobalEventListener(eventName, this._config.rootNodeId, () => this._isEnabled);
this._listeners.push({
eventName,
handler
});
// capture phase listener to kick in before any other listeners
rootNode.addEventListener(eventName, handler, {
capture: true
});
// bubble phase listener gets called at the end, if user space doesn't call e.stopPropagation()
rootNode.addEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._isEnabled = true;
}
getRootNode() {
if (this._config.rootNodeId) {
const rootNode = document.getElementById(this._config.rootNodeId);
if (rootNode === null) {
this._diag.warn(`Root Node id: ${this._config.rootNodeId} not found!`);
return document;
}
return rootNode;
}
return document;
}
disable() {
this._isEnabled = false;
this._listeners.forEach(({
eventName,
handler
}) => {
document.removeEventListener(eventName, handler, {
capture: true
});
document.removeEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._listeners = [];
}
}
UserInteractionInstrumentation._eventMap = new WeakMap();
const shouldCreateSpan = (event, element, eventName, rootNodeId) => {
if (!(element instanceof HTMLElement)) {
return false;
}
const handlerName = `on${eventName}`;
if (!elementHasEventHandler(element, handlerName, rootNodeId)) {
return false;
}
if (!element.getAttribute) {
return false;
}
if (element.hasAttribute('disabled')) {
return false;
}
return true;
};
/**
* Detects if this event on this element is useful
* by checking if this element or any of its parents have handlers
* for this event.
*
* Accounts for the fact that frameworks like React will put dummy/noop
* handlers at their root, and ignores those.
*/
const elementHasEventHandler = (element, eventName, rootNodeId) => {
if (!element || !!rootNodeId && element.id === rootNodeId) {
return false;
}
if (element[eventName]) {
return true;
}
return elementHasEventHandler(element.parentElement, eventName, rootNodeId);
};
const wrapEventPropagationCb = (event, key, span) => {
const oldCb = event[key].bind(event);
event[key] = () => {
span.end();
oldCb();
};
};
exports.UserInteractionInstrumentation = UserInteractionInstrumentation;
exports.VERSION = VERSION;
import { trace, context } from '@opentelemetry/api';
import { InstrumentationBase } from '@opentelemetry/instrumentation';
import { getElementXPath } from '@opentelemetry/sdk-trace-web';
const VERSION = '1.2.0';
const INSTRUMENTATION_NAME = '@honeycombio/user-instrumentation';
const DEFAULT_EVENT_NAMES = ['click'];
class UserInteractionInstrumentation extends InstrumentationBase {
constructor(config = {}) {
var _a, _b;
super(INSTRUMENTATION_NAME, VERSION, config);
this._config = config;
this._isEnabled = (_a = this._config.enabled) !== null && _a !== void 0 ? _a : false;
// enable() gets called by our superclass constructor
// @ts-expect-error this may get set in enable()
this._listeners = (_b = this._listeners) !== null && _b !== void 0 ? _b : [];
}
init() {}
static handleEndSpan(ev) {
var _a;
(_a = UserInteractionInstrumentation._eventMap.get(ev)) === null || _a === void 0 ? void 0 : _a.end();
}
static createGlobalEventListener(eventName, rootNodeId, isInstrumentationEnabled) {
return event => {
const element = event.target;
if (isInstrumentationEnabled() === false) return;
if (UserInteractionInstrumentation._eventMap.has(event)) return;
if (!shouldCreateSpan(event, element, eventName, rootNodeId)) return;
const xpath = getElementXPath(element);
const tracer = trace.getTracer(INSTRUMENTATION_NAME);
context.with(context.active(), () => {
tracer.startActiveSpan(eventName, {
attributes: {
event_type: eventName,
target_element: element.tagName,
target_xpath: xpath,
'http.url': window.location.href
}
}, span => {
// if user space code calls stopPropagation, we'll never see it again
// so let's monkey patch those funcs to end the span if they do kill it
wrapEventPropagationCb(event, 'stopPropagation', span);
wrapEventPropagationCb(event, 'stopImmediatePropagation', span);
UserInteractionInstrumentation._eventMap.set(event, span);
});
});
};
}
enable() {
var _a;
if (this._isEnabled) {
return;
}
const rootNode = this.getRootNode();
// enable() gets called by our superclass constructor
// meaning our private fields aren't initialized yet!!
this._listeners = [];
//
const eventNames = (_a = this._config.eventNames) !== null && _a !== void 0 ? _a : DEFAULT_EVENT_NAMES;
eventNames.forEach(eventName => {
// we need a stable reference to this handler so that we can remove it later
const handler = UserInteractionInstrumentation.createGlobalEventListener(eventName, this._config.rootNodeId, () => this._isEnabled);
this._listeners.push({
eventName,
handler
});
// capture phase listener to kick in before any other listeners
rootNode.addEventListener(eventName, handler, {
capture: true
});
// bubble phase listener gets called at the end, if user space doesn't call e.stopPropagation()
rootNode.addEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._isEnabled = true;
}
getRootNode() {
if (this._config.rootNodeId) {
const rootNode = document.getElementById(this._config.rootNodeId);
if (rootNode === null) {
this._diag.warn(`Root Node id: ${this._config.rootNodeId} not found!`);
return document;
}
return rootNode;
}
return document;
}
disable() {
this._isEnabled = false;
this._listeners.forEach(({
eventName,
handler
}) => {
document.removeEventListener(eventName, handler, {
capture: true
});
document.removeEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._listeners = [];
}
}
UserInteractionInstrumentation._eventMap = new WeakMap();
const shouldCreateSpan = (event, element, eventName, rootNodeId) => {
if (!(element instanceof HTMLElement)) {
return false;
}
const handlerName = `on${eventName}`;
if (!elementHasEventHandler(element, handlerName, rootNodeId)) {
return false;
}
if (!element.getAttribute) {
return false;
}
if (element.hasAttribute('disabled')) {
return false;
}
return true;
};
/**
* Detects if this event on this element is useful
* by checking if this element or any of its parents have handlers
* for this event.
*
* Accounts for the fact that frameworks like React will put dummy/noop
* handlers at their root, and ignores those.
*/
const elementHasEventHandler = (element, eventName, rootNodeId) => {
if (!element || !!rootNodeId && element.id === rootNodeId) {
return false;
}
if (element[eventName]) {
return true;
}
return elementHasEventHandler(element.parentElement, eventName, rootNodeId);
};
const wrapEventPropagationCb = (event, key, span) => {
const oldCb = event[key].bind(event);
event[key] = () => {
span.end();
oldCb();
};
};
export { UserInteractionInstrumentation as U, VERSION as V };
+1
-1
'use strict';
var userInteractionInstrumentation = require('../user-interaction-instrumentation-qqYujxvd.js');
var userInteractionInstrumentation = require('../user-interaction-instrumentation-BgsIo2V3.js');
require('@opentelemetry/api');

@@ -5,0 +5,0 @@ require('@opentelemetry/instrumentation');

@@ -1,4 +0,4 @@

export { U as UserInteractionInstrumentation } from '../user-interaction-instrumentation-CetVOd-2.js';
export { U as UserInteractionInstrumentation } from '../user-interaction-instrumentation-be50HE5P.js';
import '@opentelemetry/api';
import '@opentelemetry/instrumentation';
import '@opentelemetry/sdk-trace-web';
{
"name": "@honeycombio/opentelemetry-web",
"version": "1.1.0",
"version": "1.2.0",
"description": "Honeycomb OpenTelemetry Wrapper for Browser Applications",

@@ -5,0 +5,0 @@ "repository": {

'use strict';
var api = require('@opentelemetry/api');
var instrumentation = require('@opentelemetry/instrumentation');
var sdkTraceWeb = require('@opentelemetry/sdk-trace-web');
const VERSION = '1.1.0';
const INSTRUMENTATION_NAME = '@honeycombio/user-instrumentation';
const DEFAULT_EVENT_NAMES = ['click'];
class UserInteractionInstrumentation extends instrumentation.InstrumentationBase {
constructor(config = {}) {
var _a, _b;
super(INSTRUMENTATION_NAME, VERSION, config);
this._config = config;
this._isEnabled = (_a = this._config.enabled) !== null && _a !== void 0 ? _a : false;
// enable() gets called by our superclass constructor
// @ts-expect-error this may get set in enable()
this._listeners = (_b = this._listeners) !== null && _b !== void 0 ? _b : [];
}
init() {}
static handleEndSpan(ev) {
var _a;
(_a = UserInteractionInstrumentation._eventMap.get(ev)) === null || _a === void 0 ? void 0 : _a.end();
}
static createGlobalEventListener(eventName, rootNodeId, isInstrumentationEnabled) {
return event => {
const element = event.target;
if (isInstrumentationEnabled() === false) return;
if (UserInteractionInstrumentation._eventMap.has(event)) return;
if (!shouldCreateSpan(event, element, eventName, rootNodeId)) return;
const xpath = sdkTraceWeb.getElementXPath(element);
const tracer = api.trace.getTracer(INSTRUMENTATION_NAME);
api.context.with(api.context.active(), () => {
tracer.startActiveSpan(eventName, {
attributes: {
event_type: eventName,
target_element: element.tagName,
target_xpath: xpath,
'http.url': window.location.href
}
}, span => {
// if user space code calls stopPropagation, we'll never see it again
// so let's monkey patch those funcs to end the span if they do kill it
wrapEventPropagationCb(event, 'stopPropagation', span);
wrapEventPropagationCb(event, 'stopImmediatePropagation', span);
UserInteractionInstrumentation._eventMap.set(event, span);
});
});
};
}
enable() {
var _a;
if (this._isEnabled) {
return;
}
const rootNode = this.getRootNode();
// enable() gets called by our superclass constructor
// meaning our private fields aren't initialized yet!!
this._listeners = [];
//
const eventNames = (_a = this._config.eventNames) !== null && _a !== void 0 ? _a : DEFAULT_EVENT_NAMES;
eventNames.forEach(eventName => {
// we need a stable reference to this handler so that we can remove it later
const handler = UserInteractionInstrumentation.createGlobalEventListener(eventName, this._config.rootNodeId, () => this._isEnabled);
this._listeners.push({
eventName,
handler
});
// capture phase listener to kick in before any other listeners
rootNode.addEventListener(eventName, handler, {
capture: true
});
// bubble phase listener gets called at the end, if user space doesn't call e.stopPropagation()
rootNode.addEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._isEnabled = true;
}
getRootNode() {
if (this._config.rootNodeId) {
const rootNode = document.getElementById(this._config.rootNodeId);
if (rootNode === null) {
this._diag.warn(`Root Node id: ${this._config.rootNodeId} not found!`);
return document;
}
return rootNode;
}
return document;
}
disable() {
this._isEnabled = false;
this._listeners.forEach(({
eventName,
handler
}) => {
document.removeEventListener(eventName, handler, {
capture: true
});
document.removeEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._listeners = [];
}
}
UserInteractionInstrumentation._eventMap = new WeakMap();
const shouldCreateSpan = (event, element, eventName, rootNodeId) => {
if (!(element instanceof HTMLElement)) {
return false;
}
const handlerName = `on${eventName}`;
if (!elementHasEventHandler(element, handlerName, rootNodeId)) {
return false;
}
if (!element.getAttribute) {
return false;
}
if (element.hasAttribute('disabled')) {
return false;
}
return true;
};
/**
* Detects if this event on this element is useful
* by checking if this element or any of its parents have handlers
* for this event.
*
* Accounts for the fact that frameworks like React will put dummy/noop
* handlers at their root, and ignores those.
*/
const elementHasEventHandler = (element, eventName, rootNodeId) => {
if (!element || !!rootNodeId && element.id === rootNodeId) {
return false;
}
if (element[eventName]) {
return true;
}
return elementHasEventHandler(element.parentElement, eventName, rootNodeId);
};
const wrapEventPropagationCb = (event, key, span) => {
const oldCb = event[key].bind(event);
event[key] = () => {
span.end();
oldCb();
};
};
exports.UserInteractionInstrumentation = UserInteractionInstrumentation;
exports.VERSION = VERSION;
import { trace, context } from '@opentelemetry/api';
import { InstrumentationBase } from '@opentelemetry/instrumentation';
import { getElementXPath } from '@opentelemetry/sdk-trace-web';
const VERSION = '1.1.0';
const INSTRUMENTATION_NAME = '@honeycombio/user-instrumentation';
const DEFAULT_EVENT_NAMES = ['click'];
class UserInteractionInstrumentation extends InstrumentationBase {
constructor(config = {}) {
var _a, _b;
super(INSTRUMENTATION_NAME, VERSION, config);
this._config = config;
this._isEnabled = (_a = this._config.enabled) !== null && _a !== void 0 ? _a : false;
// enable() gets called by our superclass constructor
// @ts-expect-error this may get set in enable()
this._listeners = (_b = this._listeners) !== null && _b !== void 0 ? _b : [];
}
init() {}
static handleEndSpan(ev) {
var _a;
(_a = UserInteractionInstrumentation._eventMap.get(ev)) === null || _a === void 0 ? void 0 : _a.end();
}
static createGlobalEventListener(eventName, rootNodeId, isInstrumentationEnabled) {
return event => {
const element = event.target;
if (isInstrumentationEnabled() === false) return;
if (UserInteractionInstrumentation._eventMap.has(event)) return;
if (!shouldCreateSpan(event, element, eventName, rootNodeId)) return;
const xpath = getElementXPath(element);
const tracer = trace.getTracer(INSTRUMENTATION_NAME);
context.with(context.active(), () => {
tracer.startActiveSpan(eventName, {
attributes: {
event_type: eventName,
target_element: element.tagName,
target_xpath: xpath,
'http.url': window.location.href
}
}, span => {
// if user space code calls stopPropagation, we'll never see it again
// so let's monkey patch those funcs to end the span if they do kill it
wrapEventPropagationCb(event, 'stopPropagation', span);
wrapEventPropagationCb(event, 'stopImmediatePropagation', span);
UserInteractionInstrumentation._eventMap.set(event, span);
});
});
};
}
enable() {
var _a;
if (this._isEnabled) {
return;
}
const rootNode = this.getRootNode();
// enable() gets called by our superclass constructor
// meaning our private fields aren't initialized yet!!
this._listeners = [];
//
const eventNames = (_a = this._config.eventNames) !== null && _a !== void 0 ? _a : DEFAULT_EVENT_NAMES;
eventNames.forEach(eventName => {
// we need a stable reference to this handler so that we can remove it later
const handler = UserInteractionInstrumentation.createGlobalEventListener(eventName, this._config.rootNodeId, () => this._isEnabled);
this._listeners.push({
eventName,
handler
});
// capture phase listener to kick in before any other listeners
rootNode.addEventListener(eventName, handler, {
capture: true
});
// bubble phase listener gets called at the end, if user space doesn't call e.stopPropagation()
rootNode.addEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._isEnabled = true;
}
getRootNode() {
if (this._config.rootNodeId) {
const rootNode = document.getElementById(this._config.rootNodeId);
if (rootNode === null) {
this._diag.warn(`Root Node id: ${this._config.rootNodeId} not found!`);
return document;
}
return rootNode;
}
return document;
}
disable() {
this._isEnabled = false;
this._listeners.forEach(({
eventName,
handler
}) => {
document.removeEventListener(eventName, handler, {
capture: true
});
document.removeEventListener(eventName, UserInteractionInstrumentation.handleEndSpan);
});
this._listeners = [];
}
}
UserInteractionInstrumentation._eventMap = new WeakMap();
const shouldCreateSpan = (event, element, eventName, rootNodeId) => {
if (!(element instanceof HTMLElement)) {
return false;
}
const handlerName = `on${eventName}`;
if (!elementHasEventHandler(element, handlerName, rootNodeId)) {
return false;
}
if (!element.getAttribute) {
return false;
}
if (element.hasAttribute('disabled')) {
return false;
}
return true;
};
/**
* Detects if this event on this element is useful
* by checking if this element or any of its parents have handlers
* for this event.
*
* Accounts for the fact that frameworks like React will put dummy/noop
* handlers at their root, and ignores those.
*/
const elementHasEventHandler = (element, eventName, rootNodeId) => {
if (!element || !!rootNodeId && element.id === rootNodeId) {
return false;
}
if (element[eventName]) {
return true;
}
return elementHasEventHandler(element.parentElement, eventName, rootNodeId);
};
const wrapEventPropagationCb = (event, key, span) => {
const oldCb = event[key].bind(event);
event[key] = () => {
span.end();
oldCb();
};
};
export { UserInteractionInstrumentation as U, VERSION as V };

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display