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

plugin-user-interaction integrated into vue.js #820

Closed
1 of 2 tasks
snake-ch opened this issue Feb 28, 2020 · 0 comments
Closed
1 of 2 tasks

plugin-user-interaction integrated into vue.js #820

snake-ch opened this issue Feb 28, 2020 · 0 comments

Comments

@snake-ch
Copy link

snake-ch commented Feb 28, 2020

  • This only affects the JavaScript OpenTelemetry library
  • This may affect other libraries, but I would like to get opinions here first

I try to use user-interaction plugin with vue.js, there is something wrong with tracing. I read the source code of the plugin. it seems that async operation counter +1 when invoke patchScheduleTask() and -1 when invoke patchRunTask() and then finish span when all tasks done.

The question is : is it possible an async operation scheduled in a zoneTask and invoke its callback in another?

<div id="root" @click="hello">{{ msg }}</div>
var vm = new Vue({
  el: '#root',
  data: {
    msg : ''
  }
  methods:{
    ...
   
    function hello(){
      // 1. dom update
      this.msg = "hello world"
      // 2. async operation
      setTimeout(() => {}, 0);
    }
    
    ...
  }
})

In user-interaction-plugin, click event listener callback(here is hello()) will run in a new zone, then patchScheduleTask() will detect setTimeout(...), patchRunTask() will invoke its callback fn, right?
when hello() function done, vue will notify watcher to update DOM, it generates a Promise outside hello() function, with DOM update callback inside.

I print the params defined in patchScheduleTask() and patchRunTask() log message, schedule and run with different zoneTask, and _shouldCountTask() followed, span with number of task is not correct.

_patchZoneScheduleTask(), _patchZoneRunTask(), _patchZoneCancelTask(), I replace current zone global to the zone.js callback inner one:

  private _patchZoneScheduleTask() {
    const plugin = this;
    return (original: any) => {
      return function patchScheduleTask<T extends Task>(
        this: Zone,
        task: AsyncTask
      ) {
        // const currentZone = Zone.current;
        const currentZone = this;
        const currentSpan: types.Span = currentZone.get(ZONE_SCOPE_KEY);
        if (currentSpan && plugin._shouldCountTask(task, currentZone)) {
          plugin._incrementTask(currentSpan);
          plugin._checkForTimeout(task, currentSpan);
        }
        return original.call(this, task) as T;
      };
    };
  }

it works, is it the right thing to do?

pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this issue Dec 15, 2023
* chore: typo in CONTRIBUTING.md

* chore: cleanup files entries in package.json (open-telemetry#820)

* chore: add missing files entries to package.json (open-telemetry#820)

* chore: remove useless .npmignore (open-telemetry#820)

---------

Co-authored-by: Amir Blum <[email protected]>
martinkuba pushed a commit to martinkuba/opentelemetry-js that referenced this issue Mar 13, 2024
* chore: typo in CONTRIBUTING.md

* chore: cleanup files entries in package.json (open-telemetry#820)

* chore: add missing files entries to package.json (open-telemetry#820)

* chore: remove useless .npmignore (open-telemetry#820)

---------

Co-authored-by: Amir Blum <[email protected]>
martinkuba pushed a commit to martinkuba/opentelemetry-js that referenced this issue Mar 16, 2024
* chore: typo in CONTRIBUTING.md

* chore: cleanup files entries in package.json (open-telemetry#820)

* chore: add missing files entries to package.json (open-telemetry#820)

* chore: remove useless .npmignore (open-telemetry#820)

---------

Co-authored-by: Amir Blum <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant