|
1 | 1 | // Copyright (c) Microsoft Corporation. |
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | | -import { EvaluationResult, createFeatureEvaluationEventProperties, TargetingContextAccessor } from "@microsoft/feature-management"; |
| 4 | +import { EvaluationResult, createFeatureEvaluationEventProperties, ITargetingContextAccessor } from "@microsoft/feature-management"; |
5 | 5 | import { TelemetryClient, Contracts } from "applicationinsights"; |
6 | 6 |
|
7 | 7 | const TARGETING_ID = "TargetingId"; |
@@ -45,14 +45,14 @@ export function trackEvent(client: TelemetryClient, targetingId: string, event: |
45 | 45 | * @param targetingContextAccessor The accessor function to get the targeting context. |
46 | 46 | * @returns A telemetry processor that attaches targeting id to telemetry envelopes. |
47 | 47 | */ |
48 | | -export function createTargetingTelemetryProcessor(targetingContextAccessor: TargetingContextAccessor): (envelope: Contracts.EnvelopeTelemetry) => boolean { |
| 48 | +export function createTargetingTelemetryProcessor(targetingContextAccessor: ITargetingContextAccessor): (envelope: Contracts.EnvelopeTelemetry) => boolean { |
49 | 49 | return (envelope: Contracts.EnvelopeTelemetry) => { |
50 | | - const targetingContext = targetingContextAccessor(); |
| 50 | + const targetingContext = targetingContextAccessor.getTargetingContext(); |
51 | 51 | if (targetingContext?.userId === undefined) { |
52 | 52 | console.warn("Targeting id is undefined."); |
53 | 53 | } |
54 | 54 | envelope.data.baseData = envelope.data.baseData || {}; |
55 | | - envelope.data.baseData.properties = {...envelope.data.baseData.properties, [TARGETING_ID]: targetingContext.userId}; |
| 55 | + envelope.data.baseData.properties = {...envelope.data.baseData.properties, [TARGETING_ID]: targetingContext?.userId || ""}; |
56 | 56 | return true; // If a telemetry processor returns false, that telemetry item isn't sent. |
57 | 57 | }; |
58 | 58 | } |
0 commit comments