Registry Mirror
搜索
Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Files
Expand file tree
main
Breadcrumbs
FeatureManagement-Python
/
samples
/
feature_variant_sample_with_telemetry.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
37 lines (29 loc) · 1.31 KB
main
Breadcrumbs
FeatureManagement-Python
/
samples
/
feature_variant_sample_with_telemetry.py
Copy path
Top
File metadata and controls
Code
Blame
37 lines (29 loc) · 1.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
37
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""Sample demonstrating feature variants with telemetry."""
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")
You can’t perform that action at this time.