New Relic: How to replace createTracer with startSegment - callback

I had a createTracer() method in the code which we were using in old new relic version.
NR.createTracer("processThread", _ => this._initialize())();
To migrate new relic to latest versin of New Relic, I've replaced it to startSegment() method as per new relic doc: https://github.com/newrelic/node-newrelic/blob/master/Migration%20Guide.md#upgrading-to-agent-v5
NR.startSegment("processThread", _ => this._initialize())();
But now, my code is giving me this error:
TypeError: NR.startSegment(...) is not a function
What am I doing wrong here?
I see the arguments have been changed in startSegment() and createTracer()
https://newrelic.github.io/node-newrelic/docs/API.html#createTracer

As docs suggest, you have a mandatory (boolean) second parameter which you must supply:
NR.startSegment('mySegment', false, _ => this._initialize())();
record bool
Indicates if the segment should be recorded as a metric. Metrics will show up on the transaction breakdown table and server breakdown graph. Segments just show up in transaction traces.
And parameter callback is now optional, you should use third parameter handler for callback
To instrument individual callbacks, call startSegment() inside the callback, and move the main callback logic to the handler function.

Related

How to get a list of all pending assignments under all courses in Moodle using the Web service API

I want to get a list of all assignments along with their completion status under all courses. Basically what is shown under the timeline in the dashboard.
The WS function core_course_get_enrolled_courses_by_timeline_classification, gives me all the current courses the student is enrolled in when I use the parameter ?classification=inprogress.
Using the course ids from the above function, I pass them as parameters to the function mod_assign_get_assignments, but there's just one tiny problem, it doesn't give any information on whether that assignment has been marked as complete by the student (completion status).
The function core_course_get_contents is a lot more than what I need since it provides every single module in that course and all activities under each module, moreover it gives all this only for one course at a time, however it does give the completion status for each activity.
Also, it would help me out a lot if you provide the required and optional query parameters since the API docs are quite terrible and doesn't provide any of that, I had to google each function which was very time consuming.
The closest function I can see is core_completion_get_activities_completion_status
You can pass the course id and the user id
Which returns with a list of activities including
'cmid' => new external_value(PARAM_INT, 'course module ID'),
'modname' => new external_value(PARAM_PLUGIN, 'activity module name'),
'instance' => new external_value(PARAM_INT, 'instance ID'),
'state' => new external_value(PARAM_INT,
"Completion state value:
0 means incomplete,
1 complete,
2 complete pass,
3 complete fail"
),
'timecompleted' => new external_value(PARAM_INT,
'timestamp for completed activity'),
So in your code, filter the result for modname = 'assign'
The id in the mdl_assign table is the instance id

Running into an issue with a mutation and component flickering with react-query

