Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: plugin user interaction for web #658

Merged
merged 22 commits into from
Feb 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: fixes after merge
obecny committed Jan 10, 2020
commit 26eaffeb87d91e1fc5e6d724576cea71d405d31e
8 changes: 4 additions & 4 deletions examples/tracer-web/examples/user-interaction/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerRegistry } from '@opentelemetry/web';
import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request';
import { UserInteractionPlugin } from '@opentelemetry/plugin-user-interaction';
import { ZoneScopeManager } from '@opentelemetry/scope-zone';
import { CollectorExporter } from '@opentelemetry/exporter-collector';
import { B3Format } from '@opentelemetry/core';

const webTracerWithZone = new WebTracer({
const registryWithZone = new WebTracerRegistry({
httpTextFormat: new B3Format(),
scopeManager: new ZoneScopeManager(),
plugins: [
@@ -20,8 +20,8 @@ const webTracerWithZone = new WebTracer({
]
});

webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter()));
registryWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
registryWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter()));

let lastButtonId = 0;

10 changes: 6 additions & 4 deletions examples/tracer-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerRegistry } from '@opentelemetry/web';
import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request';
import { ZoneScopeManager } from '@opentelemetry/scope-zone';
import { CollectorExporter } from '@opentelemetry/exporter-collector';
import { B3Format } from '@opentelemetry/core';

const webTracerWithZone = new WebTracer({
const webTracerRegistryWithZone = new WebTracerRegistry({
httpTextFormat: new B3Format(),
scopeManager: new ZoneScopeManager(),
plugins: [
@@ -20,8 +20,10 @@ const webTracerWithZone = new WebTracer({
]
});

webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter()));
webTracerRegistryWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
webTracerRegistryWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter()));

const webTracerWithZone = webTracerRegistryWithZone.getTracer();

// example of keeping track of scope between async operations
const prepareClickEvent = () => {
2 changes: 1 addition & 1 deletion examples/tracer-web/package.json
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
"dependencies": {
"@opentelemetry/exporter-collector": "^0.3.2",
"@opentelemetry/plugin-document-load": "^0.3.2",
"@opentelemetry/plugin-user-interaction": "^0.4.0",
"@opentelemetry/plugin-user-interaction": "^0.3.2",
"@opentelemetry/plugin-xml-http-request": "^0.3.2",
"@opentelemetry/scope-zone": "^0.3.2",
"@opentelemetry/tracing": "^0.3.2",
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentelemetry/plugin-user-interaction",
"version": "0.4.0",
"version": "0.3.2",
"description": "OpenTelemetry UserInteraction automatic instrumentation package.",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Original file line number Diff line number Diff line change
@@ -44,6 +44,10 @@ export class UserInteractionPlugin extends BasePlugin<unknown> {
private _spansData = new WeakMap<types.Span, SpanData>();
private _zonePatched = false;

constructor() {
super('@opentelemetry/plugin-user-interaction', VERSION);
}

/**
* This will check if last task was timeout and will save the time to
* fix the user interaction when nothing happens
Original file line number Diff line number Diff line change
@@ -15,4 +15,4 @@
*/

// this is autogenerated file, see scripts/version-update.js
export const VERSION = '0.4.0';
export const VERSION = '0.3.2';
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import * as assert from 'assert';
import * as sinon from 'sinon';
import { isWrapped, LogLevel } from '@opentelemetry/core';
import * as tracing from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerRegistry } from '@opentelemetry/web';
import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request';
import { UserInteractionPlugin } from '../src';

@@ -40,7 +40,7 @@ describe('UserInteractionPlugin', () => {
describe('when zone.js is NOT available', () => {
let userInteractionPlugin: UserInteractionPlugin;
let sandbox: sinon.SinonSandbox;
let webTracer: WebTracer;
let webTracerRegistry: WebTracerRegistry;
let dummySpanExporter: DummySpanExporter;
let exportSpy: any;
let requests: any[] = [];
@@ -66,14 +66,14 @@ describe('UserInteractionPlugin', () => {
.stub(userInteractionPlugin, 'getZoneWithPrototype')
.callsFake(() => undefined);

webTracer = new WebTracer({
webTracerRegistry = new WebTracerRegistry({
logLevel: LogLevel.ERROR,
plugins: [userInteractionPlugin, new XMLHttpRequestPlugin()],
});

dummySpanExporter = new DummySpanExporter();
exportSpy = sandbox.stub(dummySpanExporter, 'export');
webTracer.addSpanProcessor(
webTracerRegistry.addSpanProcessor(
new tracing.SimpleSpanProcessor(dummySpanExporter)
);

Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import * as assert from 'assert';
import * as sinon from 'sinon';
import { isWrapped, LogLevel } from '@opentelemetry/core';
import * as tracing from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { WebTracerRegistry } from '@opentelemetry/web';
import { ZoneScopeManager } from '@opentelemetry/scope-zone-peer-dep';
import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request';
import { UserInteractionPlugin } from '../src';
@@ -44,7 +44,7 @@ describe('UserInteractionPlugin', () => {
describe('when zone.js is available', () => {
let userInteractionPlugin: UserInteractionPlugin;
let sandbox: sinon.SinonSandbox;
let webTracer: WebTracer;
let webTracerRegistry: WebTracerRegistry;
let dummySpanExporter: DummySpanExporter;
let exportSpy: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use let exportSpy: jasmine.Spy? Can we need to pull in Jasmine types for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@obecny friendly ping on this - is it possible to use the jasmine.Spy type here?

let requests: any[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What properties are you accessing on requests? Could you make an interface to represent those so you don't need any here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@obecny friendly ping here, is there any more specific type we can use?

@@ -66,14 +66,14 @@ describe('UserInteractionPlugin', () => {
sandbox.useFakeTimers();

userInteractionPlugin = new UserInteractionPlugin();
webTracer = new WebTracer({
webTracerRegistry = new WebTracerRegistry({
logLevel: LogLevel.ERROR,
scopeManager: new ZoneScopeManager(),
plugins: [userInteractionPlugin, new XMLHttpRequestPlugin()],
});
dummySpanExporter = new DummySpanExporter();
exportSpy = sandbox.stub(dummySpanExporter, 'export');
webTracer.addSpanProcessor(
webTracerRegistry.addSpanProcessor(
new tracing.SimpleSpanProcessor(dummySpanExporter)
);