/// <summary>
        /// Process a collected telemetry item.
        /// </summary>
        /// <param name="item">A collected Telemetry item.</param>
        public void Process(ITelemetry item)
        {
            if (this.EventSourceInternal == null)
            {
                return;
            }

            Action <ITelemetry> handler = null;
            var itemType = item.GetType();

            if (this.telemetryHandlers.TryGetValue(itemType, out handler))
            {
                item.FlattenIExtensionIfExists();
                handler(item);
            }
            else
            {
                if (this.unknownTelemetryHandler != null)
                {
                    item.Sanitize();
                    EventData telemetryData = item.FlattenTelemetryIntoEventData();
                    telemetryData.name = Constants.EventNameForUnknownTelemetry;

                    this.unknownTelemetryHandler(telemetryData, item.Context.InstrumentationKey, item.Context.SanitizedTags, item.Context.Flags);
                }
            }
        }
Beispiel #2
0
        private static void SerializeTelemetryItem(ITelemetry telemetryItem, JsonSerializationWriter jsonSerializationWriter)
        {
            jsonSerializationWriter.WriteStartObject();

            if (telemetryItem is IAiSerializableTelemetry serializeableTelemetry)
            {
                telemetryItem.CopyGlobalPropertiesIfExist();
                telemetryItem.FlattenIExtensionIfExists();
                SerializeHelper(telemetryItem, jsonSerializationWriter, telemetryName: serializeableTelemetry.TelemetryName, baseType: serializeableTelemetry.BaseType);
            }
            else
            {
                SerializeUnknownTelemetryHelper(telemetryItem, jsonSerializationWriter);
            }

            jsonSerializationWriter.WriteEndObject();
        }