public void InitializerDoesNotFailOnNullContextStore()
 {
     var telemetry = new DependencyTelemetry();
     AsyncLocalHelpers.SaveOperationContext(null);
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.IsNull(telemetry.Context.Operation.ParentId);
 }
        public void DependencyKindIsSetIfValueCanBeParsedFromEnum()
        {
            DependencyTelemetry expected = new DependencyTelemetry();
            expected.DependencyKind = BondDependencyKind.Http.ToString();

            Assert.Equal(BondDependencyKind.Http.ToString(), expected.DependencyKind);
        }
        public void DependencyKindDefaultsToOtherIfUnexpectedValuePassed()
        {
            DependencyTelemetry expected = new DependencyTelemetry();
            expected.DependencyKind = "badValue";

            Assert.Equal(BondDependencyKind.Other.ToString(), expected.DependencyKind);
        }
        public void DependencyKindDefaultsToOtherIfNullIsPassed()
        {
            DependencyTelemetry expected = new DependencyTelemetry();
            expected.DependencyKind = null;

            Assert.Equal(BondDependencyKind.Other.ToString(), expected.DependencyKind);
        }
 public void AddTupleForSqlDependenciesThrowsExceptionIfExists()
 {
     var telemetry = new DependencyTelemetry();
     var falseTelemetry = new DependencyTelemetry();
     ClientServerDependencyTracker.AddTupleForSqlDependencies(this.sqlRequest, falseTelemetry, false);
     ClientServerDependencyTracker.AddTupleForSqlDependencies(this.sqlRequest, telemetry, false);
 }
        /// <summary>
        /// Populates WebRequest using the operation context in telemetry item.
        /// </summary>
        /// <param name="dependencyTelemetry">Dependency telemetry item.</param>
        /// <param name="webRequest">Http web request.</param>
        internal static void SetCorrelationContextForWebRequest(DependencyTelemetry dependencyTelemetry, WebRequest webRequest)
        {
            if (dependencyTelemetry == null)
            {
                throw new ArgumentNullException("dependencyTelemetry");
            }

            if (webRequest != null)
            {
                OperationContext context = dependencyTelemetry.Context.Operation;

                if (!string.IsNullOrEmpty(context.Id))
                {
                    webRequest.Headers.Add(RequestResponseHeaders.StandardRootIdHeader, context.Id);
                }

                if (!string.IsNullOrEmpty(dependencyTelemetry.Id))
                {
                    webRequest.Headers.Add(RequestResponseHeaders.StandardParentIdHeader, dependencyTelemetry.Id);
                }
            }
            else
            {
                DependencyCollectorEventSource.Log.WebRequestIsNullWarning();
            }
        }
 public void TelemetryContextIsUpdatedWithOperationNameForDependencyTelemetry()
 {
     this.SetOperationContextToCallContext(new OperationContextForCallContext { RootOperationName = "OperationName" });
     var telemetry = new DependencyTelemetry();
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual(telemetry.Context.Operation.Name, "OperationName");
     CallContext.FreeNamedDataSlot(CallContextHelpers.OperationContextSlotName);
 }
 public void TelemetryContextIsUpdatedWithOperationIdForDependencyTelemetry()
 {
     this.SetOperationContextToCallContext(new OperationContextForCallContext { ParentOperationId = "ParentOperationId" });
     var telemetry = new DependencyTelemetry();
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual("ParentOperationId", telemetry.Context.Operation.ParentId);
     CallContext.FreeNamedDataSlot(CallContextHelpers.OperationContextSlotName);
 }
 public void OperationTelemetryStartInitializesTimeStampAndStartTimeToTelemetry()
 {
     var telemetry = new DependencyTelemetry();
     Assert.Equal(telemetry.StartTime, DateTimeOffset.MinValue);
     Assert.Equal(telemetry.Timestamp, DateTimeOffset.MinValue);
     telemetry.Start();
     Assert.Equal(telemetry.StartTime, telemetry.Timestamp);
 }
 public void TelemetryContextIsUpdatedWithOperationIdForDependencyTelemetry()
 {
     AsyncLocalHelpers.SaveOperationContext(new OperationContextForAsyncLocal { ParentOperationId = "ParentOperationId" });
     var telemetry = new DependencyTelemetry();
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual("ParentOperationId", telemetry.Context.Operation.ParentId);
     AsyncLocalHelpers.SaveOperationContext(null);
 }
 /// <summary>
 /// The function that needs to be called before sending a request to the server. Creates and initializes dependency telemetry item.
 /// </summary>
 /// <param name="telemetryClient">Telemetry client object to initialize the context of the telemetry item.</param>
 internal static DependencyTelemetry BeginTracking(TelemetryClient telemetryClient)
 {
     var telemetry = new DependencyTelemetry();
     telemetry.Start();
     telemetryClient.Initialize(telemetry);
     PretendProfilerIsAttached = false;
     return telemetry;
 }
 public DependencyTelemetryTimelineMessage(DependencyTelemetry telemetry)
 {
     this.EventName = telemetry.Name;
     this.EventCategory = new TimelineCategoryItem("Application Insights", "red", "orange");
     this.EventSubText = telemetry.CommandName;
     this.Duration = telemetry.Duration;
     this.StartTime = telemetry.StartTime.DateTime;
 }
 public void TelemetryContextIsUpdatedWithOperationNameForDependencyTelemetry()
 {
     AsyncLocalHelpers.SaveOperationContext(new OperationContextForAsyncLocal { RootOperationName = "OperationName" });
     var telemetry = new DependencyTelemetry();
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual(telemetry.Context.Operation.Name, "OperationName");
     AsyncLocalHelpers.SaveOperationContext(null);
 }
 public void OperationTelemetryStopAssignsCurrentTimeAsStartTimeAndTimeStampWithoutStart()
 {
     var telemetry = new DependencyTelemetry();
     telemetry.Stop();
     Assert.NotEqual(DateTimeOffset.MinValue, telemetry.StartTime);
     Assert.Equal(telemetry.StartTime, telemetry.Timestamp);
     Assert.Equal(telemetry.Duration, TimeSpan.Zero);
 }
 public DependencyTelemetryMessage(DependencyTelemetry dependency)
 {
     this.Time = dependency.Timestamp.DateTime;
     this.Name = dependency.Type + ": " + dependency.Name.Split('|')[0];
     this.Details = dependency.Data;
     this.Properties = dependency.Properties.Count > 0 ? dependency.Properties : null;
     this.Type = "Dependency";
     this.Context = dependency.Context;
 }
 public void InitializeDoesNotUpdateOperationIdIfItExists()
 {
     this.SetOperationContextToCallContext(new OperationContextForCallContext { ParentOperationId = "ParentOperationId" });
     var telemetry = new DependencyTelemetry();
     telemetry.Context.Operation.ParentId = "OldParentOperationId";
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual("OldParentOperationId", telemetry.Context.Operation.ParentId);
     CallContext.FreeNamedDataSlot(CallContextHelpers.OperationContextSlotName);
 }
 public void InitializeDoesNotUpdateOperationNameIfItExists()
 {
     this.SetOperationContextToCallContext(new OperationContextForCallContext { RootOperationName = "OperationName" });
     var telemetry = new DependencyTelemetry();
     telemetry.Context.Operation.Name = "OldOperationName";
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual(telemetry.Context.Operation.Name, "OldOperationName");
     CallContext.FreeNamedDataSlot(CallContextHelpers.OperationContextSlotName);
 }
 public void OperationTelemetryStopComputesDurationAfterStart()
 {
     var telemetry = new DependencyTelemetry();
     telemetry.Start();
     Thread.Sleep(2000);
     Assert.Equal(TimeSpan.Zero, telemetry.Duration);
     telemetry.Stop();
     Assert.True(telemetry.Duration.TotalMilliseconds > 0);
 }
 public void OperationTelemetryStopDoesNotAffectTimeStampAndStartTimeAfterStart()
 {
     var telemetry = new DependencyTelemetry();
     telemetry.Start();
     DateTimeOffset actualTime = telemetry.Timestamp;
     telemetry.Stop();
     Assert.Equal(actualTime, telemetry.Timestamp);
     Assert.Equal(actualTime, telemetry.StartTime);
 }
 public void AddTupleForWebDependenciesAddsTelemteryTupleToTheTable()
 {
     var telemetry = new DependencyTelemetry();
     ClientServerDependencyTracker.AddTupleForWebDependencies(this.webRequest, telemetry, false);
     var tuple = ClientServerDependencyTracker.GetTupleForWebDependencies(this.webRequest);
     Assert.IsNotNull(tuple);
     Assert.IsNotNull(tuple.Item1);
     Assert.AreEqual(telemetry, tuple.Item1);
 }
 public void InitializeDoesNotUpdateOperationNameIfItExists()
 {
     AsyncLocalHelpers.SaveOperationContext(new OperationContextForAsyncLocal { RootOperationName = "OperationName" });
     var telemetry = new DependencyTelemetry();
     telemetry.Context.Operation.Name = "OldOperationName";
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual(telemetry.Context.Operation.Name, "OldOperationName");
     AsyncLocalHelpers.SaveOperationContext(null);
 }
 public void InitializeDoesNotUpdateOperationIdIfItExists()
 {
     AsyncLocalHelpers.SaveOperationContext(new OperationContextForAsyncLocal { ParentOperationId = "ParentOperationId" });
     var telemetry = new DependencyTelemetry();
     telemetry.Context.Operation.ParentId = "OldParentOperationId";
     (new OperationCorrelationTelemetryInitializer()).Initialize(telemetry);
     Assert.AreEqual("OldParentOperationId", telemetry.Context.Operation.ParentId);
     AsyncLocalHelpers.SaveOperationContext(null);
 }
        public void SetUserAndSessionContextForWebRequestDoesNothingIfTelemetryItemIsNotInitialized()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));
            var telemetry = new DependencyTelemetry();

            string cookieValue = DependencyCollectorTestHelpers.GetCookieValueFromWebRequest(webRequest as HttpWebRequest, "ai_session");
            Assert.IsNull(cookieValue);
            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(telemetry, webRequest);
            cookieValue = DependencyCollectorTestHelpers.GetCookieValueFromWebRequest(webRequest as HttpWebRequest, "ai_session");
            Assert.IsNull(cookieValue);
        }
 public void FilterstToGlimpseHandler()
 {
     //
     // TODO: Agregar aquí la lógica de las pruebas
     //
     GlimpseTelemetryChannel TestTelemetryChanel = new GlimpseTelemetryChannel();
     ITelemetry RTitem = new RequestTelemetry();
     ITelemetry DTitem = new DependencyTelemetry();
     TestTelemetryChanel.Send(RTitem);
     TestTelemetryChanel.Send(DTitem);
 }
        public void TestBasicDependencyPropertiesAfterRequestingBasicPage()
        {
            using (var server = new InProcessServer(assemblyName))
            {
                const string RequestPath = "/api/values";

                var expectedDependencyTelemetry = new DependencyTelemetry();
                expectedDependencyTelemetry.Name = server.BaseHost + RequestPath;
                expectedDependencyTelemetry.ResultCode = "200";
                expectedDependencyTelemetry.Success = true;
                this.ValidateBasicDependency(server, RequestPath, expectedDependencyTelemetry);
            }
        }
        public void SetCorrelationContextForWebRequestSetsHeaders()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));
            var telemetry = new DependencyTelemetry();
            telemetry.Id = "Id";
            telemetry.Context.Operation.Id = "RootId";

            WebRequestDependencyTrackingHelpers.SetCorrelationContextForWebRequest(telemetry, webRequest);
            var rootId = webRequest.Headers["x-ms-request-root-id"];
            var operationId = webRequest.Headers["x-ms-request-id"];
            Assert.AreEqual("RootId", rootId);
            Assert.AreEqual("Id", operationId);
        }
        public void SerializeWritesNullValuesAsExpectedByEndpoint()
        {
            DependencyTelemetry original = new DependencyTelemetry();
            original.Name = null;
            original.CommandName = null;
            original.DependencyTypeName = null;
            original.Success = null;
            original.Async = null;
            original.DependencyKind = null;
            ((ITelemetry)original).Sanitize();
            var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem<DependencyTelemetry, DataPlatformModel.RemoteDependencyData>(original);

            Assert.Equal(2, item.Data.BaseData.Ver);
        }
        public void SetCorrelationContextForWebRequestDoesNothingIfOperaitonContextEmpty()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));
            var telemetry = new DependencyTelemetry();

            string rootId = webRequest.Headers["x-ms-request-root-id"];
            string operationId = webRequest.Headers["x-ms-request-id"];
            Assert.IsNull(rootId);
            Assert.IsNull(operationId);
            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(telemetry, webRequest);
            rootId = webRequest.Headers["x-ms-request-root-id"];
            operationId = webRequest.Headers["x-ms-request-id"];
            Assert.IsNull(rootId);
            Assert.IsNull(operationId);
        }
 public void TestInitialize()
 {
     var configuration = new TelemetryConfiguration();
     this.sendItems = new List<ITelemetry>();
     configuration.TelemetryChannel = new StubTelemetryChannel { OnSend = item => this.sendItems.Add(item) };
     configuration.InstrumentationKey = Guid.NewGuid().ToString();
     configuration.TelemetryInitializers.Add(new MockTelemetryInitializer());
     DependencyTrackingTelemetryModule module = new DependencyTrackingTelemetryModule();
     module.Initialize(configuration);
     this.telemetryClient = new TelemetryClient(configuration);
     var operationHolder = this.telemetryClient.StartOperation<DependencyTelemetry>("operationName");
     this.telemetry = operationHolder.Telemetry;
     this.webRequest = WebRequest.Create(new Uri("http://bing.com"));
     this.sqlRequest = new SqlCommand("select * from table;");
 }
        public void ValidateBasicDependency(InProcessServer server, string requestPath, DependencyTelemetry expected)
        {
            DateTimeOffset testStart = DateTimeOffset.Now;
            var timer = Stopwatch.StartNew();
            var httpClient = new HttpClient();
            var task = httpClient.GetAsync(server.BaseHost + requestPath);
            task.Wait(TestTimeoutMs);
            var result = task.Result;

            var actual = server.BackChannel.Buffer.OfType<DependencyTelemetry>().Single();
            timer.Stop();

            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(expected.Success, actual.Success);
            Assert.Equal(expected.ResultCode, actual.ResultCode);
        }
        public void SanitizeWillTrimAppropriateFields()
        {
            DependencyTelemetry telemetry = new DependencyTelemetry();

            telemetry.Name               = new string('Z', Property.MaxNameLength + 1);
            telemetry.CommandName        = new string('Y', Property.MaxCommandNameLength + 1);
            telemetry.DependencyTypeName = new string('D', Property.MaxDependencyTypeLength + 1);
            telemetry.Properties.Add(new string('X', Property.MaxDictionaryNameLength) + 'X', new string('X', Property.MaxValueLength + 1));
            telemetry.Properties.Add(new string('X', Property.MaxDictionaryNameLength) + 'Y', new string('X', Property.MaxValueLength + 1));

            ((ITelemetry)telemetry).Sanitize();

            Assert.Equal(new string('Z', Property.MaxNameLength), telemetry.Name);
            Assert.Equal(new string('Y', Property.MaxCommandNameLength), telemetry.CommandName);
            Assert.Equal(new string('D', Property.MaxDependencyTypeLength), telemetry.DependencyTypeName);

            Assert.Equal(2, telemetry.Properties.Count);
            Assert.Equal(new string('X', Property.MaxDictionaryNameLength), telemetry.Properties.Keys.ToArray()[0]);
            Assert.Equal(new string('X', Property.MaxValueLength), telemetry.Properties.Values.ToArray()[0]);
            Assert.Equal(new string('X', Property.MaxDictionaryNameLength - 3) + "001", telemetry.Properties.Keys.ToArray()[1]);
            Assert.Equal(new string('X', Property.MaxValueLength), telemetry.Properties.Values.ToArray()[1]);

            Assert.Same(telemetry.Properties, telemetry.Properties);
        }
        public void RemoteDependencyTelemetrySerializesToJson()
        {
            DependencyTelemetry expected = this.CreateRemoteDependencyTelemetry();
            var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <DependencyTelemetry, DataPlatformModel.RemoteDependencyData>(expected);

            Assert.Equal(expected.Timestamp, item.Time);
            Assert.Equal(expected.Sequence, item.Seq);
            Assert.Equal(expected.Context.InstrumentationKey, item.IKey);
            Assert.Equal(expected.Context.Tags.ToArray(), item.Tags.ToArray());
            Assert.Equal(typeof(DataPlatformModel.RemoteDependencyData).Name, item.Data.BaseType);

            Assert.Equal(expected.Id, item.Data.BaseData.Id);
            Assert.Equal(expected.ResultCode, item.Data.BaseData.ResultCode);
            Assert.Equal(expected.Name, item.Data.BaseData.Name);
            Assert.Equal(DataPlatformModel.DataPointType.Aggregation, item.Data.BaseData.Kind);
            Assert.Equal(expected.Duration.TotalMilliseconds, item.Data.BaseData.Value);
            Assert.Equal(expected.DependencyKind.ToString(), item.Data.BaseData.DependencyKind.ToString());
            Assert.Equal(expected.DependencyTypeName, item.Data.BaseData.DependencyTypeName);

            Assert.Equal(expected.Success, item.Data.BaseData.Success);
            Assert.Equal(expected.Async, item.Data.BaseData.Async);

            Assert.Equal(expected.Properties.ToArray(), item.Data.BaseData.Properties.ToArray());
        }
Example #33
0
        public void DependencyKindDefaultsToOtherInConstructor()
        {
            var dependency = new DependencyTelemetry("name", "command name", DateTimeOffset.Now, TimeSpan.FromSeconds(42), false);

            Assert.Equal("Other", dependency.DependencyKind);
        }
Example #34
0
        public void DependencyTelemetryImplementsISupportSamplingContract()
        {
            var telemetry = new DependencyTelemetry();

            Assert.IsNotNull(telemetry as ISupportSampling);
        }
        public void VerifyExpectedDefaultValue()
        {
            var defaultDependencyTelemetry = new DependencyTelemetry();

            Assert.AreEqual(true, defaultDependencyTelemetry.Success, "Success is expected to be true");
        }