Exemple #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 */));
            }
Exemple #2
0
        public static Tracer CreateRemoteTracer()
        {
            var sender = new HttpSender
                         .Builder(Utils.CurrentConfig.OpenTracingCollectorURL)
                         .WithAuth(Utils.CurrentConfig.Token)
                         .Build();
            var reporter = new RemoteReporter.Builder().WithSender(sender);

            return(CreateTracer(reporter.Build()));
        }
Exemple #3
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());
    }
Exemple #4
0
        internal static ITracer CreateLogger()
        {
            var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
            var config   = ConfigurationManager.OpenExeConfiguration(assembly.Location);
            var cfg      = config.GetSection(SectionName) as JaegerConfigurationSection;

            if (cfg == null || !cfg.Enabled)
            {
                return(NoopTracerFactory.Create());
            }

            var sender = default(ThriftSender);

            if (cfg.UseUdp)
            {
                var udp = cfg.UdpSender;
                sender = new UdpSender(udp.Host, udp.Port, udp.MaxPacketSize);
            }
            else
            {
                var http = cfg.HttpSender;
                sender = new HttpSender.Builder($"http://{http.Host}:{http.Port}/api/traces")
                         .WithMaxPacketSize(http.MaxPacketSize)
                         .Build();
            }
            var sampler = new ConstSampler(true);

            var reporter = new RemoteReporter.Builder()
                           .WithSender(sender)
                           .Build();

            return(new Tracer.Builder(cfg.ServiceName)
                   .WithReporter(reporter)
                   .WithSampler(sampler)
                   .Build());
        }