Exemplo n.º 1
0
        public async Task FlushTwice()
        {
            var w = new CIAgentWriter(_api.Object);
            await w.FlushAndCloseAsync();

            await w.FlushAndCloseAsync();
        }
Exemplo n.º 2
0
        public async Task WriteTrace_2Traces_SendToApi()
        {
            var trace         = new[] { new Span(new SpanContext(TraceId.CreateFromUlong(1), 1), DateTimeOffset.UtcNow) };
            var expectedData1 = Vendors.MessagePack.MessagePackSerializer.Serialize(trace, SpanFormatterResolver.Instance);

            _ciAgentWriter.WriteTrace(new ArraySegment <Span>(trace));
            await _ciAgentWriter.FlushTracesAsync(); // Force a flush to make sure the trace is written to the API

            _api.Verify(x => x.SendTracesAsync(It.Is <ArraySegment <byte> >(y => Equals(y, expectedData1)), It.Is <int>(i => i == 1)), Times.Once);

            _api.Invocations.Clear();

            trace = new[] { new Span(new SpanContext(TraceId.CreateFromUlong(2), 2), DateTimeOffset.UtcNow) };
            var expectedData2 = Vendors.MessagePack.MessagePackSerializer.Serialize(trace, SpanFormatterResolver.Instance);

            _ciAgentWriter.WriteTrace(new ArraySegment <Span>(trace));
            await _ciAgentWriter.FlushTracesAsync(); // Force a flush to make sure the trace is written to the API

            _api.Verify(x => x.SendTracesAsync(It.Is <ArraySegment <byte> >(y => Equals(y, expectedData2)), It.Is <int>(i => i == 1)), Times.Once);

            await _ciAgentWriter.FlushAndCloseAsync();
        }
Exemplo n.º 3
0
        public static async Task <bool> CheckAgentConnectionAsync(string agentUrl)
        {
            var env = new NameValueCollection();

            if (!string.IsNullOrWhiteSpace(agentUrl))
            {
                env["DD_TRACE_AGENT_URL"] = agentUrl;
            }

            var globalSettings = GlobalSettings.CreateDefaultConfigurationSource();

            globalSettings.Add(new NameValueConfigurationSource(env));
            var tracerSettings = new TracerSettings(globalSettings);
            var agentWriter    = new CIAgentWriter(tracerSettings.Build(), new CISampler());

            try
            {
                if (!await agentWriter.Ping().ConfigureAwait(false))
                {
                    WriteError($"Error connecting to the Datadog Agent at {tracerSettings.Exporter.AgentUri}.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                WriteError($"Error connecting to the Datadog Agent at {tracerSettings.Exporter.AgentUri}.");
                AnsiConsole.WriteException(ex);
                return(false);
            }
            finally
            {
                await agentWriter.FlushAndCloseAsync().ConfigureAwait(false);
            }

            return(true);
        }