Reputation: 2168
a) Should the custom properties be on the envelope.data
, env.data.baseData
or envelope.data.properties
?
It appears to change depending on the type of call made.
b) Can I set the CustomServiceName
on the operation context instead of EVERY request instead?
Currently we are using this
var telemetryInitializer = (envelope) => {
envelope.tags["ai.application.ver"] = "1.2.3";
if (envelope.data) {
envelope.data["CustomServiceName"] = "MyName";
if (envelope.data.properties) {
envelope.data.properties["CustomServiceName"] = "MyName";
}
}
};
aisdk.addTelemetryInitializer(telemetryInitializer);
Based on https://github.com/microsoft/ApplicationInsights-JS#telemetry-initializers
Upvotes: 1
Views: 2593
Reputation: 3511
a) envelope.data
is the base of the model and setting new properties directly on this object may not be ingested properly, and env.data.baseData
will vary depending on the type of data you send. envelope.data.properties
should exist on all telemetry types and allows you to send whatever custom data along with your telemetry you wish. envelope.data.properties["CustomServiceName"] = "MyName";
is the correct implementation.
b) Using a telemetry initializer is the best way to achieve this- adding a property to each request is one of the use cases for them. The context has a small number of specific data points, and the list isn't customizable. Depending on the rest of your setup, Cloud Role may fit, but you will still need to use a telemetry initializer to set it.
Upvotes: 1