/// <summary>
        /// Initialize for framework event source (not supported for Net40).
        /// </summary>
        private void InitializeForDiagnosticAndFrameworkEventSource()
        {
            if (!this.DisableDiagnosticSourceInstrumentation)
            {
                DesktopDiagnosticSourceHttpProcessing desktopHttpProcessing = new DesktopDiagnosticSourceHttpProcessing(
                    this.telemetryConfiguration,
                    DependencyTableStore.Instance.WebRequestCacheHolder,
                    this.SetComponentCorrelationHttpHeaders,
                    this.ExcludeComponentCorrelationHttpHeadersOnDomains,
                    this.EnableLegacyCorrelationHeadersInjection,
                    this.EnableRequestIdHeaderInjectionInW3CMode);
                this.httpDesktopDiagnosticSourceListener = new HttpDesktopDiagnosticSourceListener(desktopHttpProcessing, new ApplicationInsightsUrlFilter(this.telemetryConfiguration));
            }

            FrameworkHttpProcessing frameworkHttpProcessing = new FrameworkHttpProcessing(
                this.telemetryConfiguration,
                DependencyTableStore.Instance.WebRequestCacheHolder,
                this.SetComponentCorrelationHttpHeaders,
                this.ExcludeComponentCorrelationHttpHeadersOnDomains,
                this.EnableLegacyCorrelationHeadersInjection);

            // In 4.5 EventListener has a race condition issue in constructor so we retry to create listeners
            this.httpEventListener = RetryPolicy.Retry <InvalidOperationException, TelemetryConfiguration, FrameworkHttpEventListener>(
                config => new FrameworkHttpEventListener(frameworkHttpProcessing),
                this.telemetryConfiguration,
                TimeSpan.FromMilliseconds(10));

            this.sqlEventListener = RetryPolicy.Retry <InvalidOperationException, TelemetryConfiguration, FrameworkSqlEventListener>(
                config => new FrameworkSqlEventListener(config, DependencyTableStore.Instance.SqlRequestCacheHolder, this.EnableSqlCommandTextInstrumentation),
                this.telemetryConfiguration,
                TimeSpan.FromMilliseconds(10));
        }
        public void TestInitialize()
        {
            this.sendItems = new List <ITelemetry>();

            Activity.DefaultIdFormat      = ActivityIdFormat.W3C;
            Activity.ForceDefaultIdFormat = true;

            this.configuration = new TelemetryConfiguration()
            {
                TelemetryChannel = new StubTelemetryChannel
                {
                    OnSend = telemetry => this.sendItems.Add(telemetry)
                },
                InstrumentationKey    = TestInstrumentationKey,
                ApplicationIdProvider = new MockApplicationIdProvider(TestInstrumentationKey, TestApplicationId)
            };

            this.configuration.TelemetryInitializers.Add(this.operationDetailsInitializer);

            this.httpDesktopProcessingFramework = new DesktopDiagnosticSourceHttpProcessing(
                this.configuration,
                new CacheBasedOperationHolder("testCache", 100 * 1000),
                setCorrelationHeaders: true,
                correlationDomainExclusionList: new List <string>(),
                injectLegacyHeaders: false,
                injectRequestIdInW3cMode: true);
            DependencyTableStore.IsDesktopHttpDiagnosticSourceActivated = false;
        }
        public void RddTestHttpDesktopProcessingFrameworkOnBeginAddsLegacyHeaders()
        {
            var httpProcessingLegacyHeaders = new DesktopDiagnosticSourceHttpProcessing(
                this.configuration,
                new CacheBasedOperationHolder("testCache", 100 * 1000),
                setCorrelationHeaders: true,
                correlationDomainExclusionList: new List <string>(),
                injectLegacyHeaders: true,
                enableW3CHeaders: false);
            var request = WebRequest.Create(this.testUrl);

            Assert.IsNull(request.Headers[RequestResponseHeaders.StandardParentIdHeader]);

            var client = new TelemetryClient(this.configuration);

            using (var op = client.StartOperation <RequestTelemetry>("request"))
            {
                httpProcessingLegacyHeaders.OnBegin(request);

                var actualRootIdHeader    = request.Headers[RequestResponseHeaders.StandardRootIdHeader];
                var actualParentIdHeader  = request.Headers[RequestResponseHeaders.StandardParentIdHeader];
                var actualRequestIdHeader = request.Headers[RequestResponseHeaders.RequestIdHeader];
                Assert.IsNotNull(actualRootIdHeader);
                Assert.IsNotNull(actualParentIdHeader);
                Assert.IsNotNull(actualRequestIdHeader);

                Assert.AreNotEqual(actualParentIdHeader, op.Telemetry.Context.Operation.Id);

                Assert.AreEqual(actualParentIdHeader, actualRequestIdHeader);
                Assert.AreEqual(Activity.Current.RootId, actualRootIdHeader);
            }
        }
        public void RddTestHttpDesktopProcessingFrameworkOnBeginSkipsAddingSourceHeaderPerConfig()
        {
            string hostnamepart = "partofhostname";
            string url          = string.Format(CultureInfo.InvariantCulture, "http://hostnamestart{0}hostnameend.com/path/to/something?param=1", hostnamepart);
            var    request      = WebRequest.Create(new Uri(url));

            Assert.IsNull(request.Headers[RequestResponseHeaders.RequestContextHeader]);
            Assert.AreEqual(0, request.Headers.Keys.Cast <string>().Where((x) => { return(x.StartsWith("x-ms-", StringComparison.OrdinalIgnoreCase)); }).Count());

            var localHttpProcessingFramework = new DesktopDiagnosticSourceHttpProcessing(
                this.configuration,
                new CacheBasedOperationHolder("testCache", 100 * 1000),
                false,
                new List <string>(),
                RandomAppIdEndpoint);

            localHttpProcessingFramework.OnBegin(request);
            Assert.IsNull(request.Headers[RequestResponseHeaders.RequestContextHeader]);
            Assert.AreEqual(0, request.Headers.Keys.Cast <string>().Count(x => x.StartsWith("x-ms-", StringComparison.OrdinalIgnoreCase)));

            ICollection <string> exclusionList = new SanitizedHostList()
            {
                "randomstringtoexclude", hostnamepart
            };

            localHttpProcessingFramework = new DesktopDiagnosticSourceHttpProcessing(
                this.configuration,
                new CacheBasedOperationHolder("testCache", 100 * 1000),
                true,
                exclusionList,
                RandomAppIdEndpoint);
            localHttpProcessingFramework.OnBegin(request);
            Assert.IsNull(request.Headers[RequestResponseHeaders.RequestContextHeader]);
            Assert.AreEqual(0, request.Headers.Keys.Cast <string>().Count(x => x.StartsWith("x-ms-", StringComparison.OrdinalIgnoreCase)));
        }
