Example #1
0
 def test_invalid_key_suffix(self):
     self.assertRaises(
         ValueError,
         lambda: ConnectionStringParser(
             connection_string=
             "InstrumentationKey=1234abcd-5678-4efa-8abc-1234567890abtest"),
     )
Example #2
0
 def test_invalid_key_section5_length(self):
     self.assertRaises(
         ValueError,
         lambda: ConnectionStringParser(
             connection_string=
             "InstrumentationKey=234abcd-678-4efa-8abc-11234567890ab"),
     )
Example #3
0
 def test_process_options_ikey_env_cs(self):
     os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] = (
         "Authorization=ikey;InstrumentationKey=" +
         self._valid_instrumentation_key)
     os.environ["APPINSIGHTS_INSTRUMENTATIONKEY"] = "101112"
     parser = ConnectionStringParser(connection_string=None)
     self.assertEqual(parser.instrumentation_key,
                      self._valid_instrumentation_key)
Example #4
0
    def __init__(self, **kwargs: Any) -> None:
        """Azure Monitor base exporter for OpenTelemetry.

        :param options: Exporter configuration options.
        :type options: ~azure.opentelemetry.exporter.azuremonitor.options.ExporterOptions
        :keyword str connection_string: The connection string to be used for authentication
        :rtype: None
        """
        options = ExporterOptions(**kwargs)
        parsed_connection_string = ConnectionStringParser(
            options.connection_string)

        self._instrumentation_key = parsed_connection_string.instrumentation_key
        self._timeout = 10.0  # networking timeout in seconds

        temp_suffix = self._instrumentation_key or ""
        default_storage_path = os.path.join(tempfile.gettempdir(),
                                            TEMPDIR_PREFIX + temp_suffix)
        config = AzureMonitorClientConfiguration(
            parsed_connection_string.endpoint, **kwargs)
        policies = [
            RequestIdPolicy(**kwargs),
            config.headers_policy,
            config.user_agent_policy,
            config.proxy_policy,
            ContentDecodePolicy(**kwargs),
            config.redirect_policy,
            config.retry_policy,
            config.authentication_policy,
            config.custom_hook_policy,
            config.logging_policy,
            # Explicitly disabling to avoid infinite loop of Span creation when data is exported
            # DistributedTracingPolicy(**kwargs),
            config.http_logging_policy or HttpLoggingPolicy(**kwargs)
        ]
        self.client = AzureMonitorClient(
            host=parsed_connection_string.endpoint,
            connection_timeout=self._timeout,
            policies=policies,
            **kwargs)
        self.storage = LocalFileStorage(
            path=default_storage_path,
            max_size=50 * 1024 * 1024,  # Maximum size in bytes.
            maintenance_period=60,  # Maintenance interval in seconds.
            retention_period=7 * 24 * 60 * 60,  # Retention period in seconds
        )
Example #5
0
 def test_invalid_key_empty(self):
     self.assertRaises(ValueError,
                       lambda: ConnectionStringParser(connection_string=""))
Example #6
0
 def test_parse_connection_string_suffix_no_location(self):
     parser = ConnectionStringParser(
         connection_string=
         "Authorization=ikey;EndpointSuffix=123;InstrumentationKey=" +
         self._valid_instrumentation_key, )
     self.assertEqual(parser.endpoint, "https://dc.123")
Example #7
0
 def test_parse_connection_string_invalid_auth(self):
     self.assertRaises(
         ValueError,
         lambda: ConnectionStringParser(connection_string=
                                        "Authorization=asd", ),
     )
Example #8
0
 def test_parse_connection_string_invalid(self):
     self.assertRaises(
         ValueError,
         lambda: ConnectionStringParser(connection_string="asd"))
Example #9
0
 def test_process_options_endpoint_default(self):
     parser = ConnectionStringParser(
         connection_string=self._valid_connection_string, )
     self.assertEqual(parser.endpoint,
                      "https://dc.services.visualstudio.com")
Example #10
0
 def test_process_options_endpoint_env_cs(self):
     os.environ[
         "APPLICATIONINSIGHTS_CONNECTION_STRING"] = "Authorization=ikey;IngestionEndpoint=456;InstrumentationKey=" + self._valid_instrumentation_key
     parser = ConnectionStringParser(connection_string=None, )
     self.assertEqual(parser.endpoint, "456")
Example #11
0
 def test_validate_connection_String(self):
     parser = ConnectionStringParser(
         connection_string=self._valid_connection_string)
     self.assertEqual(parser._connection_string,
                      self._valid_connection_string)
Example #12
0
 def test_process_options_ikey_env_ikey(self):
     os.environ[
         "APPINSIGHTS_INSTRUMENTATIONKEY"] = self._valid_instrumentation_key
     parser = ConnectionStringParser(connection_string=None)
     self.assertEqual(parser.instrumentation_key,
                      self._valid_instrumentation_key)