redux-saga / redux-saga

An alternative side effect model for Redux apps

Home Page:https://redux-saga.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible for a saga to "trace" the effect "chain"?

schontz opened this issue · comments

I'm curious if there's any way for a generator to get information about where it is being used in the effect "chain" to put some trace clues in logs. I'm thinking something like so:

function* sagaOne() {
  const sagaInfo = yield call(getSagaInfo);
  console.log('something important', sagaInfo.effectIds);
  const value = yield call(sagaTwo);
  console.log('the value is', value, sagaInfo.effectIds);
}

function* sagaTwo() {
  const sagaInfo = yield call(getSagaInfo);
  console.log('something else important', sagaInfo.effectIds);
  return 2;
}

I'm imagining the log output might be something like so:

something important [1, 2]
something else important [1, 2, 3]
the value is 2 [1, 2]

And we could then reconstruct a trace of effects that are all strung together. Since there may be any number of effects going on simultaneously, our logs are hard to trace, as async things are not sequential.

commented

Did you tried simlple-saga-monitor ?

I assumed using the saga monitor would be part of the equation. I'm just not sure if there's a way to match up monitor data and an effect, i.e.: yield call(getSagaMonitorDataForCurrentEffect)

commented

You will be able to inspect the payload as well.

Saga monitor is where, historically, our effort has gone into tracability.

Having said that, saga-query is a new experimental library that acts as a middleware system for your sagas using express-like middleware.

Using that system, tracability is dramatically improved because you can easily attach loggers to most of your sagas.