ApplicationInsights-node.js: `ai.operation.name` not available when deployed to Azure
I have a need to update the operation name in a NodeJS API using express. Our API is using path parameter and we can’t get any useful metric from Application Insights dashboard because each request with different ID has a different operation name, hence data is not aggregated correctly.
Locally (docker and node index.js), I can run this successfully, with it replacing what I need in the operation name.
But when this is deployed Azure App Service, neither the envolope or context have the relevant properties.
I am using 2.9.6.
appInsights.defaultClient.addTelemetryProcessor(applyOperationNamePattern);
/* ... */
function applyOperationNamePattern (envelope, context) {
console.log({ context, envelope: JSON.stringify(envelope) });
if (envelope.data.baseType === 'RequestData') {
const request = context?.['http.ServerRequest'] ?? null;
const operationName = envelope.tags['ai.operation.name'];
if (!operationName) {
operationName = request.originalMethod.toUpperCase() + ' ' + request.originalUrl;
}
envelope.tags['ai.operation.name'] = operationName
.replace(uuidLikeRegex, '[id]')
.replace(numberRegex, '[id]');
console.log('operationName', envelope.tags['ai.operation.name']);
}
return true;
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (9 by maintainers)
@lcssanches I see, I misunderstood what you meant about
MetricDatagoing through the processor. So, what’s really happening is that you have a telemetry processor you want to apply to request telemetry, however, you’re finding that onlyMetricDatais being processed and therefore the operation.name value remains incorrect on the request telemetry you’re receiving.