public void keytransaction_trace_not_created_when_not_configured() { // ARRANGE var keyTransactions = new Dictionary <string, double> { { "WebTransaction/Action/other", 0.1 } }; _compositeTestAgent.ServerConfiguration.WebTransactionsApdex = keyTransactions; _compositeTestAgent.ServerConfiguration.ApdexT = 10.0; _compositeTestAgent.ServerConfiguration.RpmConfig.TransactionTracerThreshold = 10.0; _compositeTestAgent.PushConfiguration(); // ==== ACT ==== var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var segment = _agent.StartTransactionSegmentOrThrow("segmentName"); segment.End(); tx.End(); _compositeTestAgent.Harvest(); // ==== ACT ==== // ASSERT Assert.IsEmpty(_compositeTestAgent.TransactionTraces); }
public void apdexPerfZone_satisfying_if_time_is_less_than_apdexT() { // ARRANGE var apdexT = TimeSpan.FromMilliseconds(100); _compositeTestAgent.ServerConfiguration.ApdexT = apdexT.TotalSeconds; _compositeTestAgent.PushConfiguration(); // ==== ACT ==== var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var segment = _agent.StartTransactionSegmentOrThrow("segmentName"); segment.End(); tx.End(); _compositeTestAgent.Harvest(); // ==== ACT ==== // ASSERT var expectedEventAttributes = new List <ExpectedAttribute> { new ExpectedAttribute { Key = "nr.apdexPerfZone", Value = "S" } }; var transactionEvent = _compositeTestAgent.TransactionEvents.First(); TransactionEventAssertions.HasAttributes(expectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent); }
public void SetUp() { _compositeTestAgent = new CompositeTestAgent(); _compositeTestAgent.LocalConfiguration.distributedTracing.enabled = false; _compositeTestAgent.PushConfiguration(); _agent = _compositeTestAgent.GetAgent(); }
public void DatastoreSpanEvent_NullCommandTextDoesNotGenerateStatementAttribute() { var testHostName = "myHost"; var testPort = "myPort"; var testDBName = "myDatabase"; _compositeTestAgent.ServerConfiguration.TrustedAccountKey = "33"; _compositeTestAgent.PushConfiguration(); var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); _agent.CurrentTransaction.AcceptDistributedTraceHeaders(NewRelicHeaders, HeaderFunctions.GetHeaders, TransportType.HTTP); var segment = _agent.StartDatastoreRequestSegmentOrThrow(null, DatastoreVendor.MSSQL, null, null, null, testHostName, testPort, testDBName); segment.End(); tx.End(); _compositeTestAgent.Harvest(); var spanEvents = _compositeTestAgent.SpanEvents; Assert.AreEqual(2, spanEvents.Count); // The faux span we create to contain the actual spans. var rootSpan = spanEvents.FirstOrDefault(span => span.IntrinsicAttributes().ContainsKey("nr.entryPoint")); // The span created from the segment at the top of the test. var actualSpan = spanEvents.FirstOrDefault(span => !span.IntrinsicAttributes().ContainsKey("nr.entryPoint")); //Test that the information we get on our spans matches the info that we added to the request. TestPayloadInfoMatchesSpanInfo(Payload, rootSpan, actualSpan); var agentAttributes = actualSpan.AgentAttributes(); //The specific test Assert.IsFalse(agentAttributes.ContainsKey("db.statement")); Assert.AreEqual(testDBName, agentAttributes["db.instance"]); Assert.AreEqual(testHostName, agentAttributes["peer.hostname"]); Assert.AreEqual($"{testHostName}:{testPort}", agentAttributes["peer.address"]); }
public void BeforeEachTest() { _compositeTestAgent = new CompositeTestAgent(); _adaptiveSampler = new AdaptiveSampler(AdaptiveSampler.DefaultTargetSamplesPerInterval, DefaultSamplingTargetIntervalInSecondsForTesting, DefaultSeedForTesting); //This will simulate that the agent has connected and force a sampling interval to start _compositeTestAgent.ServerConfiguration.SamplingTarget = AdaptiveSampler.DefaultTargetSamplesPerInterval; _compositeTestAgent.ServerConfiguration.SamplingTargetPeriodInSeconds = DefaultSamplingTargetIntervalInSecondsForTesting; _compositeTestAgent.PushConfiguration(); }
public void only_agent_and_custom_attributes_should_be_filtered_when_attributes_disabled() { _compositeTestAgent.LocalConfiguration.attributes.enabled = false; _compositeTestAgent.PushConfiguration(); _attribDefs.TransactionName.TrySetValue(_attribValues, "name"); _attribDefs.HostDisplayName.TrySetValue(_attribValues, "host"); _attribDefs.GetCustomAttributeForTransaction("custom1Name").TrySetValue(_attribValues, "custom1Value"); var expectedIntrisicDictionary = new Dictionary <string, object> { { "name", "name" } }; NrAssert.Multiple ( () => CollectionAssert.AreEquivalent(expectedIntrisicDictionary, _attribValues.ToDictionary(AttributeClassification.Intrinsics)), () => CollectionAssert.IsEmpty(_attribValues.ToDictionary(AttributeClassification.AgentAttributes), "Agent attributes were not empty."), () => CollectionAssert.IsEmpty(_attribValues.ToDictionary(AttributeClassification.UserAttributes), "Custom attributes were not empty.") ); }
public void ShouldNotCreateDistributedTracePayload_WhenDistributedTracingIsDisabled() { _compositeTestAgent.LocalConfiguration.distributedTracing.enabled = false; _compositeTestAgent.PushConfiguration(); var agentWrapperApi = _compositeTestAgent.GetAgent(); var transaction = agentWrapperApi.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.ASP), transactionDisplayName: "TransactionName", doNotTrackAsUnitOfWork: true); var transactionBridgeApi = new TransactionBridgeApi(transaction, _apiSupportabilityMetricCounters, _configSvc); dynamic payload = transactionBridgeApi.CreateDistributedTracePayload(); NrAssert.Multiple( () => Assert.IsEmpty(payload.HttpSafe()), () => Assert.IsEmpty(payload.Text()), () => Assert.IsTrue(payload.IsEmpty()) ); }
public void TransactionTrace_HasSqlParameter() { _compositeTestAgent.LocalConfiguration.transactionTracer.explainThreshold = 0; _compositeTestAgent.PushConfiguration(); var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var segment = _agent.StartDatastoreRequestSegmentOrThrow("SELECT", DatastoreVendor.MSSQL, "Table1", "SELECT * FROM Table1"); segment.End(); tx.End(); _compositeTestAgent.Harvest(); var transactionTrace = _compositeTestAgent.TransactionTraces.First(); var parameters = transactionTrace.TransactionTraceData.RootSegment.Children[0].Children[0].Parameters; Assert.AreEqual("SELECT * FROM Table1", parameters["sql"]); }
private void CreateATransactionWithDatastoreSegmentAndHarvest(bool instanceReportingEnabled, bool databaseNameReportingEnabled, DatastoreVendor vendor = DatastoreVendor.MSSQL, string host = "myhost", string portPathOrId = "myport", string databaseName = "mydatabase") { _compositeTestAgent.LocalConfiguration.transactionTracer.explainThreshold = 0; _compositeTestAgent.LocalConfiguration.datastoreTracer.instanceReporting.enabled = instanceReportingEnabled; _compositeTestAgent.LocalConfiguration.datastoreTracer.databaseNameReporting.enabled = databaseNameReportingEnabled; _compositeTestAgent.PushConfiguration(); var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var segment = _agent.StartDatastoreRequestSegmentOrThrow("SELECT", vendor, "Table1", "SELECT * FROM Table1", null, host, portPathOrId, databaseName); segment.End(); tx.End(); _compositeTestAgent.Harvest(); }
public void NoRequestUriInTransactionEvent() { _compositeTestAgent.LocalConfiguration.attributes.exclude = new List <string> { "request.uri" }; _compositeTestAgent.PushConfiguration(); var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var segment = _agent.StartTransactionSegmentOrThrow("segmentName"); segment.End(); tx.End(); _compositeTestAgent.Harvest(); var transactionEvent = _compositeTestAgent.TransactionEvents.First(); Assert.IsFalse(transactionEvent.GetAttributes(AttributeClassification.AgentAttributes).ContainsKey("request.uri")); }
public void SetUp() { _compositeTestAgent = new CompositeTestAgent(); _compositeTestAgent.LocalConfiguration.distributedTracing.enabled = false; _compositeTestAgent.LocalConfiguration.crossApplicationTracingEnabled = true; _compositeTestAgent.ServerConfiguration.AccountId = _accountId.ToString(); _compositeTestAgent.ServerConfiguration.TrustedAccountKey = _trustKey; _compositeTestAgent.ServerConfiguration.PrimaryApplicationId = _appId.ToString(); _catMetricCounters = _compositeTestAgent.Container.Resolve <ICATSupportabilityMetricCounters>(); var crossProcessID = $"{_accountId}#{_appId}"; _crossProcessIDEncoded = Strings.Base64Encode(crossProcessID, _agent.Configuration.EncodingKey); var reqData = new CrossApplicationRequestData("referrerTransactionGuid", false, "referrerTripId", "referrerPathHash"); _reqDataEncoded = HeaderEncoder.SerializeAndEncode(reqData, _agent.Configuration.EncodingKey); _compositeTestAgent.ServerConfiguration.TrustedIds = new long[] { _accountId }; _compositeTestAgent.PushConfiguration(); }
public void SimpleTransaction_CreatesDatastoreTransactionAndSqlTrace() { _compositeTestAgent.LocalConfiguration.transactionTracer.explainThreshold = 0; // Config to run explain plans on queries with any nonzero duration _compositeTestAgent.PushConfiguration(); var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var segment = _agent.StartDatastoreRequestSegmentOrThrow("SELECT", DatastoreVendor.MSSQL, "Table1", "SELECT * FROM Table1"); segment.End(); tx.End(); _compositeTestAgent.Harvest(); var sqlTrace = _compositeTestAgent.SqlTraces.First(); NrAssert.Multiple( () => Assert.IsNotNull(sqlTrace), () => Assert.AreEqual("Datastore/statement/MSSQL/Table1/SELECT", sqlTrace.DatastoreMetricName), () => Assert.AreEqual("SELECT * FROM Table1", sqlTrace.Sql) ); }
public void synthetics_attributes_when_header_is_present() { // ARRANGE var encodingKey = "foo"; var version = 1; var clientAccountId = 123; var resourceId = "resourceId"; var jobId = "jobId"; var monitorId = "monitorId"; _compositeTestAgent.ServerConfiguration.TrustedIds = new long[] { clientAccountId }; _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey; _compositeTestAgent.PushConfiguration(); var syntheticsHeaderValue = Strings.Base64Encode( string.Format(@"[{0}, {1}, ""{2}"", ""{3}"", ""{4}""]", version, clientAccountId, resourceId, jobId, monitorId), encodingKey); var requestHeaders = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(SyntheticsHeaderKey, syntheticsHeaderValue) }; // ==== ACT ==== var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); tx.AcceptDistributedTraceHeaders(requestHeaders, HeaderFunctions.GetHeaders, TransportType.HTTP); var segment = _agent.StartTransactionSegmentOrThrow("segmentName"); segment.End(); tx.End(); _compositeTestAgent.Harvest(); // ASSERT var unexpectedEventAttributes = new List <string> { "nr.alternatePathHashes" }; var expectedEventAttributes = new List <ExpectedAttribute> { new ExpectedAttribute { Key = "nr.guid" }, new ExpectedAttribute { Key = "nr.syntheticsResourceId", Value = resourceId }, new ExpectedAttribute { Key = "nr.syntheticsJobId", Value = jobId }, new ExpectedAttribute { Key = "nr.syntheticsMonitorId", Value = monitorId } }; var expectedTraceAttributes = new List <ExpectedAttribute> { new ExpectedAttribute { Key = "synthetics_resource_id", Value = resourceId }, new ExpectedAttribute { Key = "synthetics_job_id", Value = jobId }, new ExpectedAttribute { Key = "synthetics_monitor_id", Value = monitorId } }; var transactionEvent = _compositeTestAgent.TransactionEvents.First(); var transactionTrace = _compositeTestAgent.TransactionTraces.First(); NrAssert.Multiple( () => TransactionEventAssertions.HasAttributes(expectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent), () => TransactionEventAssertions.DoesNotHaveAttributes(unexpectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent), () => TransactionTraceAssertions.HasAttributes(expectedTraceAttributes, AttributeClassification.Intrinsics, transactionTrace) ); }
public void cat_attributes_when_header_is_present() { // ARRANGE var encodingKey = "foo"; var clientAccountId = 123; var crossProcessId = $"{clientAccountId}#456"; var clientTransactionGuid = "transaction guid"; var clientTripId = "trip id"; var clientPathHash = "path hash"; _compositeTestAgent.ServerConfiguration.TrustedIds = new long[] { clientAccountId }; _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey; _compositeTestAgent.PushConfiguration(); var newRelicIdHeader = new KeyValuePair <string, string>("X-NewRelic-ID", Strings.Base64Encode(crossProcessId, encodingKey)); var newRelicTransactionHeader = new KeyValuePair <string, string>("X-NewRelic-Transaction", Strings.Base64Encode($@"[""{clientTransactionGuid}"", ""{false}"", ""{clientTripId}"", ""{clientPathHash}""]", encodingKey)); var requestHeaders = new[] { newRelicIdHeader, newRelicTransactionHeader }; // ==== ACT ==== var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); _agent.CurrentTransaction.AcceptDistributedTraceHeaders(requestHeaders, HeaderFunctions.GetHeaders, TransportType.HTTP); var segment = _agent.StartTransactionSegmentOrThrow("segmentName"); segment.End(); tx.End(); _compositeTestAgent.Harvest(); // ASSERT var unexpectedEventAttributes = new List <string> { "nr.alternatePathHashes" }; var expectedEventAttributes = new List <ExpectedAttribute> { new ExpectedAttribute { Key = "nr.guid" }, new ExpectedAttribute { Key = "nr.tripId", Value = clientTripId }, new ExpectedAttribute { Key = "nr.pathHash", Value = "b5880367" }, new ExpectedAttribute { Key = "nr.referringTransactionGuid", Value = clientTransactionGuid }, new ExpectedAttribute { Key = "nr.referringPathHash", Value = "path hash" } }; var expectedTraceAttributes = new List <ExpectedAttribute> { new ExpectedAttribute { Key = "client_cross_process_id", Value = crossProcessId }, new ExpectedAttribute { Key = "trip_id", Value = clientTripId }, new ExpectedAttribute { Key = "path_hash", Value = "b5880367" }, new ExpectedAttribute { Key = "referring_transaction_guid", Value = clientTransactionGuid }, }; var transactionEvent = _compositeTestAgent.TransactionEvents.First(); var transactionTrace = _compositeTestAgent.TransactionTraces.First(); NrAssert.Multiple ( () => TransactionEventAssertions.HasAttributes(expectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent), () => TransactionEventAssertions.DoesNotHaveAttributes(unexpectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent), () => TransactionTraceAssertions.HasAttributes(expectedTraceAttributes, AttributeClassification.Intrinsics, transactionTrace) ); }
public void ExternalSegment_HasCorrectTraceNameAndMetrics_IfCatResponseReceived() { const string encodingKey = "foo"; _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey; _compositeTestAgent.PushConfiguration(); var tx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var segment = _agent.StartExternalRequestSegmentOrThrow(new Uri("http://www.newrelic.com/test"), "POST"); var catResponseData = new CrossApplicationResponseData("123#456", "transactionName", 1.1f, 2.2f, 3, "guid"); var responseHeaders = new Dictionary <string, string> { { "X-NewRelic-App-Data", HeaderEncoder.EncodeSerializedData(JsonConvert.SerializeObject(catResponseData), encodingKey) } }; tx.ProcessInboundResponse(responseHeaders, segment); segment.End(); tx.End(); _compositeTestAgent.Harvest(); var expectedMetrics = new[] { new ExpectedMetric { Name = "External/all" }, new ExpectedMetric { Name = "External/allWeb" }, new ExpectedMetric { Name = "External/www.newrelic.com/all" }, new ExpectedMetric { Name = "External/www.newrelic.com/Stream/POST" }, new ExpectedMetric { Name = "ExternalApp/www.newrelic.com/123#456/all" }, new ExpectedMetric { Name = "ExternalTransaction/www.newrelic.com/123#456/transactionName" }, new ExpectedMetric { Name = "ExternalTransaction/www.newrelic.com/123#456/transactionName", Scope = "WebTransaction/Action/name" } }; var unexpectedMetrics = new[] { new ExpectedMetric { Name = "External/allOther" }, new ExpectedMetric { Name = "External/www.newrelic.com/Stream/POST", Scope = "WebTransaction/Action/name" } }; var unexpectedSegments = new[] { "External/www.newrelic.com/Stream/POST" }; var expectedSegments = new[] { "ExternalTransaction/www.newrelic.com/123#456/transactionName" }; var actualMetrics = _compositeTestAgent.Metrics.ToList(); var transactionTrace = _compositeTestAgent.TransactionTraces.First(); NrAssert.Multiple( () => TransactionTraceAssertions.SegmentsExist(expectedSegments, transactionTrace), () => TransactionTraceAssertions.SegmentsDoNotExist(unexpectedSegments, transactionTrace), () => MetricAssertions.MetricsExist(expectedMetrics, actualMetrics), () => MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics) ); }
public void CustomInstrumentationEditor_Applied() { _compositeTestAgent.PushConfiguration(); Mock.Assert(() => _compositeTestAgent.NativeMethods.ApplyCustomInstrumentation(), Occurs.Once()); }
public void SimpleTransaction_EndedMultipleTimes() { _compositeTestAgent.LocalConfiguration.service.completeTransactionsOnThread = true; _compositeTestAgent.PushConfiguration(); var doBackgroundJob = new AutoResetEvent(false); var completedForegroundExternal = new AutoResetEvent(false); var completedBackgroundExternal = new AutoResetEvent(false); bool?transactionFlowedToBackgroundThread = null; InstrumentationThatStartsATransaction(); HttpClientInstrumentation("foregroundExternal", completedForegroundExternal); System.Threading.Tasks.Task.Run((Action)BackgroundJob); completedForegroundExternal.WaitOne(); InstrumentationThatEndsTheTransaction(); doBackgroundJob.Set(); completedBackgroundExternal.WaitOne(); _compositeTestAgent.Harvest(); var transactionEvents = _compositeTestAgent.TransactionEvents; var metrics = _compositeTestAgent.Metrics; var errors = _compositeTestAgent.ErrorEvents; Assert.AreEqual(true, transactionFlowedToBackgroundThread); Assert.AreEqual(1, transactionEvents.Count); Assert.AreEqual("foregroundExternal", transactionEvents.First().AgentAttributes()["request.uri"]); CollectionAssert.IsEmpty(errors); CollectionAssert.IsEmpty(metrics.Where(x => x.MetricName.Name.Contains("backgroundExternal"))); CollectionAssert.IsNotEmpty(metrics.Where(x => x.MetricName.Name.Contains("foregroundExternal"))); void InstrumentationThatStartsATransaction() { _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); _agent.CurrentTransaction.AttachToAsync(); _agent.CurrentTransaction.DetachFromPrimary(); } void InstrumentationThatEndsTheTransaction() { _agent.CurrentTransaction.End(); } void BackgroundJob() { transactionFlowedToBackgroundThread = _agent.CurrentTransaction.IsValid; doBackgroundJob.WaitOne(); HttpClientInstrumentation("backgroundExternal", completedBackgroundExternal); _agent.CurrentTransaction.NoticeError(new Exception()); }; System.Threading.Tasks.Task HttpClientInstrumentation(string segmentName, AutoResetEvent autoResetEvent) { var transactionWrapperApi = _agent.CurrentTransaction; var segment = _agent.StartTransactionSegmentOrThrow(segmentName); _agent.CurrentTransaction.SetUri(segmentName); segment.RemoveSegmentFromCallStack(); transactionWrapperApi.Hold(); return(System.Threading.Tasks.Task.Delay(1000).ContinueWith(task => { segment.End(); transactionWrapperApi.Release(); autoResetEvent.Set(); })); }; }