示例#5
0
        public void TestInitialize()
        {
            this.sendItems       = new List <ITelemetry>();
            this.request         = null;
            this.response        = null;
            this.responseHeaders = null;

            this.configuration = new TelemetryConfiguration()
            {
                TelemetryChannel = new StubTelemetryChannel
                {
                    OnSend = telemetry =>
                    {
                        this.sendItems.Add(telemetry);

                        // The correlation id lookup service also makes http call, just make sure we skip that
                        DependencyTelemetry depTelemetry = telemetry as DependencyTelemetry;
                        if (depTelemetry != null)
                        {
                            depTelemetry.TryGetOperationDetail(RemoteDependencyConstants.HttpRequestOperationDetailName, out this.request);
                            depTelemetry.TryGetOperationDetail(RemoteDependencyConstants.HttpResponseOperationDetailName, out this.response);
                            depTelemetry.TryGetOperationDetail(RemoteDependencyConstants.HttpResponseHeadersOperationDetailName, out this.responseHeaders);
                        }
                    },
                },
                InstrumentationKey    = TestInstrumentationKey,
                ApplicationIdProvider = new MockApplicationIdProvider(TestInstrumentationKey, TestApplicationId)
            };

            this.httpDesktopProcessingFramework = new DesktopDiagnosticSourceHttpProcessing(this.configuration, new CacheBasedOperationHolder("testCache", 100 * 1000), /*setCorrelationHeaders*/ true, new List <string>(), false);
            DependencyTableStore.IsDesktopHttpDiagnosticSourceActivated = false;
        }
