Skip to content

Commit

Permalink
Removed TrackMetric extension for now
Browse files Browse the repository at this point in the history
  • Loading branch information
rossgrambo committed Jan 16, 2024
1 parent 8560fb9 commit 0168adf
Showing 1 changed file with 2 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void TrackEvent(this TelemetryClient telemetryClient, string event
properties = new Dictionary<string, string>();
}

AddTargetingProperties(properties, targetingContext);
properties["TargetingId"] = targetingContext.UserId;

telemetryClient.TrackEvent(eventName, properties, metrics);
}
Expand All @@ -41,56 +41,17 @@ public static void TrackEvent(this TelemetryClient telemetryClient, EventTelemet
telemetry = new EventTelemetry();
}

AddTargetingProperties(telemetry.Properties, targetingContext);
telemetry.Properties["TargetingId"] = targetingContext.UserId;

telemetryClient.TrackEvent(telemetry);
}

/// <summary>
/// Extension method to track a metric with <see cref="TargetingContext"/>.
/// </summary>
public static void TrackMetric(this TelemetryClient telemetryClient, string name, double value, TargetingContext targetingContext, IDictionary<string, string> properties = null)
{
ValidateTargetingContext(targetingContext);

if (properties == null)
{
properties = new Dictionary<string, string>();
}

AddTargetingProperties(properties, targetingContext);

telemetryClient.TrackMetric(name, value, properties);
}

/// <summary>
/// Extension method to track a <see cref="MetricTelemetry"/> with <see cref="TargetingContext"/>.
/// </summary>
public static void TrackMetric(this TelemetryClient telemetryClient, MetricTelemetry telemetry, TargetingContext targetingContext)
{
ValidateTargetingContext(targetingContext);

if (telemetry == null)
{
telemetry = new MetricTelemetry();
}

AddTargetingProperties(telemetry.Properties, targetingContext);

telemetryClient.TrackMetric(telemetry);
}

private static void ValidateTargetingContext(TargetingContext targetingContext)
{
if (targetingContext == null)
{
throw new ArgumentNullException(nameof(targetingContext));
}
}

private static void AddTargetingProperties(IDictionary<string, string> properties, TargetingContext targetingContext)
{
properties["TargetingId"] = targetingContext.UserId;
}
}
}

0 comments on commit 0168adf

Please sign in to comment.