private static ISpanEventWireModel[] CreateSpanEventModels() { var result = new List <ISpanEventWireModel>(); var attribSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f)); var attribDefs = attribSvc.AttributeDefs; { var spanAttribs = new SpanAttributeValueCollection(); spanAttribs.Priority = 0.654321f; attribDefs.Timestamp.TrySetValue(spanAttribs, TestTime); attribDefs.Priority.TrySetValue(spanAttribs, spanAttribs.Priority); result.Add(spanAttribs); } { var spanAttribs = new SpanAttributeValueCollection(); spanAttribs.Priority = 0.654321f; attribDefs.Timestamp.TrySetValue(spanAttribs, TestTime.AddMilliseconds(1)); attribDefs.Priority.TrySetValue(spanAttribs, spanAttribs.Priority); result.Add(spanAttribs); } { var spanAttribs = new SpanAttributeValueCollection(); spanAttribs.Priority = 0.1f; attribDefs.Timestamp.TrySetValue(spanAttribs, TestTime); attribDefs.Priority.TrySetValue(spanAttribs, spanAttribs.Priority); result.Add(spanAttribs); } return(result.ToArray()); }
public void LazyValueTest_TransactionSpanEvents() { var attribValues = new SpanAttributeValueCollection(); LazyValueTest_SetAttribValues(attribValues); //This happens in the spanEventAggregator or SpanEventAggregatorForInfiniteTracing attribValues.MakeImmutable(); LazyValueTest_Assertions(attribValues); }
private ISpanEventWireModel CreateSpanEvent(float priority, TimeSpan duration, string traceId, string httpMethod) { var wireModel = new SpanAttributeValueCollection(); wireModel.Priority = priority; _attribDefs.GetTypeAttribute(TypeAttributeValue.Span).TrySetDefault(wireModel); _attribDefs.Priority.TrySetValue(wireModel, priority); _attribDefs.Duration.TrySetValue(wireModel, duration); _attribDefs.DistributedTraceId.TrySetValue(wireModel, traceId); _attribDefs.HttpMethod.TrySetValue(wireModel, httpMethod); return(wireModel); }
public void SupportabilityMetrics_SeenAndDropped(int queueSize, int expectedSeen, bool addAsSingleItems) { long actualCountSpansSeen = 0; long actualCountSpansDropped = 0; Mock.Arrange(() => _currentConfiguration.InfiniteTracingQueueSizeSpans).Returns(queueSize); Mock.Arrange(() => _mockAgentHealthReporter.ReportInfiniteTracingSpanEventsDropped(Arg.IsAny <long>())) .DoInstead <long>((countSpans) => { actualCountSpansDropped += countSpans; }); Mock.Arrange(() => _mockAgentHealthReporter.ReportInfiniteTracingSpanEventsSeen(Arg.IsAny <long>())) .DoInstead <long>((countSpans) => { actualCountSpansSeen += countSpans; }); var expectedCountDrops = Math.Max(expectedSeen - queueSize, 0); var streamingSvc = GetMockStreamingService(true, true); var aggregator = CreateAggregator(streamingSvc); FireAgentConnectedEvent(); //Act var items = new List <ISpanEventWireModel>(); for (var i = 0; i < expectedSeen; i++) { var item = new SpanAttributeValueCollection(); if (addAsSingleItems) { aggregator.Collect(item); } items.Add(item); } if (!addAsSingleItems) { aggregator.Collect(items); } //Assert NrAssert.Multiple ( () => Assert.AreEqual(expectedSeen, actualCountSpansSeen, $"{(addAsSingleItems ? "Single Adds" : "Collection")} - Count Seen Items"), () => Assert.AreEqual(expectedCountDrops, actualCountSpansDropped, $"{(addAsSingleItems ? "Single Adds" : "Collection")} - Count Dropped") ); }
/// <summary> /// Creates a single root span, much like we do for Transaction Traces, since DT requires that there be only one parent-less span per txn (or at least the UI/Backend is expecting that). /// </summary> private SpanAttributeValueCollection GenerateRootSpan(string rootSpanId, ImmutableTransaction immutableTransaction, string transactionName, IAttributeValueCollection transactionAttribValues) { var spanAttributes = new SpanAttributeValueCollection(); spanAttributes.AddRange(transactionAttribValues.GetAttributeValues(AttributeClassification.AgentAttributes)); _attribDefs.TransactionNameForSpan.TrySetValue(spanAttributes, transactionName); spanAttributes.Priority = immutableTransaction.Priority; spanAttributes.AddRange(immutableTransaction.CommonSpanAttributes); if (immutableTransaction.TracingState != null) { _attribDefs.ParentId.TrySetValue(spanAttributes, immutableTransaction.TracingState.ParentId ?? immutableTransaction.TracingState.Guid); _attribDefs.TrustedParentId.TrySetValue(spanAttributes, immutableTransaction.TracingState.Guid); _attribDefs.TracingVendors.TrySetValue(spanAttributes, immutableTransaction.TracingState.VendorStateEntries ?? null); } if (_configurationService.Configuration.ErrorCollectorEnabled && immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.HasError) { _attribDefs.SpanErrorClass.TrySetValue(spanAttributes, immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.ErrorData.ErrorTypeName); _attribDefs.SpanErrorMessage.TrySetValue(spanAttributes, immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.ErrorData.ErrorMessage); if (immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.ErrorData.IsExpected) { _attribDefs.SpanIsErrorExpected.TrySetValue(spanAttributes, true); } } _attribDefs.Guid.TrySetValue(spanAttributes, rootSpanId); _attribDefs.Timestamp.TrySetValue(spanAttributes, immutableTransaction.StartTime); _attribDefs.Duration.TrySetValue(spanAttributes, immutableTransaction.Duration); _attribDefs.NameForSpan.TrySetValue(spanAttributes, transactionName); _attribDefs.SpanCategory.TrySetValue(spanAttributes, SpanCategory.Generic); _attribDefs.NrEntryPoint.TrySetValue(spanAttributes, true); spanAttributes.AddRange(transactionAttribValues.GetAttributeValues(AttributeClassification.UserAttributes)); spanAttributes.MakeImmutable(); return(spanAttributes); }
public void SpanEventWireModelTests_Serialization() { const float priority = 1.975676f; var duration = TimeSpan.FromSeconds(4.81); var expectedSerialization = new Dictionary <string, object>[3] { new Dictionary <string, object> { { "type", "Span" }, { "priority", priority }, { "traceId", "ed5bbf27f28ebef3" }, { "duration", duration.TotalSeconds } }, new Dictionary <string, object> { }, new Dictionary <string, object> { { "http.method", "GET" } } }; var spanEventWireModel = new SpanAttributeValueCollection(); spanEventWireModel.Priority = priority; _attribDefs.GetTypeAttribute(TypeAttributeValue.Span).TrySetDefault(spanEventWireModel); _attribDefs.Priority.TrySetValue(spanEventWireModel, priority); _attribDefs.Duration.TrySetValue(spanEventWireModel, duration); _attribDefs.DistributedTraceId.TrySetValue(spanEventWireModel, "ed5bbf27f28ebef3"); _attribDefs.HttpMethod.TrySetValue(spanEventWireModel, "GET"); var serialized = JsonConvert.SerializeObject(spanEventWireModel); Assert.That(serialized, Is.Not.Null); var deserialized = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(serialized); Assert.That(deserialized, Is.Not.Null); AttributeComparer.CompareDictionaries(expectedSerialization, deserialized); }