Exemplo n.º 1
0
        public void Context_Destination_from_Db(ExternalDbType externalDbType, ConnectionDetails connectionDetails)
        {
            if (connectionDetails == null)
            {
                return;
            }

            var mockPayloadSender = new MockPayloadSender();

            using (var agent = new ApmAgent(new AgentComponents(payloadSender: mockPayloadSender)))
            {
                agent.Subscribe(new EfCoreDiagnosticsSubscriber());
                agent.Tracer.CaptureTransaction("test TX name", "test TX type"
                                                , () => { ExecuteTestCrudSequence(() => externalDbType.DbContextBuilder(connectionDetails)); });
            }
            mockPayloadSender.Transactions.Should().HaveCount(1);
            mockPayloadSender.Spans.ForEach(span =>
            {
                span.Type.Should().Be(ApiConstants.TypeDb);
                span.Subtype.Should().Be(externalDbType.SpanSubtype);
                span.Action.Should().Be(ApiConstants.ActionQuery);
                span.Context.Db.Type.Should().Be(Database.TypeSql);
                span.Context.Destination.Address.Should().Be(connectionDetails.Host);
                span.Context.Destination.Port.Should().Be(externalDbType.DefaultPort);
            });
        }
Exemplo n.º 2
0
        private static ConnectionDetails GetConnectionDetails(ExternalDbType externalDbType)
        {
            var connectionDetails = new ConnectionDetails();

            foreach (var envVarSuffixToConnectionProperty in EnvVarSuffixToConnectionProperty)
            {
                var envVarName  = "ELASTIC_APM_TESTS_" + externalDbType.EnvVarNameMiddlePart + "_" + envVarSuffixToConnectionProperty.Key;
                var envVarValue = Environment.GetEnvironmentVariable(envVarName);
                if (envVarValue == null)
                {
                    return(null);
                }
                envVarSuffixToConnectionProperty.Value(connectionDetails, envVarValue);
            }

            return(connectionDetails);
        }