-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce enable live metrics to distro (#35566)
- Loading branch information
Showing
10 changed files
with
177 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sdk/monitor/azure-monitor-opentelemetry/samples/metrics/live_metrics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
""" | ||
This example shows how configure live metrics to be enabled. It sets up a minimal example of sending dependency, | ||
trace and exception telemetry to demonstrate the capabilities and collection set of live metrics. | ||
""" | ||
import logging | ||
import requests | ||
import time | ||
|
||
from azure.monitor.opentelemetry import configure_azure_monitor | ||
from opentelemetry import trace | ||
|
||
from opentelemetry.sdk.resources import Resource | ||
|
||
configure_azure_monitor( | ||
resource=Resource.create({ | ||
"service.name": "live_metrics_service", | ||
"service.instance.id": "qp_instance_id", | ||
}), | ||
logger_name=__name__, | ||
enable_live_metrics=True, # Enable live metrics configuration | ||
) | ||
|
||
tracer = trace.get_tracer(__name__) | ||
logger = logging.getLogger(__name__) | ||
|
||
# Continuously send metrics | ||
while True: | ||
with tracer.start_as_current_span("parent"): | ||
logger.warning("sending request") | ||
response = requests.get("https://azure.microsoft.com/", timeout=5) | ||
try: | ||
val = 1 / 0 | ||
print(val) | ||
except ZeroDivisionError: | ||
logger.error("Error: Division by zero", stack_info=True, exc_info=True) | ||
time.sleep(2) |
Oops, something went wrong.