0
votes

What I would like to do is add custom properties to telemetry data as it leaves my application. Currently I am achieving this using a Telemetry Processor, however ideally I would like to read the value to be sent with the event from a database.

Is it possible to perform async operations inside a telemetry processor?

var TraceProcessor = function (app) {
    return function (envelope) {

        var i;
        var objTelemetryController = app.telemetryController;

        objTelemetryController.__proto__.getActiveTraces('GLOBAL', function (err, objTraces) {
            if (err) {
                // Error controller log error
                return;
            }

            if (objTraces) {
                for (i = 0; i < objTraces.length; i++) {
                    envelope.data.baseData.properties['TraceProperty'] = objTraces[i];
                }

                return true;
            }
        });
    };
};
module.exports = TraceProcessor;

Using his code the telemetry data is not sent because insights requires true to be returned from any telemetry processors that are in use. Obviously this does happen eventually but not so that the properties can be added.

1

1 Answers

1
votes

I think it's better to use TelemetryInitializer to enrich the telemetry data with extra information, the purpose of the TelemetryProcessor skewed more towards filtering rather than data enrichment.

However, I think that if you try to call SQL or HTTP dependency from within the Telemetry Initializer it might go into an endless cycle:

  • Telemetry Item is processed in Initializer
  • Initializer starts SQL query AI
  • Detects SQL query and start processing telemetry item about it
  • Telemetry Initializer calls into SQL....

I doubt that async is really supported here at this moment, it could've helped (e.g. return a task and wait for value to fill in) but it would require an immersive investigation to consider all the cases.