Esempio n. 1
0
        protected BaseOtlpGrpcExportClient(OtlpExporterOptions options)
        {
            Guard.Null(options, nameof(options));
            Guard.InvalidTimeout(options.TimeoutMilliseconds, nameof(options.TimeoutMilliseconds));

            this.Options = options;
            this.Headers = options.GetMetadataFromHeaders();
        }
        protected BaseOtlpGrpcExportClient(OtlpExporterOptions options)
        {
            Guard.ThrowIfNull(options, nameof(options));
            Guard.ThrowIfInvalidTimeout(options.TimeoutMilliseconds, nameof(options.TimeoutMilliseconds));

            ExporterClientValidation.EnsureUnencryptedSupportIsEnabled(options);

            this.Options = options;
            this.Headers = options.GetMetadataFromHeaders();
        }
        protected BaseOtlpGrpcExportClient(OtlpExporterOptions options)
        {
            Guard.ThrowIfNull(options);
            Guard.ThrowIfInvalidTimeout(options.TimeoutMilliseconds);

            ExporterClientValidation.EnsureUnencryptedSupportIsEnabled(options);

            this.Endpoint            = new UriBuilder(options.Endpoint).Uri;
            this.Headers             = options.GetMetadataFromHeaders();
            this.TimeoutMilliseconds = options.TimeoutMilliseconds;
        }
        [InlineData("key1=value1;key2=value2", new string[] { "key1" }, new string[] { "value1;key2=value2" })] // semicolon is not treated as a delimeter (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables)
        public void GetMetadataFromHeadersWorksCorrectFormat(string headers, string[] keys, string[] values)
        {
            var options = new OtlpExporterOptions();

            options.Headers = headers;
            var metadata = options.GetMetadataFromHeaders();

            Assert.Equal(keys.Length, metadata.Count);

            for (int i = 0; i < keys.Length; i++)
            {
                Assert.Contains(metadata, entry => entry.Key == keys[i] && entry.Value == values[i]);
            }
        }
        public void GetMetadataFromHeadersThrowsExceptionOnInvalidFormat(string headers)
        {
            try
            {
                var options = new OtlpExporterOptions();
                options.Headers = headers;
                var metadata = options.GetMetadataFromHeaders();
            }
            catch (Exception ex)
            {
                Assert.IsType <ArgumentException>(ex);
                Assert.Equal("Headers provided in an invalid format.", ex.Message);
                return;
            }

            throw new XunitException("GetMetadataFromHeaders did not throw an exception for invalid input headers");
        }