-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfeature_variant_sample_with_telemetry.py
36 lines (28 loc) · 1.25 KB
/
feature_variant_sample_with_telemetry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import json
import os
import sys
from random_filter import RandomFilter
from featuremanagement import FeatureManager
from featuremanagement.azuremonitor import publish_telemetry, track_event
try:
from azure.monitor.opentelemetry import configure_azure_monitor
# Configure Azure Monitor
configure_azure_monitor(connection_string=os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"))
except ImportError:
pass
script_directory = os.path.dirname(os.path.abspath(sys.argv[0]))
with open(script_directory + "/formatted_feature_flags.json", "r", encoding="utf-8") as f:
feature_flags = json.load(f)
# Initialize the feature manager with telemetry callback
feature_manager = FeatureManager(
feature_flags, feature_filters=[RandomFilter()], on_feature_evaluated=publish_telemetry
)
# Evaluate the feature flag for the user
print(feature_manager.get_variant("TestVariants", "Adam").configuration)
# Track an event
track_event("TestEvent", "Adam")