private ImmutableTransaction BuildTestTransaction(string uri = null, string guid = null, int?statusCode = null, int?subStatusCode = null, IEnumerable <ErrorData> transactionExceptionDatas = null) { var transactionMetadata = new TransactionMetadata(); if (uri != null) { transactionMetadata.SetUri(uri); } if (statusCode != null) { transactionMetadata.SetHttpResponseStatusCode(statusCode.Value, subStatusCode, _errorService); } if (transactionExceptionDatas != null) { transactionExceptionDatas.ForEach(data => transactionMetadata.TransactionErrorState.AddExceptionData(data)); } var name = TransactionName.ForWebTransaction("foo", "bar"); var segments = Enumerable.Empty <Segment>(); var metadata = transactionMetadata.ConvertToImmutableMetadata(); guid = guid ?? Guid.NewGuid().ToString(); var attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f)); return(new ImmutableTransaction(name, segments, metadata, DateTime.UtcNow, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), guid, false, false, false, 0.5f, false, string.Empty, null, attribDefSvc.AttributeDefs)); }
private IInternalTransaction BuildTestTransaction(bool isWebTransaction = true, string uri = null, string referrerUri = null, string guid = null, int?statusCode = null, int?subStatusCode = null, string referrerCrossProcessId = null, string transactionCategory = "defaultTxCategory", string transactionName = "defaultTxName", ErrorData exceptionData = null, ErrorData customErrorData = null, bool isSynthetics = true, bool isCAT = true, bool includeUserAttributes = false, float priority = 0.5f, bool sampled = false, string traceId = "traceId") { var name = isWebTransaction ? TransactionName.ForWebTransaction(transactionCategory, transactionName) : TransactionName.ForOtherTransaction(transactionCategory, transactionName); var segments = Enumerable.Empty <Segment>(); var placeholderMetadataBuilder = new TransactionMetadata(); var placeholderMetadata = placeholderMetadataBuilder.ConvertToImmutableMetadata(); var immutableTransaction = new ImmutableTransaction(name, segments, placeholderMetadata, DateTime.UtcNow, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), guid, false, false, false, priority, sampled, traceId, null, _attribDefs); var internalTransaction = new Transaction(Mock.Create <IConfiguration>(), immutableTransaction.TransactionName, _timerFactory.StartNewTimer(), DateTime.UtcNow, Mock.Create <ICallStackManager>(), Mock.Create <IDatabaseService>(), priority, Mock.Create <IDatabaseStatementParser>(), Mock.Create <IDistributedTracePayloadHandler>(), Mock.Create <IErrorService>(), _attribDefs); var adaptiveSampler = Mock.Create <IAdaptiveSampler>(); Mock.Arrange(() => adaptiveSampler.ComputeSampled(ref priority)).Returns(sampled); internalTransaction.SetSampled(adaptiveSampler); var transactionMetadata = internalTransaction.TransactionMetadata; PopulateTransactionMetadataBuilder(transactionMetadata, uri, statusCode, subStatusCode, referrerCrossProcessId, exceptionData, customErrorData, isSynthetics, isCAT, referrerUri, includeUserAttributes); return(internalTransaction); }
public void Build_HasEmptyPathHashIfNeverSet() { var transactionMetadata = new TransactionMetadata(); var immutableMetadata = transactionMetadata.ConvertToImmutableMetadata(); NrAssert.Multiple( () => Assert.AreEqual(null, immutableMetadata.CrossApplicationPathHash), () => Assert.AreEqual(0, immutableMetadata.CrossApplicationAlternatePathHashes.Count()) ); }
public void Build_HasZeroAlternatePathHashesIfSetOnce() { var metadata = new TransactionMetadata(); metadata.SetCrossApplicationPathHash("pathHash1"); var immutableMetadata = metadata.ConvertToImmutableMetadata(); NrAssert.Multiple( () => Assert.AreEqual("pathHash1", immutableMetadata.CrossApplicationPathHash), () => Assert.AreEqual(0, immutableMetadata.CrossApplicationAlternatePathHashes.Count()) ); }
private ImmutableTransaction BuildTestImmutableTransaction(bool isWebTransaction = true, string guid = null, float priority = 0.5f, bool sampled = false, string traceId = "traceId", bool isDTParticipant = false) { var name = TransactionName.ForWebTransaction("category", "name"); var segments = Enumerable.Empty <Segment>(); var placeholderMetadataBuilder = new TransactionMetadata(); var placeholderMetadata = placeholderMetadataBuilder.ConvertToImmutableMetadata(); var immutableTransaction = new ImmutableTransaction(name, segments, placeholderMetadata, DateTime.UtcNow, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), guid, false, false, false, priority, sampled, traceId, BuildMockTracingState(isDTParticipant), _attribDefs); return(immutableTransaction); }
public void Getters_HttpResponseStatusCode() { var metadata = new TransactionMetadata(); Assert.IsNull(metadata.HttpResponseStatusCode); metadata.SetHttpResponseStatusCode(200, null, Mock.Create <IErrorService>()); Assert.AreEqual(200, metadata.HttpResponseStatusCode); metadata.SetHttpResponseStatusCode(400, null, Mock.Create <IErrorService>()); Assert.AreEqual(400, metadata.HttpResponseStatusCode); var immutableMetadata = metadata.ConvertToImmutableMetadata(); Assert.AreEqual(400, immutableMetadata.HttpResponseStatusCode); Assert.IsNull(immutableMetadata.HttpResponseSubStatusCode); metadata.SetHttpResponseStatusCode(404, 420, Mock.Create <IErrorService>()); Assert.AreEqual(404, metadata.HttpResponseStatusCode); immutableMetadata = metadata.ConvertToImmutableMetadata(); Assert.AreEqual(404, immutableMetadata.HttpResponseStatusCode); Assert.AreEqual(420, immutableMetadata.HttpResponseSubStatusCode); }
public static IInternalTransaction CreateDefaultTransaction(bool isWebTransaction = true, string uri = null, string guid = null, int?statusCode = null, int?subStatusCode = null, string referrerCrossProcessId = null, string transactionCategory = "defaultTxCategory", string transactionName = "defaultTxName", bool addSegment = true, IEnumerable <Segment> segments = null, bool sampled = false, IConfigurationService configurationService = null, Exception exception = null) { var name = isWebTransaction ? TransactionName.ForWebTransaction(transactionCategory, transactionName) : TransactionName.ForOtherTransaction(transactionCategory, transactionName); segments = segments ?? Enumerable.Empty <Segment>(); var placeholderMetadataBuilder = new TransactionMetadata(); var placeholderMetadata = placeholderMetadataBuilder.ConvertToImmutableMetadata(); var immutableTransaction = new ImmutableTransaction(name, segments, placeholderMetadata, DateTime.Now, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), guid, false, false, false, 0.5f, false, string.Empty, null, _attribDefSvc.AttributeDefs); var priority = 0.5f; var configuration = configurationService?.Configuration ?? GetDefaultConfiguration(); var errorService = configurationService != null ? new ErrorService(configurationService) : new ErrorService(Mock.Create <IConfigurationService>()); var internalTransaction = new Transaction(configuration, immutableTransaction.TransactionName, Mock.Create <ITimer>(), DateTime.UtcNow, Mock.Create <ICallStackManager>(), _databaseService, priority, Mock.Create <IDatabaseStatementParser>(), Mock.Create <IDistributedTracePayloadHandler>(), errorService, _attribDefSvc.AttributeDefs); if (exception != null) { internalTransaction.NoticeError(exception); } if (segments.Any()) { foreach (var segment in segments) { internalTransaction.Add(segment); } } else if (addSegment) { internalTransaction.Add(SimpleSegmentDataTests.createSimpleSegmentBuilder(TimeSpan.Zero, TimeSpan.Zero, 0, null, new MethodCallData("typeName", "methodName", 1), Enumerable.Empty <KeyValuePair <string, object> >(), "MyMockedRootNode", false)); } var adaptiveSampler = Mock.Create <IAdaptiveSampler>(); Mock.Arrange(() => adaptiveSampler.ComputeSampled(ref priority)).Returns(sampled); internalTransaction.SetSampled(adaptiveSampler); var transactionMetadata = internalTransaction.TransactionMetadata; PopulateTransactionMetadataBuilder(transactionMetadata, errorService, uri, statusCode, subStatusCode, referrerCrossProcessId); return(internalTransaction); }
private ImmutableTransaction BuildTestTransaction(IEnumerable <Segment> segments = null, DateTime?startTime = null) { var transactionMetadata = new TransactionMetadata(); var name = TransactionName.ForWebTransaction("foo", "bar"); segments = segments ?? Enumerable.Empty <Segment>(); var metadata = transactionMetadata.ConvertToImmutableMetadata(); startTime = startTime ?? DateTime.Now; var duration = TimeSpan.FromSeconds(1); var guid = Guid.NewGuid().ToString(); return(new ImmutableTransaction(name, segments, metadata, startTime.Value, duration, duration, guid, false, false, false, 1.23f, false, string.Empty, null, _attribDefs)); }
public void Build_OnlyRetainsACertainNumberOfAlternatePathHashes() { var maxPathHashes = PathHashMaker.AlternatePathHashMaxSize; var transactionMetadata = new TransactionMetadata(); Enumerable.Range(0, maxPathHashes + 2).ForEach(number => transactionMetadata.SetCrossApplicationPathHash($"pathHash{number}")); var immutableMetadata = transactionMetadata.ConvertToImmutableMetadata(); NrAssert.Multiple( () => Assert.AreEqual($"pathHash{PathHashMaker.AlternatePathHashMaxSize + 1}", immutableMetadata.CrossApplicationPathHash), () => Assert.AreEqual(PathHashMaker.AlternatePathHashMaxSize, immutableMetadata.CrossApplicationAlternatePathHashes.Count()), () => Assert.IsFalse(immutableMetadata.CrossApplicationAlternatePathHashes.Contains($"pathHash{PathHashMaker.AlternatePathHashMaxSize + 1}")) ); }
public static ImmutableTransaction CreateTestTransactionWithSegments(IEnumerable <Segment> segments) { var uri = "sqlTrace/Uri"; var transactionMetadata = new TransactionMetadata(); transactionMetadata.SetUri(uri); var name = TransactionName.ForWebTransaction("TxsWithSegments", "TxWithSegmentX"); var metadata = transactionMetadata.ConvertToImmutableMetadata(); var guid = Guid.NewGuid().ToString(); var transaction = new ImmutableTransaction(name, segments, metadata, DateTime.UtcNow, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), guid, false, false, false, 0.5f, false, string.Empty, null, _attribDefSvc.AttributeDefs); return(transaction); }
public void Build_PutsAllPathHashesIntoAlternatePathHashes_ExceptLatest() { var metadata = new TransactionMetadata(); metadata.SetCrossApplicationPathHash("pathHash1"); metadata.SetCrossApplicationPathHash("pathHash2"); metadata.SetCrossApplicationPathHash("pathHash3"); var immutableMetadata = metadata.ConvertToImmutableMetadata(); NrAssert.Multiple( () => Assert.AreEqual("pathHash3", immutableMetadata.CrossApplicationPathHash), () => Assert.AreEqual(2, immutableMetadata.CrossApplicationAlternatePathHashes.Count()), () => Assert.IsTrue(immutableMetadata.CrossApplicationAlternatePathHashes.Contains("pathHash1")), () => Assert.IsTrue(immutableMetadata.CrossApplicationAlternatePathHashes.Contains("pathHash2")) ); }
private ImmutableTransaction BuildTestTransaction(DateTime?startTime = null, TimeSpan?duration = null, TimeSpan?responseTime = null, string uri = null, string guid = null) { var transactionMetadata = new TransactionMetadata(); if (uri != null) { transactionMetadata.SetUri(uri); } var name = TransactionName.ForWebTransaction("foo", "bar"); var segments = Enumerable.Empty <Segment>(); var metadata = transactionMetadata.ConvertToImmutableMetadata(); startTime = startTime ?? DateTime.Now; duration = duration ?? TimeSpan.FromSeconds(1); guid = guid ?? Guid.NewGuid().ToString(); return(new ImmutableTransaction(name, segments, metadata, startTime.Value, duration.Value, responseTime, guid, false, false, false, 1.2f, false, string.Empty, null, _attribDefs)); }
public void AddUserAttribute_LastInWins() { var key = "testKey"; var valueA = "valueA"; var valueB = "valueB"; var metadata = new TransactionMetadata(); metadata.AddUserAttribute(key, valueA); metadata.AddUserAttribute(key, valueB); var immutableTransactionMetadata = metadata.ConvertToImmutableMetadata(); var userAttributes = immutableTransactionMetadata.UserAttributes.ToDictionary(); var result = userAttributes[key]; Assert.AreEqual(result, valueB); }
public void AddRequestParameter_LastInWins() { var key = "testKey"; var valueA = "valueA"; var valueB = "valueB"; var metadata = new TransactionMetadata(); metadata.AddRequestParameter(key, valueA); metadata.AddRequestParameter(key, valueB); var immutableTransactionMetadata = metadata.ConvertToImmutableMetadata(); var requestParameters = immutableTransactionMetadata.RequestParameters.ToDictionary(); var result = requestParameters[key]; Assert.AreEqual(result, valueB); }
public void multiple_sqlId_does_not_has_9_digits_number() { var transactionMetadata = new TransactionMetadata(); var name = TransactionName.ForWebTransaction("foo", "bar"); var metadata = transactionMetadata.ConvertToImmutableMetadata(); var duration = TimeSpan.FromSeconds(1); var guid = Guid.NewGuid().ToString(); var transactionMetricName = new TransactionMetricName("WebTransaction", "Name"); var databaseService = new DatabaseService(Mock.Create <ICacheStatsReporter>()); var configurationService = Mock.Create <IConfigurationService>(); var attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f)); string[] queries = { Sql, "Select * from someTable", "Insert x into anotherTable", "another random string", "1234567890!@#$%^&*()", "fjdksalfjdkla;fjdla;", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "NNNNNNNNNNNUUUUUUUUUUUUUUUUTTTTTTTTTTTTTTTHHHHHHHHHHHHHIIIIIIIIIIIIIIIIIIIINNNNNNNNNNNNNNNNNNNN", double.MaxValue.ToString() }; var sqlTraceMaker = new SqlTraceMaker(configurationService, attribDefSvc, databaseService); var traceDatas = new List <SqlTraceWireModel>(); foreach (string query in queries) { var data = new DatastoreSegmentData(databaseService, new ParsedSqlStatement(DatastoreVendor.MSSQL, null, null), query); var segment = new Segment(TransactionSegmentStateHelpers.GetItransactionSegmentState(), new MethodCallData("typeName", "methodName", 1)); segment.SetSegmentData(data); var segments = new List <Segment>() { new Segment(new TimeSpan(), TotalCallTime, segment, null) }; var immutableTransaction = new ImmutableTransaction(name, segments, metadata, DateTime.Now, duration, duration, guid, false, false, false, 1.2f, false, string.Empty, null, _attribDefs); var sqlTraceData = sqlTraceMaker.TryGetSqlTrace(immutableTransaction, transactionMetricName, immutableTransaction.Segments.FirstOrDefault()); traceDatas.Add(sqlTraceData); } foreach (SqlTraceWireModel traceData in traceDatas) { var numberOfDigits = Math.Floor(Math.Log10(traceData.SqlId) + 1); Assert.IsTrue(numberOfDigits != 9); } }