示例#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 */));
            }
示例#2
0
        public void Save()
        {
            var agent = new ServerAgent {
                Id      = AgentId,
                Name    = AgentName,
                TcpHost = AgentHost,
                TcpPort = AgentPort.To <int>(),
            };

            agent.Roles.AddRange(AgentRoles);

            string prevId = null;

            if (!string.Equals(AgentId_Source, AgentId, StringComparison.Ordinal))
            {
                prevId = AgentId_Source;
            }

            PhotonServer.Instance.Agents.Save(agent, prevId);
        }