當前位置: 首頁>>代碼示例>>C#>>正文


C# DataContracts.RequestTelemetry類代碼示例

本文整理匯總了C#中Microsoft.ApplicationInsights.DataContracts.RequestTelemetry的典型用法代碼示例。如果您正苦於以下問題:C# RequestTelemetry類的具體用法?C# RequestTelemetry怎麽用?C# RequestTelemetry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RequestTelemetry類屬於Microsoft.ApplicationInsights.DataContracts命名空間,在下文中一共展示了RequestTelemetry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DispatchRequest

 public static void DispatchRequest(RequestTelemetry request, TimeSpan duration, bool success)
 {
     request.Duration = duration;
     request.Success = success;
     request.ResponseCode = (success) ? SUCCESS_CODE : FAILURE_CODE;
     AI_CLIENT.TrackRequest(request);
 }
開發者ID:Jinwenxin,項目名稱:ApplicationInsights-Home,代碼行數:7,代碼來源:RequestTelemetryHelper.cs

示例2: RichPayloadEventSourceRequestSentTest

        public void RichPayloadEventSourceRequestSentTest()
        {
            var client = new TelemetryClient();
            client.InstrumentationKey = Guid.NewGuid().ToString();

            using (var listener = new Microsoft.ApplicationInsights.TestFramework.TestEventListener())
            {
                listener.EnableEvents(RichPayloadEventSource.Log.EventSourceInternal, EventLevel.Verbose, RichPayloadEventSource.Keywords.Requests);

                var item = new RequestTelemetry("TestRequest", DateTimeOffset.Now, TimeSpan.FromMilliseconds(10), "200", true);
                item.Context.Properties.Add("property1", "value1");
                item.Context.User.Id = "testUserId";
                item.Context.Operation.Id = Guid.NewGuid().ToString();

                client.TrackRequest(item);

                var actualEvent = listener.Messages.FirstOrDefault();

                Assert.IsNotNull(actualEvent);
                Assert.AreEqual(client.InstrumentationKey, actualEvent.Payload[0]);

                object[] tags = actualEvent.Payload[1] as object[];
                Assert.AreEqual("ai.user.id", ((Dictionary<string, object>)(tags[0]))["Key"]);
                Assert.AreEqual("testUserId", ((Dictionary<string, object>)(tags[0]))["Value"]);

                Assert.AreEqual("ai.operation.id", ((Dictionary<string, object>)(tags[1]))["Key"]);
                Assert.AreEqual(item.Context.Operation.Id, ((Dictionary<string, object>)(tags[1]))["Value"]);

                Assert.IsNotNull(actualEvent.Payload[2]);
            }
        }
開發者ID:jwChung,項目名稱:ApplicationInsights-dotnet,代碼行數:31,代碼來源:RichPayloadEventSourceTest.cs

示例3: StartNewRequest

 public static RequestTelemetry StartNewRequest(string name, DateTimeOffset startTime)
 {
     var request = new RequestTelemetry();
     request.Name = name;
     request.Timestamp = startTime;
     return request;
 }
開發者ID:Jinwenxin,項目名稱:ApplicationInsights-Home,代碼行數:7,代碼來源:RequestTelemetryHelper.cs

示例4: SendAsync

        /// <summary>
        /// Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
        /// </summary>
        /// <param name="request">The HTTP request message to send to the server.</param>
        /// <param name="cancellationToken">A cancellation token to cancel operation.</param>
        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            Guard.NotNull(request, nameof(request));

            AppInsights.GenerateAsyncAwareOperationId();

            var startTime = DateTimeOffset.UtcNow;
            var watch = Stopwatch.StartNew();
            bool success = true;

            try
            {
                return await base.SendAsync(request, cancellationToken);
            }
            catch (Exception exception) when (exception is LogbookException == false)
            {
                success = false;
                throw;
            }
            finally
            {
                watch.Stop();

                var telemetry = new RequestTelemetry
                {
                    HttpMethod = request.Method.Method,
                    Duration = watch.Elapsed,
                    Success = success,
                    StartTime = startTime,
                    Url = request.RequestUri
                };

                AppInsights.Client.TrackRequest(telemetry);
            }
        }
開發者ID:LeagueLogbook,項目名稱:Logbook,代碼行數:40,代碼來源:LoggingMessageHandler.cs

