Esempio n. 1
0
        public void SetUp()
        {
            _environment                = Mock.Create <IEnvironment>();
            _processStatic              = Mock.Create <IProcessStatic>();
            _httpRuntimeStatic          = Mock.Create <IHttpRuntimeStatic>();
            _configurationManagerStatic = Mock.Create <IConfigurationManagerStatic>();
            _dnsStatic = Mock.Create <IDnsStatic>();
            _securityPoliciesConfiguration = new SecurityPoliciesConfiguration();

            _runTimeConfiguration = new RunTimeConfiguration();
            _serverConfig         = new ServerConfiguration();

            SetLocalConfigurationDefaults();
            PublishConfig();

            _configAutoResponder = new ConfigurationAutoResponder(_config);

            _configurationService = Mock.Create <IConfigurationService>();
            Mock.Arrange(() => _configurationService.Configuration).Returns(() => _config);

            _attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f));

            _metricNameSvc = new MetricNameService();
            _transactionMetricNameMaker = new TransactionMetricNameMaker(_metricNameSvc);

            _transactionAttribMaker = new TransactionAttributeMaker(_configurationService, _attribDefSvc);

            _spanEventMaker  = new SpanEventMaker(_attribDefSvc, _configurationService);
            _databaseService = new DatabaseService(Mock.Create <ICacheStatsReporter>());

            _transactionEventMaker = new TransactionEventMaker(_attribDefSvc);


            _transactionGuid = GuidGenerator.GenerateNewRelicGuid();
            _startTime       = new DateTime(2018, 7, 18, 7, 0, 0, DateTimeKind.Utc); // unixtime = 1531897200000

            // Generic Segments
            _baseGenericSegment = new Segment(CreateTransactionSegmentState(3, null, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _baseGenericSegment.SetSegmentData(new SimpleSegmentData(SegmentName));

            _childGenericSegment = new Segment(CreateTransactionSegmentState(4, 3, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _childGenericSegment.SetSegmentData(new SimpleSegmentData(SegmentName));

            // Datastore Segments
            _connectionInfo       = new ConnectionInfo("localhost", "1234", "default", "maininstance");
            _parsedSqlStatement   = SqlParser.GetParsedDatabaseStatement(DatastoreVendor.MSSQL, System.Data.CommandType.Text, ShortQuery);
            _obfuscatedSql        = _databaseService.GetObfuscatedSql(ShortQuery, DatastoreVendor.MSSQL);
            _baseDatastoreSegment = new Segment(CreateTransactionSegmentState(3, null, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _baseDatastoreSegment.SetSegmentData(new DatastoreSegmentData(_databaseService, _parsedSqlStatement, ShortQuery, _connectionInfo));

            // Http Segments
            _baseHttpSegment = new Segment(CreateTransactionSegmentState(3, null, 777), new MethodCallData(MethodCallType, MethodCallMethod, 1));
            _baseHttpSegment.SetSegmentData(new ExternalSegmentData(new Uri(HttpUri), HttpMethod));
        }
Esempio n. 2
0
        public ISpan StartManual()
        {
            LambdaTracer tracer     = LambdaTracer.Instance as LambdaTracer;
            ISpan        activeSpan = tracer.ActiveSpan;

            ISpanContext parentSpanContext = null;

            if (!_ignoreActiveSpan && _parent == null && activeSpan != null)
            {
                AddReference(References.ChildOf, activeSpan.Context);
                parentSpanContext = activeSpan.Context;
            }
            else if (_parent != null)
            {
                parentSpanContext = _parent;
            }

            LambdaSpan parentSpan = null;

            if (parentSpanContext is LambdaSpanContext)
            {
                parentSpan = ((LambdaSpanContext)parentSpanContext).GetSpan();
            }

            var        guid = GuidGenerator.GenerateNewRelicGuid();
            LambdaSpan newSpan;

            if (parentSpan != null)
            {
                newSpan = new LambdaSpan(_operationName, DateTimeOffset.UtcNow, _tags, parentSpan, guid);
            }
            else
            {
                var rootSpan = new LambdaRootSpan(_operationName, DateTimeOffset.UtcNow, _tags, guid, new DataCollector(_logger, tracer.DebugMode), new TransactionState(), new PrioritySamplingState(), new DistributedTracingState());

                if (parentSpanContext is LambdaPayloadContext payloadContext)
                {
                    rootSpan.ApplyLambdaPayloadContext(payloadContext);
                }
                else
                {
                    rootSpan.ApplyAdaptiveSampling(tracer.AdaptiveSampler);
                }

                newSpan = rootSpan;
            }

            LambdaSpanContext spanContext = new LambdaSpanContext(newSpan);

            newSpan.SetContext(spanContext);

            return(newSpan);
        }
        public void Example_ExerciserAlone()
        {
            //Exerciser by itself
            var iterativeExerciser = IterativeExerciser.Create()
                                     .DoThisUnitOfWork(() => { var newGuid = GuidGenerator.GenerateNewRelicGuid(); })
                                     .PerformUnitOfWorkNTimes(1000)
                                     .UsingThreads(10);

            var iterativeExerciserResults = iterativeExerciser.ExecAll();

            //10 threads each running 1K units of work can produce 10K results
            Assert.AreEqual(10000, iterativeExerciserResults.CountUnitsOfWorkPerformed);
        }
Esempio n. 4
0
        public IEnumerable <ISpanEventWireModel> GetSpanEvents(ImmutableTransaction immutableTransaction, string transactionName, IAttributeValueCollection transactionAttribValues)
        {
            var rootSpanId = GuidGenerator.GenerateNewRelicGuid();

            yield return(GenerateRootSpan(rootSpanId, immutableTransaction, transactionName, transactionAttribValues));

            foreach (var segment in immutableTransaction.Segments)
            {
                var segmentAttribValues = GetAttributeValues(segment, immutableTransaction, rootSpanId);

                segmentAttribValues.MakeImmutable();

                yield return(segmentAttribValues);
            }
        }
Esempio n. 5
0
        private string BuildTraceParent(IInternalTransaction transaction)
        {
            var traceId = transaction.TraceId;

            traceId = FormatTraceId(traceId);
            var parentId = _configurationService.Configuration.SpanEventsEnabled ? transaction.CurrentSegment.SpanId : GuidGenerator.GenerateNewRelicGuid();
            var flags    = transaction.Sampled.Value ? "01" : "00";

            return($"{TraceParentVersion}-{traceId}-{parentId}-{flags}");
        }