Ejemplo n.º 1
0
 def test_invalid_key_suffix(self):
     self.assertRaises(
         ValueError,
         lambda:
         ExporterOptions(instrumentation_key=
                         "1234abcd-5678-4efa-8abc-1234567890abtest"),
     )
Ejemplo n.º 2
0
 def test_parse_connection_string_suffix(self):
     options = ExporterOptions(
         connection_string=
         "Authorization=ikey;EndpointSuffix=123;Location=US",
         instrumentation_key=self._valid_instrumentation_key,
     )
     self.assertEqual(options.endpoint, "https://US.dc.123")
Ejemplo n.º 3
0
 def test_process_options_proxies_default(self):
     options = ExporterOptions(
         connection_string=None,
         instrumentation_key=self._valid_instrumentation_key,
         proxies={},
     )
     self.assertEqual(options.proxies, {})
Ejemplo n.º 4
0
 def test_process_options_proxies_set_proxies(self):
     options = ExporterOptions(
         connection_string=None,
         instrumentation_key=self._valid_instrumentation_key,
         proxies={"https": "https://test-proxy.com"},
     )
     self.assertEqual(options.proxies, {"https": "https://test-proxy.com"})
Ejemplo n.º 5
0
 def test_process_options_ikey_env_ikey(self):
     os.environ[
         "APPINSIGHTS_INSTRUMENTATIONKEY"] = self._valid_instrumentation_key
     options = ExporterOptions(connection_string=None,
                               instrumentation_key=None)
     self.assertEqual(options.instrumentation_key,
                      self._valid_instrumentation_key)
Ejemplo n.º 6
0
 def test_process_options_endpoint_default(self):
     options = ExporterOptions(
         connection_string=None,
         instrumentation_key=self._valid_instrumentation_key,
     )
     self.assertEqual(options.endpoint,
                      "https://dc.services.visualstudio.com")
Ejemplo n.º 7
0
 def test_parse_connection_string_invalid_auth(self):
     self.assertRaises(
         ValueError,
         lambda: ExporterOptions(
             connection_string="Authorization=asd",
             instrumentation_key=self._valid_instrumentation_key,
         ),
     )
Ejemplo n.º 8
0
 def test_process_options_endpoint_env_cs(self):
     os.environ[
         "APPLICATIONINSIGHTS_CONNECTION_STRING"] = "Authorization=ikey;IngestionEndpoint=456"
     options = ExporterOptions(
         connection_string=None,
         instrumentation_key=self._valid_instrumentation_key,
     )
     self.assertEqual(options.endpoint, "456")
Ejemplo n.º 9
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"
     options = ExporterOptions(connection_string=None,
                               instrumentation_key=None)
     self.assertEqual(options.instrumentation_key,
                      self._valid_instrumentation_key)
Ejemplo n.º 10
0
 def __init__(self, **options):
     self._telemetry_processors = []
     self.options = ExporterOptions(**options)
     retry_policy = RetryPolicy(timeout=self.options.timeout)
     proxy_policy = ProxyPolicy(proxies=self.options.proxies)
     self.client = AzureMonitorClient(
         self.options.endpoint, proxy_policy=proxy_policy, retry_policy=retry_policy)
     self.storage = LocalFileStorage(
         path=self.options.storage_path,
         max_size=self.options.storage_max_size,
         maintenance_period=self.options.storage_maintenance_period,
         retention_period=self.options.storage_retention_period,
     )
Ejemplo n.º 11
0
    def __init__(self, **options):
        options = ExporterOptions(**options)
        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)
        retry_policy = RetryPolicy(timeout=self._timeout)
        self.client = AzureMonitorClient(parsed_connection_string.endpoint,
                                         retry_policy=retry_policy)
        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
        )
Ejemplo n.º 12
0
 def test_invalid_key_section5_length(self):
     self.assertRaises(
         ValueError,
         lambda: ExporterOptions(instrumentation_key=
                                 "234abcd-678-4efa-8abc-11234567890ab"),
     )
Ejemplo n.º 13
0
 def test_invalid_key_empty(self):
     self.assertRaises(ValueError,
                       lambda: ExporterOptions(instrumentation_key=""))
Ejemplo n.º 14
0
 def test_parse_connection_string_invalid(self):
     self.assertRaises(ValueError,
                       lambda: ExporterOptions(connection_string="asd"))
Ejemplo n.º 15
0
 def test_validate_instrumentation_key(self):
     options = ExporterOptions(
         instrumentation_key=self._valid_instrumentation_key)
     self.assertEqual(options.instrumentation_key,
                      self._valid_instrumentation_key)