示例5: CreateHttpContextAccessor

        public static HttpContextAccessor CreateHttpContextAccessor(RequestTelemetry requestTelemetry = null, ActionContext actionContext = null)
        {
            var services = new ServiceCollection();

            var request = new DefaultHttpContext().Request;
            request.Method = "GET";
            request.Path = new PathString("/Test");
            var contextAccessor = new HttpContextAccessor() { HttpContext = request.HttpContext };

            services.AddInstance<IHttpContextAccessor>(contextAccessor);

            if (actionContext != null)
            {
                var si = new ActionContextAccessor();
                si.ActionContext = actionContext;
                services.AddInstance<IActionContextAccessor>(si);
            }

            if (requestTelemetry != null)
            {
                services.AddInstance<RequestTelemetry>(requestTelemetry);
            }

            IServiceProvider serviceProvider = services.BuildServiceProvider();
            contextAccessor.HttpContext.RequestServices = serviceProvider;

            return contextAccessor;
        }
開發者ID:hackathonvixion,項目名稱:ApplicationInsights-aspnet5,代碼行數:28,代碼來源:HttpContextAccessorHelper.cs

示例6: Invoke

        public async Task Invoke(HttpContext httpContext, RequestTelemetry telemetry)
        {
            telemetry.Timestamp = DateTimeOffset.UtcNow;

            var sw = new Stopwatch();
            sw.Start();

            bool requestFailed = false;

            try
            {
                await this.next.Invoke(httpContext);
            }
            catch (Exception)
            {
                requestFailed = true;
                throw;
            }
            finally
            {
                sw.Stop();

                telemetry.Duration = sw.Elapsed;
                telemetry.ResponseCode = httpContext.Response.StatusCode.ToString();
                telemetry.Success = (!requestFailed) && (httpContext.Response.StatusCode < 400);
                telemetry.HttpMethod = httpContext.Request.Method;
                telemetry.Url = httpContext.Request.GetUri();
                telemetry.Context.GetInternalContext().SdkVersion = this.sdkVersion;
                    
                this.telemetryClient.TrackRequest(telemetry);
            }
        }
開發者ID:RehanSaeed,項目名稱:ApplicationInsights-aspnetcore,代碼行數:32,代碼來源:RequestTrackingMiddleware.cs

示例7: OnInitializeTelemetry

        /// <summary>
        /// Implements initialization logic.
        /// </summary>
        /// <param name="platformContext">Http context.</param>
        /// <param name="requestTelemetry">Request telemetry object associated with the current request.</param>
        /// <param name="telemetry">Telemetry item to initialize.</param>
        protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
        {
            if (string.IsNullOrEmpty(telemetry.Context.Operation.SyntheticSource))
            {
                if (platformContext != null)
                {
                    var request = platformContext.GetRequest();

                    if (request != null && !string.IsNullOrEmpty(request.UserAgent))
                    {
                        // We expect customers to configure telemetry initializer before they add it to active configuration
                        // So we will not protect fiterPatterns array with locks (to improve perf)
                        foreach (string pattern in this.filterPatterns)
                        {
                            if (!string.IsNullOrWhiteSpace(pattern) &&
                                request.UserAgent.IndexOf(pattern, StringComparison.OrdinalIgnoreCase) != -1)
                            {
                                telemetry.Context.Operation.SyntheticSource = "Bot";
                                return;
                            }
                        }
                    }
                }
            }
        }
開發者ID:Microsoft,項目名稱:ApplicationInsights-dotnet-server,代碼行數:31,代碼來源:SyntheticUserAgentTelemetryInitializer.cs

示例8: OnInitializeTelemetry

 protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
 {
     if (string.IsNullOrEmpty(telemetry.Context.Operation.Id))
     {
         telemetry.Context.Operation.Id = requestTelemetry.Id;
     }
 }
開發者ID:jango2015,項目名稱:ApplicationInsights-aspnet5,代碼行數:7,代碼來源:OperationIdTelemetryInitializer.cs

示例9: InitializeAssignsVersionToTelemetry

 public void InitializeAssignsVersionToTelemetry()
 {
     var initializer = new ComponentVersionTelemetryInitializer(this.BuildConfigurationWithVersion());
     var telemetry = new RequestTelemetry();
     initializer.Initialize(telemetry);
     Assert.NotNull(telemetry.Context.Component.Version);
 }
開發者ID:RehanSaeed,項目名稱:ApplicationInsights-aspnetcore,代碼行數:7,代碼來源:ComponentVersionTelemetryInitializerTests.cs