示例#6
0
        /// <summary>
        /// Initialize for framework event source (not supported for Net40).
        /// </summary>
        private void InitializeForDiagnosticAndFrameworkEventSource()
        {
#if NET45
            if (!this.DisableDiagnosticSourceInstrumentation)
            {
                DesktopDiagnosticSourceHttpProcessing desktopHttpProcessing = new DesktopDiagnosticSourceHttpProcessing(
                    this.telemetryConfiguration,
                    DependencyTableStore.Instance.WebRequestCacheHolder,
                    this.SetComponentCorrelationHttpHeaders,
                    this.ExcludeComponentCorrelationHttpHeadersOnDomains,
                    this.EffectiveProfileQueryEndpoint);
                this.httpDesktopDiagnosticSourceListener = new HttpDesktopDiagnosticSourceListener(desktopHttpProcessing);
            }

            FrameworkHttpProcessing frameworkHttpProcessing = new FrameworkHttpProcessing(
                this.telemetryConfiguration,
                DependencyTableStore.Instance.WebRequestCacheHolder,
                this.SetComponentCorrelationHttpHeaders,
                this.ExcludeComponentCorrelationHttpHeadersOnDomains,
                this.EffectiveProfileQueryEndpoint);

            // In 4.5 EventListener has a race condition issue in constructor so we retry to create listeners
            this.httpEventListener = RetryPolicy.Retry <InvalidOperationException, TelemetryConfiguration, FrameworkHttpEventListener>(
                config => new FrameworkHttpEventListener(frameworkHttpProcessing),
                this.telemetryConfiguration,
                TimeSpan.FromMilliseconds(10));

            this.sqlEventListener = RetryPolicy.Retry <InvalidOperationException, TelemetryConfiguration, FrameworkSqlEventListener>(
                config => new FrameworkSqlEventListener(config, DependencyTableStore.Instance.SqlRequestCacheHolder),
                this.telemetryConfiguration,
                TimeSpan.FromMilliseconds(10));
#endif
        }
 public void TestInitialize()
 {
     this.configuration = new TelemetryConfiguration();
     this.sendItems     = new List <ITelemetry>();
     this.configuration.TelemetryChannel = new StubTelemetryChannel {
         OnSend = item => this.sendItems.Add(item)
     };
     this.configuration.InstrumentationKey = Guid.NewGuid().ToString();
     this.httpDesktopProcessingFramework   = new DesktopDiagnosticSourceHttpProcessing(this.configuration, new CacheBasedOperationHolder("testCache", 100 * 1000), /*setCorrelationHeaders*/ true, new List <string>(), RandomAppIdEndpoint);
     this.httpDesktopProcessingFramework.OverrideCorrelationIdLookupHelper(new CorrelationIdLookupHelper(new Dictionary <string, string> {
         { this.configuration.InstrumentationKey, "cid-v1:" + this.configuration.InstrumentationKey }
     }));
     DependencyTableStore.IsDesktopHttpDiagnosticSourceActivated = false;
 }
