Skip to content

Commit

Permalink
chore(user-interactions): remove component and user agent span attrib…
Browse files Browse the repository at this point in the history
…utes (open-telemetry#1366)

Co-authored-by: Haddas Bronfman <85441461+haddasbronfman@users.noreply.github.com>
  • Loading branch information
blumamir and haddasbronfman authored Feb 16, 2023
1 parent b02775f commit a9fa540
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*/

export enum AttributeNames {
COMPONENT = 'component',
EVENT_TYPE = 'event_type',
TARGET_ELEMENT = 'target_element',
TARGET_XPATH = 'target_xpath',
HTTP_URL = 'http.url',
// NOT ON OFFICIAL SPEC
HTTP_USER_AGENT = 'http.user_agent',
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ function defaultShouldPreventSpanCreation() {
* addEventListener of HTMLElement
*/
export class UserInteractionInstrumentation extends InstrumentationBase<unknown> {
readonly component: string = 'user-interaction';
readonly version = VERSION;
moduleName = this.component;
readonly moduleName: string = 'user-interaction';
private _spansData = new WeakMap<api.Span, SpanData>();
private _zonePatched?: boolean;
// for addEventListener/removeEventListener state
Expand Down Expand Up @@ -134,12 +133,10 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>
eventName,
{
attributes: {
[AttributeNames.COMPONENT]: this.component,
[AttributeNames.EVENT_TYPE]: eventName,
[AttributeNames.TARGET_ELEMENT]: element.tagName,
[AttributeNames.TARGET_XPATH]: xpath,
[AttributeNames.HTTP_URL]: window.location.href,
[AttributeNames.HTTP_USER_AGENT]: navigator.userAgent,
},
},
parentSpan
Expand All @@ -157,7 +154,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>

return span;
} catch (e) {
api.diag.error(this.component, e);
this._diag.error('failed to start create new user interaction span', e);
}
return undefined;
}
Expand Down Expand Up @@ -575,7 +572,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>
*/
override enable() {
const ZoneWithPrototype = this.getZoneWithPrototype();
api.diag.debug(
this._diag.debug(
'applying patch to',
this.moduleName,
this.version,
Expand All @@ -585,15 +582,15 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>
if (ZoneWithPrototype) {
if (isWrapped(ZoneWithPrototype.prototype.runTask)) {
this._unwrap(ZoneWithPrototype.prototype, 'runTask');
api.diag.debug('removing previous patch from method runTask');
this._diag.debug('removing previous patch from method runTask');
}
if (isWrapped(ZoneWithPrototype.prototype.scheduleTask)) {
this._unwrap(ZoneWithPrototype.prototype, 'scheduleTask');
api.diag.debug('removing previous patch from method scheduleTask');
this._diag.debug('removing previous patch from method scheduleTask');
}
if (isWrapped(ZoneWithPrototype.prototype.cancelTask)) {
this._unwrap(ZoneWithPrototype.prototype, 'cancelTask');
api.diag.debug('removing previous patch from method cancelTask');
this._diag.debug('removing previous patch from method cancelTask');
}

this._zonePatched = true;
Expand All @@ -618,13 +615,13 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>
targets.forEach(target => {
if (isWrapped(target.addEventListener)) {
this._unwrap(target, 'addEventListener');
api.diag.debug(
this._diag.debug(
'removing previous patch from method addEventListener'
);
}
if (isWrapped(target.removeEventListener)) {
this._unwrap(target, 'removeEventListener');
api.diag.debug(
this._diag.debug(
'removing previous patch from method removeEventListener'
);
}
Expand All @@ -645,7 +642,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>
*/
override disable() {
const ZoneWithPrototype = this.getZoneWithPrototype();
api.diag.debug(
this._diag.debug(
'removing patch from',
this.moduleName,
this.version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export function assertInteractionSpan(
assert.strictEqual(span.name, name);

const attributes = span.attributes;
assert.strictEqual(attributes.component, 'user-interaction');
assert.strictEqual(attributes.event_type, eventType);
assert.strictEqual(attributes.target_element, 'BUTTON');
assert.strictEqual(attributes.target_xpath, `//*[@id="${elementId}"]`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ describe('UserInteractionInstrumentation', () => {
);

const attributes = spanClick.attributes;
assert.equal(attributes.component, 'user-interaction');
assert.equal(attributes.event_type, 'click');
assert.equal(attributes.target_element, 'BUTTON');
assert.equal(attributes.target_xpath, '//*[@id="testBtn"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ describe('UserInteractionInstrumentation', () => {
);

const attributes = spanClick.attributes;
assert.equal(attributes.component, 'user-interaction');
assert.equal(attributes.event_type, 'click');
assert.equal(attributes.target_element, 'BUTTON');
assert.equal(attributes.target_xpath, '//*[@id="testBtn"]');
Expand Down

0 comments on commit a9fa540

Please sign in to comment.