-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Introduce enable live metrics to distro #35566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6f33e54
add live metrics to distro
lzchen 33d7d22
docstring
lzchen 1fe4034
lint
lzchen 1bc37b7
lint
lzchen f3d8f10
Update _configure.py
lzchen 8367b8a
Update _configure.py
lzchen 0af2302
default
lzchen 0de60a9
Update _configure.py
lzchen a07de6c
typing
lzchen 04b1de1
lint
lzchen 6c06302
Update _configure.py
lzchen b2896ce
lint
lzchen 0392bc1
Update _configure.py
lzchen 2c2c35f
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen 3a683e8
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen 75fae7d
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen 2480421
Update CHANGELOG.md
lzchen 58c0bff
default
lzchen df3088f
spell
lzchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -60,6 +60,7 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to | |
| Parameter | Description | Environment Variable | | ||
|-------------------|----------------------------------------------------|----------------------| | ||
| `connection_string` | The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. | `APPLICATIONINSIGHTS_CONNECTION_STRING` | | ||
| `enable_live_metrics` | Enable [live metrics][application_insights_live_metrics] feature. Defaults to `False`. | `N/A` | | ||
| `logger_name` | The name of the [Python logger][python_logger] under which telemetry is collected. | `N/A` | | ||
| `instrumentation_options` | A nested dictionary that determines which instrumentations to enable or disable. Instrumentations are referred to by their [Library Names](#officially-supported-instrumentations). For example, `{"azure_sdk": {"enabled": False}, "flask": {"enabled": False}, "django": {"enabled": True}}` will disable Azure Core Tracing and the Flask instrumentation but leave Django and the other default instrumentations enabled. The `OTEL_PYTHON_DISABLED_INSTRUMENTATIONS` environment variable explained below can also be used to disable instrumentations. | `N/A` | | ||
| `resource` | Specifies the OpenTelemetry [Resource][ot_spec_resource] associated with your application. Passed in [Resource Attributes][ot_spec_resource_attributes] take priority over default attributes and those from [Resource Detectors][ot_python_resource_detectors]. | [OTEL_SERVICE_NAME][ot_spec_service_name], [OTEL_RESOURCE_ATTRIBUTES][ot_spec_resource_attributes], [OTEL_EXPERIMENTAL_RESOURCE_DETECTORS][ot_python_resource_detectors] | | ||
|
@@ -210,6 +211,7 @@ contact [[email protected]](mailto:[email protected]) with any additio | |
[azure_monitor_opentelemetry_exporters]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry-exporter#microsoft-opentelemetry-exporter-for-azure-monitor | ||
[azure_portal]: https://portal.azure.com | ||
[azure_sub]: https://azure.microsoft.com/free/ | ||
[application_insights_live_metrics]: https://learn.microsoft.com/azure/azure-monitor/app/live-stream | ||
[application_insights_namespace]: https://learn.microsoft.com/azure/azure-monitor/app/app-insights-overview | ||
[application_insights_sampling]: https://learn.microsoft.com/azure/azure-monitor/app/sampling | ||
[connection_string_doc]: https://learn.microsoft.com/azure/azure-monitor/app/sdk-connection-string | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.