示例#8
0
        public void TestInitialize()
        {
            this.configuration = new TelemetryConfiguration()
            {
                TelemetryChannel = new StubTelemetryChannel {
                    OnSend = item => this.sendItems.Add(item)
                },
                InstrumentationKey    = TestInstrumentationKey,
                ApplicationIdProvider = new MockApplicationIdProvider(TestInstrumentationKey, TestApplicationId)
            };

            this.httpDesktopProcessingFramework = new DesktopDiagnosticSourceHttpProcessing(this.configuration, new CacheBasedOperationHolder("testCache", 100 * 1000), /*setCorrelationHeaders*/ true, new List <string>());
            DependencyTableStore.IsDesktopHttpDiagnosticSourceActivated = false;
        }
        public void TestInitialize()
        {
            this.sendItems       = new List <ITelemetry>();
            this.request         = null;
            this.response        = null;
            this.responseHeaders = null;

            this.configuration = new TelemetryConfiguration()
            {
                TelemetryChannel = new StubTelemetryChannel
                {
                    OnSend = telemetry =>
                    {
                        this.sendItems.Add(telemetry);
                    },
                },
                InstrumentationKey    = TestInstrumentationKey,
                ApplicationIdProvider = new MockApplicationIdProvider(TestInstrumentationKey, TestApplicationId)
            };

            this.configuration.TelemetryInitializers.Add(new StubTelemetryInitializer
            {
                OnInitialize = telemetry =>
                {
                    var depTelemetry = telemetry as DependencyTelemetry;
                    depTelemetry.TryGetOperationDetail(RemoteDependencyConstants.HttpRequestOperationDetailName, out this.request);
                    depTelemetry.TryGetOperationDetail(RemoteDependencyConstants.HttpResponseOperationDetailName, out this.response);
                    depTelemetry.TryGetOperationDetail(RemoteDependencyConstants.HttpResponseHeadersOperationDetailName, out this.responseHeaders);
                }
            });

            this.httpDesktopProcessingFramework = new DesktopDiagnosticSourceHttpProcessing(
                this.configuration,
                new CacheBasedOperationHolder("testCache", 100 * 1000),
                setCorrelationHeaders: true,
                correlationDomainExclusionList: new List <string>(),
                injectLegacyHeaders: false,
                enableW3CHeaders: false);
            DependencyTableStore.IsDesktopHttpDiagnosticSourceActivated = false;
        }
        public void RddTestHttpDesktopProcessingFrameworkOnBeginW3COnRequestIdOff()
        {
            var request = WebRequest.Create(this.testUrl);

            Assert.IsNull(request.Headers[RequestResponseHeaders.StandardParentIdHeader]);

            var client = new TelemetryClient(this.configuration);

            using (var op = client.StartOperation <RequestTelemetry>("request"))
            {
                var httpDesktopProcessingFrameworkRequestIdOff = new DesktopDiagnosticSourceHttpProcessing(
                    this.configuration,
                    new CacheBasedOperationHolder("testCache", 100 * 1000),
                    setCorrelationHeaders: true,
                    correlationDomainExclusionList: new List <string>(),
                    injectLegacyHeaders: false,
                    injectRequestIdInW3cMode: false);

                httpDesktopProcessingFrameworkRequestIdOff.OnBegin(request);

                var actualRequestIdHeader   = request.Headers[RequestResponseHeaders.RequestIdHeader];
                var actualTraceparentHeader = request.Headers[W3C.W3CConstants.TraceParentHeader];

                Assert.IsNull(request.Headers[RequestResponseHeaders.StandardParentIdHeader]);
                Assert.IsNull(request.Headers[RequestResponseHeaders.StandardRootIdHeader]);
                Assert.IsNull(request.Headers[W3C.W3CConstants.TraceStateHeader]);
                Assert.IsNull(request.Headers[RequestResponseHeaders.CorrelationContextHeader]);

                // Active bug in .NET Fx diagnostics hook: https://github.com/dotnet/corefx/pull/40777
                // Application Insights has to inject Request-Id to work it around
                var parentActivity = Activity.Current;
                Assert.IsTrue(actualTraceparentHeader.StartsWith($"00-{parentActivity.TraceId.ToHexString()}-", StringComparison.Ordinal));
                var spanId = actualTraceparentHeader.Split('-')[2];
                Assert.AreEqual($"|{parentActivity.TraceId.ToHexString()}.{spanId}.", actualRequestIdHeader);

                Assert.AreNotEqual(parentActivity.Id, actualTraceparentHeader);
            }
        }