示例10: GetAuthUserContextFromUserCookie

        internal void GetAuthUserContextFromUserCookie(HttpCookie authUserCookie, RequestTelemetry requestTelemetry)
        {
            if (authUserCookie == null)
            {
                // Request does not have authenticated user
                WebEventSource.Log.AuthIdTrackingCookieNotAvailable();
                return;
            }

            if (string.IsNullOrEmpty(authUserCookie.Value))
            {
                // Request does not have authenticated user
                WebEventSource.Log.AuthIdTrackingCookieIsEmpty();
                return;
            }

            var authUserCookieString = HttpUtility.UrlDecode(authUserCookie.Value);

            var cookieParts = authUserCookieString.Split('|');

            if (cookieParts.Length > 0)
            {
                requestTelemetry.Context.User.AuthenticatedUserId = cookieParts[0];
            }
        }
開發者ID:gregjhogan,項目名稱:ApplicationInsights-server-dotnet,代碼行數:25,代碼來源:AuthenticatedUserIdTelemetryInitializer.cs

示例11: OnInitializeTelemetry

        /// <summary>
        /// Implements initialization logic.
        /// </summary>
        /// <param name="platformContext">Http context.</param>
        /// <param name="requestTelemetry">Request telemetry object associated with the current request.</param>
        /// <param name="telemetry">Telemetry item to initialize.</param>
        protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
        {
            if (platformContext != null)
            {
                var request = platformContext.GetRequest();

                if (request != null)
                {
                    foreach (var pattern in this.filterPatterns)
                    {
                        if (pattern.RegularExpression != null && request.UserAgent != null)
                        {
                            var match = pattern.RegularExpression.Match(request.UserAgent);
                            if (match.Success)
                            {
                                if (string.IsNullOrEmpty(telemetry.Context.Operation.SyntheticSource))
                                {
                                    telemetry.Context.Operation.SyntheticSource = !string.IsNullOrWhiteSpace(pattern.SourceName) ? pattern.SourceName : match.Value;
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
開發者ID:jawn,項目名稱:ApplicationInsights-server-dotnet,代碼行數:32,代碼來源:SyntheticUserAgentTelemetryInitializer.cs

示例12: ParameterlessConstructorInitializesRequiredFields

 public void ParameterlessConstructorInitializesRequiredFields()
 {
     var request = new RequestTelemetry();
     Assert.False(string.IsNullOrEmpty(request.Id));
     Assert.Equal("200", request.ResponseCode);
     Assert.Equal(true, request.Success);
 }
開發者ID:iusafaro,項目名稱:ApplicationInsights-dotnet,代碼行數:7,代碼來源:RequestTelemetryTest.cs

示例13: InitializeSetsSdkVersionPropertyOfGivenTelemetry

        public void InitializeSetsSdkVersionPropertyOfGivenTelemetry()
        {
            var initializer = new SdkVersionPropertyTelemetryInitializer();
            var item = new RequestTelemetry();
            initializer.Initialize(item);

            Assert.NotNull(item.Context.Internal.SdkVersion);
        }
開發者ID:iusafaro,項目名稱:ApplicationInsights-dotnet,代碼行數:8,代碼來源:SdkVersionPropertyTelemetryInitializerTest.cs

示例14: OnInitializeTelemetry

 protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
 {
     if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleInstance))
     {
         var name = LazyInitializer.EnsureInitialized(ref this.roleInstanceName, this.GetMachineName);
         telemetry.Context.Cloud.RoleInstance = name;
     }
 }
開發者ID:fjsnogueira,項目名稱:ApplicationInsights-aspnetcore,代碼行數:8,代碼來源:DomainNameRoleInstanceTelemetryInitializer.cs

示例15: InitializeDoesNotThrowIfVersionDoesNotExist

 public void InitializeDoesNotThrowIfVersionDoesNotExist()
 {
     var config = new ConfigurationBuilder()
         .Build();
     var initializer = new ComponentVersionTelemetryInitializer(config);
     var telemetry = new RequestTelemetry();
     initializer.Initialize(telemetry);
 }
開發者ID:RehanSaeed,項目名稱:ApplicationInsights-aspnetcore,代碼行數:8,代碼來源:ComponentVersionTelemetryInitializerTests.cs


注:本文中的Microsoft.ApplicationInsights.DataContracts.RequestTelemetry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。