How do I connect to Azure Monitor Opentelemetry via Corporate Proxy

Shahnawaz 41 Reputation points
2024-06-20T07:10:49.6633333+00:00

May I know how can we connect to Azure Insights using Azure Monitor Opentelemetry library via corporates proxy. I have read the document and also tried to pass the proxies = {"http/https": "hostname:port"} inside configure_azure_monitor(connection_string="APPLICATIONINSIGHTS_CONNECTION_STRING",proxies={"https":"hostname:port"}) but it never worked. May seek you help with the below code.

Sample Example: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples

from logging import INFO, getLogger
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
    # Set logger_name to the name of the logger you want to capture logging telemetry with
    logger_name="my_application_logger",
)

# Logging calls with this logger will be tracked
logger = getLogger("my_application_logger")
logger.setLevel(INFO)

# Logging calls with any logger that is a child logger will also be tracked
logger_child = getLogger("my-application_logger.module")
logger_child.setLevel(INFO)

# Logging calls with this logger will not be tracked
logger_not_tracked = getLogger("not_my_application_logger")
logger_not_tracked.setLevel(INFO)

logger.info("info log")
logger.warning("warning log")
logger.error("error log")

logger.info("info log")
logger.warning("warning log")
logger.error("error log")

logger_not_tracked.info("info log2")
logger_not_tracked.warning("warning log2")
logger_not_tracked.error("error log2")

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,033 questions
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 21,246 Reputation points
    2024-07-02T10:20:04.03+00:00

    @Shahnawaz, Users can setup proxypolicy via azure-core apis. configure_azure_monitor api passes the policies to azure monitor client via kwargs. An example of this can be shown below:

    from azure.monitor.opentelemetry import configure_azure_monitor 
    from opentelemetry import trace 
    from azure.core.pipeline import policies  
    
    configure_azure_monitor(      
    	proxy_policy=policies.ProxyPolicy(
    		proxies={"http": "http://10.10.1.10:1234"}     
    	) 
    ) 
    tracer = trace.get_tracer(__name__)
    with tracer.start_as_current_span("hello"):
         print("Hello, World!")  
    input()
    

    For more details, see the documentation for ProxyPolicy Class of the azure.core.pipeline package.

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful