Ejemplo n.º 1
0
            /// <summary>
            /// Returns a sender if one was given when creating the configuration, or attempts to create a sender based on the
            /// configuration's state.
            /// </summary>
            /// <returns>The sender passed via the constructor or a properly configured sender.</returns>
            public virtual ISender GetSender()
            {
                // if we have a sender, that's the one we return
                if (Sender != null)
                {
                    return(Sender);
                }

                if (!string.IsNullOrEmpty(Endpoint))
                {
                    HttpSender.Builder httpSenderBuilder = new HttpSender.Builder(Endpoint);
                    if (!string.IsNullOrEmpty(AuthUsername) && !string.IsNullOrEmpty(AuthPassword))
                    {
                        _logger.LogDebug("Using HTTP Basic authentication with data from the environment variables.");
                        httpSenderBuilder.WithAuth(AuthUsername, AuthPassword);
                    }
                    else if (!string.IsNullOrEmpty(AuthToken))
                    {
                        _logger.LogDebug("Auth Token environment variable found.");
                        httpSenderBuilder.WithAuth(AuthToken);
                    }

                    _logger.LogDebug("Using the HTTP Sender to send spans directly to the endpoint.");
                    return(httpSenderBuilder.Build());
                }

                _logger.LogDebug("Using the UDP Sender to send spans to the agent.");
                return(new UdpSender(
                           StringOrDefault(AgentHost, UdpSender.DefaultAgentUdpHost),
                           AgentPort.GetValueOrDefault(UdpSender.DefaultAgentUdpCompactPort),
                           0 /* max packet size */));
            }
Ejemplo n.º 2
0
    private static HttpSender BuildHttpSender(JaegerOptions.HttpSenderOptions options)
    {
        if (options is null)
        {
            throw new Exception("Missing Jaeger HTTP sender options.");
        }

        if (string.IsNullOrWhiteSpace(options.Endpoint))
        {
            throw new Exception("Missing Jaeger HTTP sender endpoint.");
        }

        var builder = new HttpSender.Builder(options.Endpoint);

        if (options.MaxPacketSize > 0)
        {
            builder = builder.WithMaxPacketSize(options.MaxPacketSize);
        }

        if (!string.IsNullOrWhiteSpace(options.AuthToken))
        {
            builder = builder.WithAuth(options.AuthToken);
        }

        if (!string.IsNullOrWhiteSpace(options.Username) && !string.IsNullOrWhiteSpace(options.Password))
        {
            builder = builder.WithAuth(options.Username, options.Password);
        }

        if (!string.IsNullOrWhiteSpace(options.UserAgent))
        {
            builder = builder.WithUserAgent(options.Username);
        }

        return(builder.Build());
    }