public void Track(ITelemetry telemetry) { // TALK TO YOUR TEAM MATES BEFORE CHANGING THIS. // This method needs to be public so that we can build and ship new telemetry types without having to ship core. // It is hidden from intellisense to prevent customer confusion. if (this.IsEnabled()) { this.Initialize(telemetry); if (string.IsNullOrEmpty(telemetry.Context.InstrumentationKey)) { TelemetryDebugWriter.WriteTelemetry(telemetry); return; } // If someone created configuration from scratch and forgot to initialize channel - use default if (this.configuration.TelemetryChannel == null) { this.configuration.TelemetryChannel = new InMemoryChannel(); } // invokes the Process in the first processor in the chain this.configuration.TelemetryProcessorChain.Process(telemetry); #if !CORE_PCL // logs rich payload ETW event for any partners to process it RichPayloadEventSource.Log.Process(telemetry); #endif } }
/// <summary> /// Process a collected telemetry item. /// </summary> /// <param name="item">A collected Telemetry item.</param> public void Process(ITelemetry item) { if (this.SamplingPercentage < 100.0 - 1.0E-12) { var samplingSupportingTelemetry = item as ISupportSampling; if (samplingSupportingTelemetry != null) { var excludedTypesHashSetRef = this.excludedTypesHashSet; var includedTypesHashSetRef = this.includedTypesHashSet; if (excludedTypesHashSetRef.Count > 0 && excludedTypesHashSetRef.Contains(item.GetType())) { if (TelemetryChannelEventSource.Log.IsVerboseEnabled) { TelemetryChannelEventSource.Log.SamplingSkippedByType(item.ToString()); } } else if (includedTypesHashSetRef.Count > 0 && !includedTypesHashSetRef.Contains(item.GetType())) { if (TelemetryChannelEventSource.Log.IsVerboseEnabled) { TelemetryChannelEventSource.Log.SamplingSkippedByType(item.ToString()); } } else if (!samplingSupportingTelemetry.SamplingPercentage.HasValue) { samplingSupportingTelemetry.SamplingPercentage = this.SamplingPercentage; if (!this.IsSampledIn(item)) { if (TelemetryChannelEventSource.Log.IsVerboseEnabled) { TelemetryChannelEventSource.Log.ItemSampledOut(item.ToString()); } TelemetryDebugWriter.WriteTelemetry(item, this.GetType().Name); return; } } } } this.Next.Process(item); }
/// <summary> /// Process a collected telemetry item. /// </summary> /// <param name="item">A collected Telemetry item.</param> public void Process(ITelemetry item) { if (this.SamplingPercentage < 100.0 - 1.0E-12) { var samplingSupportingTelemetry = item as ISupportSampling; if (samplingSupportingTelemetry != null) { var excludedTypesHashSetRef = this.excludedTypesHashSet; if (excludedTypesHashSetRef.Count > 0 && excludedTypesHashSetRef.Contains(item.GetType())) { if (TelemetryChannelEventSource.Log.IsVerboseEnabled) { TelemetryChannelEventSource.Log.SamplingSkippedByType(item.ToString()); } } else { // set sampling percentage on telemetry item, current codebase assumes it is the only one updating SamplingPercentage. samplingSupportingTelemetry.SamplingPercentage = this.SamplingPercentage; if (!this.IsSampledIn(item)) { if (TelemetryChannelEventSource.Log.IsVerboseEnabled) { TelemetryChannelEventSource.Log.ItemSampledOut(item.ToString()); } TelemetryDebugWriter.WriteTelemetry(item, this.GetType().Name); return; } } } } this.Next.Process(item); }
/// <summary> /// Process a collected telemetry item. /// </summary> /// <param name="item">A collected Telemetry item.</param> public void Process(ITelemetry item) { double samplingPercentage = this.SamplingPercentage; //// If sampling rate is 100% and we aren't distinguishing between evaluated/unevaluated items, there is nothing to do: if (samplingPercentage >= 100.0 - 1.0E-12 && this.SampledNext.Equals(this.UnsampledNext)) { this.HandlePossibleProactiveSampling(item, samplingPercentage); return; } //// So sampling rate is not 100%, or we must evaluate further var advancedSamplingSupportingTelemetry = item as ISupportAdvancedSampling; // If someone implemented ISupportSampling and hopes that SamplingTelemetryProcessor will continue to work for them: var samplingSupportingTelemetry = advancedSamplingSupportingTelemetry ?? item as ISupportSampling; //// If null was passed in as item or if sampling not supported in general, do nothing: if (samplingSupportingTelemetry == null) { this.UnsampledNext.Process(item); return; } //// If telemetry was excluded by type, do nothing: if (advancedSamplingSupportingTelemetry != null && !this.IsSamplingApplicable(advancedSamplingSupportingTelemetry.ItemTypeFlag)) { if (TelemetryChannelEventSource.IsVerboseEnabled) { TelemetryChannelEventSource.Log.SamplingSkippedByType(item.ToString()); } this.UnsampledNext.Process(item); return; } //// If telemetry was already sampled, do nothing: bool itemAlreadySampled = samplingSupportingTelemetry.SamplingPercentage.HasValue; if (itemAlreadySampled) { this.UnsampledNext.Process(item); return; } //// Ok, now we can actually sample: samplingSupportingTelemetry.SamplingPercentage = samplingPercentage; bool isSampledIn; // if this is executed in adaptive sampling processor (rate ratio has value), // and item supports proactive sampling and was sampled in before, we'll give it more weight if (this.ProactiveSamplingPercentage.HasValue && advancedSamplingSupportingTelemetry != null && advancedSamplingSupportingTelemetry.ProactiveSamplingDecision == SamplingDecision.SampledIn) { // if current rate of proactively sampled-in telemetry is too high, ProactiveSamplingPercentage is low: // we'll sample in as much proactively sampled in items as we can (based on their sampling score) // so that we still keep target rate. // if current rate of proactively sampled-in telemetry is less that configured, ProactiveSamplingPercentage // is high - it could be > 100 - and we'll sample in all items with proactive SampledIn decision (plus some more in else branch). isSampledIn = SamplingScoreGenerator.GetSamplingScore(item) < this.ProactiveSamplingPercentage; } else { isSampledIn = SamplingScoreGenerator.GetSamplingScore(item) < samplingPercentage; } if (isSampledIn) { if (advancedSamplingSupportingTelemetry != null) { this.HandlePossibleProactiveSampling(item, samplingPercentage, advancedSamplingSupportingTelemetry); } else { this.SampledNext.Process(item); } } else { if (TelemetryChannelEventSource.IsVerboseEnabled) { TelemetryChannelEventSource.Log.ItemSampledOut(item.ToString()); } TelemetryDebugWriter.WriteTelemetry(item, nameof(SamplingTelemetryProcessor)); } }
/// <summary> /// Process a collected telemetry item. /// </summary> /// <param name="item">A collected Telemetry item.</param> public void Process(ITelemetry item) { double samplingPercentage = this.SamplingPercentage; //// If sampling rate is 100% and we aren't distinguishing between evaluated/unevaluated items, there is nothing to do: if (this.SampledNext.Equals(this.UnsampledNext) && samplingPercentage >= 100.0 - 1.0E-12) { this.SampledNext.Process(item); return; } //// So sampling rate is not 100%, or we must evaluate further //// If null was passed in as item or if sampling not supported in general, do nothing: var samplingSupportingTelemetry = item as ISupportSampling; if (samplingSupportingTelemetry == null) { this.UnsampledNext.Process(item); return; } //// If telemetry was excluded by type, do nothing: if (!this.IsSamplingApplicable(item.GetType())) { if (TelemetryChannelEventSource.IsVerboseEnabled) { TelemetryChannelEventSource.Log.SamplingSkippedByType(item.ToString()); } this.UnsampledNext.Process(item); return; } //// If telemetry was already sampled, do nothing: bool itemAlreadySampled = samplingSupportingTelemetry.SamplingPercentage.HasValue; if (itemAlreadySampled) { this.UnsampledNext.Process(item); return; } //// Ok, now we can actually sample: samplingSupportingTelemetry.SamplingPercentage = samplingPercentage; bool isSampledIn = SamplingScoreGenerator.GetSamplingScore(item) < samplingPercentage; if (isSampledIn) { this.SampledNext.Process(item); } else { if (TelemetryChannelEventSource.IsVerboseEnabled) { TelemetryChannelEventSource.Log.ItemSampledOut(item.ToString()); } TelemetryDebugWriter.WriteTelemetry(item, this.GetType().Name); } }
/// <summary> /// Process a collected telemetry item. /// </summary> /// <param name="item">A collected Telemetry item.</param> public void Process(ITelemetry item) { double samplingPercentage = this.SamplingPercentage; //// If sampling rate is 100% and we aren't distinguishing between evaluated/unevaluated items, there is nothing to do: if (samplingPercentage >= 100.0 - 1.0E-12 && this.SampledNext.Equals(this.UnsampledNext)) { this.HandlePossibleProactiveSampling(item, samplingPercentage); return; } //// So sampling rate is not 100%, or we must evaluate further var advancedSamplingSupportingTelemetry = item as ISupportAdvancedSampling; // If someone implemented ISupportSampling and hopes that SamplingTelemetryProcessor will continue to work for them: var samplingSupportingTelemetry = advancedSamplingSupportingTelemetry ?? item as ISupportSampling; //// If null was passed in as item or if sampling not supported in general, do nothing: if (samplingSupportingTelemetry == null) { this.UnsampledNext.Process(item); return; } //// If telemetry was excluded by type, do nothing: if (advancedSamplingSupportingTelemetry != null && !this.IsSamplingApplicable(advancedSamplingSupportingTelemetry.ItemTypeFlag)) { if (TelemetryChannelEventSource.IsVerboseEnabled) { TelemetryChannelEventSource.Log.SamplingSkippedByType(item.ToString()); } this.UnsampledNext.Process(item); return; } //// If telemetry was already sampled, do nothing: bool itemAlreadySampled = samplingSupportingTelemetry.SamplingPercentage.HasValue; if (itemAlreadySampled) { this.UnsampledNext.Process(item); return; } //// Ok, now we can actually sample: samplingSupportingTelemetry.SamplingPercentage = samplingPercentage; bool isSampledIn = SamplingScoreGenerator.GetSamplingScore(item) < samplingPercentage; if (isSampledIn) { if (advancedSamplingSupportingTelemetry != null) { this.HandlePossibleProactiveSampling(item, samplingPercentage, advancedSamplingSupportingTelemetry); } else { this.SampledNext.Process(item); } } else { if (TelemetryChannelEventSource.IsVerboseEnabled) { TelemetryChannelEventSource.Log.ItemSampledOut(item.ToString()); } TelemetryDebugWriter.WriteTelemetry(item, nameof(SamplingTelemetryProcessor)); } }