|
6 | 6 | from typing import Annotated |
7 | 7 |
|
8 | 8 | from agent_framework import ChatAgent |
| 9 | +from agent_framework.observability import create_resource, enable_instrumentation |
9 | 10 | from agent_framework.openai import OpenAIChatClient |
10 | 11 | from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider |
| 12 | +from azure.monitor.opentelemetry import configure_azure_monitor |
11 | 13 | from dotenv import load_dotenv |
12 | 14 | from pydantic import Field |
13 | 15 | from rich import print |
|
19 | 21 | logger = logging.getLogger(__name__) |
20 | 22 | logger.setLevel(logging.INFO) |
21 | 23 |
|
22 | | -# Configura la exportación de OpenTelemetry a Azure Application Insights (si la cadena de conexión está configurada) |
| 24 | +# Configura la exportación de OpenTelemetry a Azure Application Insights |
| 25 | +# Configura APPLICATIONINSIGHTS_CONNECTION_STRING en .env (ejecuta 'azd provision' o copia desde el Portal de Azure) |
23 | 26 | load_dotenv(override=True) |
24 | | -appinsights_connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING") |
25 | | -if appinsights_connection_string: |
26 | | - from agent_framework.observability import create_resource, enable_instrumentation |
27 | | - from azure.monitor.opentelemetry import configure_azure_monitor |
28 | | - |
29 | | - os.environ.setdefault("OTEL_SERVICE_NAME", "agent-framework-demo") |
30 | | - configure_azure_monitor( |
31 | | - connection_string=appinsights_connection_string, |
32 | | - resource=create_resource(), |
33 | | - enable_live_metrics=True, |
34 | | - ) |
35 | | - enable_instrumentation(enable_sensitive_data=True) |
36 | | - logger.info("Exportación a Azure Application Insights habilitada") |
37 | | -else: |
38 | | - logger.info( |
39 | | - "Configura APPLICATIONINSIGHTS_CONNECTION_STRING en .env para exportar telemetría a Azure Application " |
40 | | - "Insights. Ejecuta 'azd provision' para provisionar y configurar Application Insights automáticamente, " |
41 | | - "o configura la cadena de conexión manualmente desde el Portal de Azure." |
42 | | - ) |
| 27 | +configure_azure_monitor( |
| 28 | + connection_string=os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"], |
| 29 | + resource=create_resource(), |
| 30 | + enable_live_metrics=True, |
| 31 | +) |
| 32 | +enable_instrumentation(enable_sensitive_data=True) |
| 33 | +logger.info("Exportación a Azure Application Insights habilitada") |
43 | 34 |
|
44 | 35 | # Configura el cliente de OpenAI según el entorno |
45 | 36 | API_HOST = os.getenv("API_HOST", "github") |
|
0 commit comments