Esempio n. 1
0
        public void LoadString_NoValue()
        {
            bool actualBool = EnvironmentVariableHelper.LoadString(EnvVar, out string actualValue);

            Assert.False(actualBool);
            Assert.Null(actualValue);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OtlpExporterOptions"/> class.
        /// </summary>
        public OtlpExporterOptions()
        {
            if (EnvironmentVariableHelper.LoadUri(EndpointEnvVarName, out Uri endpoint))
            {
                this.Endpoint = endpoint;
            }

            if (EnvironmentVariableHelper.LoadString(HeadersEnvVarName, out string headersEnvVar))
            {
                this.Headers = headersEnvVar;
            }

            if (EnvironmentVariableHelper.LoadNumeric(TimeoutEnvVarName, out int timeout))
            {
                this.TimeoutMilliseconds = timeout;
            }

            if (EnvironmentVariableHelper.LoadString(ProtocolEnvVarName, out string protocolEnvVar))
            {
                var protocol = protocolEnvVar.ToOtlpExportProtocol();
                if (protocol.HasValue)
                {
                    this.Protocol = protocol.Value;
                }
                else
                {
                    throw new FormatException($"{ProtocolEnvVarName} environment variable has an invalid value: '${protocolEnvVar}'");
                }
            }
        }
Esempio n. 3
0
        public JaegerExporterOptions()
        {
            if (EnvironmentVariableHelper.LoadString(OTelProtocolEnvVarKey, out string protocolEnvVar))
            {
                var protocol = protocolEnvVar.ToJaegerExportProtocol();

                if (protocol.HasValue)
                {
                    this.Protocol = protocol.Value;
                }
                else
                {
                    throw new FormatException($"{OTelProtocolEnvVarKey} environment variable has an invalid value: '{protocolEnvVar}'");
                }
            }

            if (EnvironmentVariableHelper.LoadString(OTelAgentHostEnvVarKey, out string agentHostEnvVar))
            {
                this.AgentHost = agentHostEnvVar;
            }

            if (EnvironmentVariableHelper.LoadNumeric(OTelAgentPortEnvVarKey, out int agentPortEnvVar))
            {
                this.AgentPort = agentPortEnvVar;
            }

            if (EnvironmentVariableHelper.LoadString(OTelEndpointEnvVarKey, out string endpointEnvVar) &&
                Uri.TryCreate(endpointEnvVar, UriKind.Absolute, out Uri endpoint))
            {
                this.Endpoint = endpoint;
            }
        }
Esempio n. 4
0
        public void LoadString()
        {
            const string value = "something";

            Environment.SetEnvironmentVariable(EnvVar, value);

            bool actualBool = EnvironmentVariableHelper.LoadString(EnvVar, out string actualValue);

            Assert.True(actualBool);
            Assert.Equal(value, actualValue);
        }
Esempio n. 5
0
        public Resource Detect()
        {
            var resource = Resource.Empty;

            if (EnvironmentVariableHelper.LoadString(EnvVarKey, out string envResourceAttributeValue))
            {
                var attributes = ParseResourceAttributes(envResourceAttributeValue);
                resource = new Resource(attributes);
            }

            return(resource);
        }
Esempio n. 6
0
        public Resource Detect()
        {
            var resource = Resource.Empty;

            if (EnvironmentVariableHelper.LoadString(EnvVarKey, out string envResourceAttributeValue))
            {
                resource = new Resource(new Dictionary <string, object>
                {
                    [ResourceSemanticConventions.AttributeServiceName] = envResourceAttributeValue,
                });
            }

            return(resource);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OtlpExporterOptions"/> class.
        /// </summary>
        public OtlpExporterOptions()
        {
            if (EnvironmentVariableHelper.LoadUri(EndpointEnvVarName, out Uri parsedEndpoint))
            {
                this.endpoint = parsedEndpoint;
            }

            if (EnvironmentVariableHelper.LoadString(HeadersEnvVarName, out string headersEnvVar))
            {
                this.Headers = headersEnvVar;
            }

            if (EnvironmentVariableHelper.LoadNumeric(TimeoutEnvVarName, out int timeout))
            {
                this.TimeoutMilliseconds = timeout;
            }

            if (EnvironmentVariableHelper.LoadString(ProtocolEnvVarName, out string protocolEnvVar))
            {
                var protocol = protocolEnvVar.ToOtlpExportProtocol();
                if (protocol.HasValue)
                {
                    this.Protocol = protocol.Value;
                }
                else
                {
                    throw new FormatException($"{ProtocolEnvVarName} environment variable has an invalid value: '{protocolEnvVar}'");
                }
            }

            this.HttpClientFactory = this.DefaultHttpClientFactory = () =>
            {
                return(new HttpClient
                {
                    Timeout = TimeSpan.FromMilliseconds(this.TimeoutMilliseconds),
                });
            };
        }
        public JaegerExporterOptions()
        {
            if (EnvironmentVariableHelper.LoadString(OtelProtocolEnvVarKey, out string protocolEnvVar) &&
                Enum.TryParse(protocolEnvVar, ignoreCase: true, out JaegerExportProtocol protocol))
            {
                this.Protocol = protocol;
            }

            if (EnvironmentVariableHelper.LoadString(OTelAgentHostEnvVarKey, out string agentHostEnvVar))
            {
                this.AgentHost = agentHostEnvVar;
            }

            if (EnvironmentVariableHelper.LoadNumeric(OTelAgentPortEnvVarKey, out int agentPortEnvVar))
            {
                this.AgentPort = agentPortEnvVar;
            }

            if (EnvironmentVariableHelper.LoadString(OTelEndpointEnvVarKey, out string endpointEnvVar) &&
                Uri.TryCreate(endpointEnvVar, UriKind.Absolute, out Uri endpoint))
            {
                this.Endpoint = endpoint;
            }
        }