0
  • Given a browser Single Page Application
  • When using AppInsights JS SDK v2.5.3
  • Then I want a CustomServiceName to be sent with ALL requests.

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

4

1 回答 1

1

a)envelope.data是模型的基础,直接在此对象上设置新属性可能无法正确摄取,并且env.data.baseData会根据您发送的数据类型而有所不同。envelope.data.properties应该存在于所有遥测类型上,并允许您随遥测一起发送任何自定义数据。envelope.data.properties["CustomServiceName"] = "MyName";是正确的实现。

b) 使用遥测初始化器是实现这一点的最佳方式——为每个请求添加一个属性是它们的用例之一。上下文具有少量特定数据点,并且列表不可自定义。根据您的其余设置,云角色可能适合,但您仍需要使用遥测初始化程序来设置它。

于 2020-03-31T02:06:23.533 回答