So, I am making a query everything my context API is updated via a form selection update..
So, order of operation is like so.
User makes a change to a form by selecting (one of possible many) from dropdown.
Change updates "context api" which resaturates the parent component.
Because the form key/values changed, I fire a mutation.
Mutation returns a value. So far, great.
But, when I repeat step #1 - #4, another component flickers with that updated value because at some point the "const" that is expecting a value is undefined... THEN, it has a value..
So, like so..
has a value...
...query api call...
has no value
...returns query
has a value
const ProductPage = (props) => {
const { question } = useContextStateWhatever();
/* Queries */
const { data = {}, isFetched } = useProductUpdatePrice({ questions });
const value = derivePriceFromResponse(data.products);
return (
<SomeComponentRendered value={value} />
)
So, you can see between the "old value" and request in query, that the passed "value" will be undefined. Then query returns, updated value.
I was hoping the query will return any previous value, but the "queryKey" changes with every selection of the form. Deep queryKey.
I was hoping I wouldn't have to then put this value into local state from within a useEffect, or use useRef and create hook to hand back "previous" value until new value is ready.... That's not what react-query is for, right? I mean, shouldn't I be able to make a query call whenever the "context api" changes, and not expect this latency diff of undefined. Any strategies to over come this?
Since the "queryKey" is different (mostly for normal form interaction) for each query, I can see how it can't hand back a previous value until it resolves etc.. any ideas?
Any thoughts?
I think the keepPreviousData: true option is what you are looking for. If the query key changes, you will the get the data from the previous query key, along with an isPreviousData: true flag. The background update will still happen, and then you’ll get the data for the new query key once it arrives. The query will stay in isSuccess status the whole time.

RSJX Observable not returning data

The following code, when subscribed to, returns an expected array of objects.
this.store.select (this.selectors.evidenceSelector);
The objects include a 'subjectId' field.
This code, based on multiple examples on the web, returns nothing when subscribed to:
this.store
.select (this.selectors.evidenceSelector)
.pipe (
groupBy (ev => ev['subjectId']),
mergeMap (group$ => group$.pipe(toArray())),
);
The subscription never gets triggered...
Any suggestions?
Oh after reading again... I think I've figured out what's going on here.
toArray will only emit a value when the stream is closed. As you're listening from your store (which will never be closed), you'll never get anything under the toArray. You have to use something like scan if you want to accumulate and show a result on every new emission.

ag-grid Refresh Column Filter after initial load

According to https://www.ag-grid.com/javascript-grid-filter-set/, "The grid does not update the filters for you as there are too many use cases...", #agreed.
I am using a Server Side data source with Infinite Paging querying a large set of data. Although, at initial load time, I may be confident the filter is listing all available "choices", I am hoping to find a solution to "reload" the filter at some frequency/event to be certain.
I am attempting to use the resetFilterValues() method of the object returned by a call to gridOptions.api.getFilterInstance(id).
When using a Server Side data source I am receiving the following console.error output:
ag-Grid: Set Filter cannot initialise because you are using a row model that does not contain all rows in the browser. Either use a different filter type, or configure Set Filter such that you provide it with values (Source ag-grid-enterprise.min.js:555
Note: The values method with async value load works splendidly and is written in accordance with recommendation e.g. callback to params.success with values.
I load the filter choices in the Column Header using the following approach:
{
headerName: 'Something',
field: 'SOMETHING',
width: 200,
suppressMenu: false,
suppressFilter: false,
filter: 'agSetColumnFilter',
filterParams: {
values: function (params) {
someAsyncMethodReturningAPIResultsAsArray();
}
newRowsAction: 'keep'
},
menuTabs: ['filterMenuTab']
}
I then attempt to reload the filters at a later time (like when a button is pressed outside the grid) using the following code:
var filter = gridOptions.api.getFilterInstance(id);
filter.resetFilterValues();
This code results in the error expressed above.
Q: Does anyone know how to configure Set Model to return rows as described in the error message? Is there a better way to approach this problem anyone has experience with?
Thanks
This code below can be executed in the postProcessPopup callback and it will call the values() function defined in filterParams every time the popup is opened
var filter = gridOptions.api.getFilterInstance(id);
filter.refreshFilterValues();
Note: The refreshFilterValues function is doing the trick here. It is available in v24 and above. Not too sure about older versions.

GTK: TreeModel::iter_next returns false when there are more elements

I have a TreeView with a TreeStore, and it looks like this:
I get the selected row from the TreeView by calling get_selection and calling get_selected on the resulting TreeSelection. From this I obtain a TreeIter which should point to the selected row.
I expect either iter_next or iter_prev (from TreeModel) to be successful since there is another row at the same level, namely Hello. However, calling either of those iter functions on the selected iter returns false.
Have I misunderstood something?
The documentation for TreeModel::iter_next states:
Returns an iterator pointing to the node following iter at the current level.
And Hello and Hello 2 are evidently on the same level.
I found the problem. I listen for Shift+Up to do the operation I mentioned. However, it seems like GTK first acts according to the Up keypress so that when my node_up function is called, the focus has changed to the Help node.