• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DataContracts.RequestTelemetry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.ApplicationInsights.DataContracts.RequestTelemetry的典型用法代码示例。如果您正苦于以下问题:C# RequestTelemetry类的具体用法?C# RequestTelemetry怎么用?C# RequestTelemetry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RequestTelemetry类属于Microsoft.ApplicationInsights.DataContracts命名空间,在下文中一共展示了RequestTelemetry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: InitializeSetsNullVersionIfBuildRootInfoNull

 public void InitializeSetsNullVersionIfBuildRootInfoNull()
 {
     var source = new BuildInfoConfigComponentVersionTelemetryInitializer();
     var requestTelemetry = new RequestTelemetry();
     source.Initialize(requestTelemetry);
     
     Assert.IsNull(requestTelemetry.Context.Component.Version);
 }
开发者ID:gregjhogan,项目名称:ApplicationInsights-server-dotnet,代码行数:8,代码来源:BuildInfoConfigComponentVersionTelemetryInitializerTest.cs


示例17: InitializeDoesNotOverrideExistingVersion

        public void InitializeDoesNotOverrideExistingVersion()
        {
            var initializer = new ComponentVersionTelemetryInitializer(this.BuildConfigurationWithVersion());
            var telemetry = new RequestTelemetry();
            telemetry.Context.Component.Version = "TestVersion";
            initializer.Initialize(telemetry);

            Assert.Equal("TestVersion", telemetry.Context.Component.Version);
        }
开发者ID:RehanSaeed,项目名称:ApplicationInsights-aspnetcore,代码行数:9,代码来源:ComponentVersionTelemetryInitializerTests.cs


示例18: LogUsageEvent

        private static void LogUsageEvent(AzurePSQoSEvent qos)
        {
            var tcEvent = new RequestTelemetry(qos.CmdletType, qos.StartTime, qos.Duration, string.Empty, qos.IsSuccess);
            tcEvent.Context.User.Id = qos.Uid;
            tcEvent.Context.User.UserAgent = AzurePowerShell.UserAgentValue.ToString();
            tcEvent.Context.Device.OperatingSystem = Environment.OSVersion.VersionString;

            TelemetryClient.TrackRequest(tcEvent);
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:9,代码来源:MetricHelper.cs


示例19: InitializeDoesNotThrowWhenHttpContextIsNull

        public void InitializeDoesNotThrowWhenHttpContextIsNull()
        {
            var requestTelemetry = new RequestTelemetry();

            var source = new OperationNameTelemetryInitializer();
            source.Initialize(requestTelemetry);

            Assert.AreEqual(string.Empty, requestTelemetry.Name);
        }
开发者ID:gregjhogan,项目名称:ApplicationInsights-server-dotnet,代码行数:9,代码来源:OperationNameTelemetryInitializerTests.cs


示例20: GetVersionReturnsCorrectVersion

        public void GetVersionReturnsCorrectVersion()
        {
            var doc = XDocument.Load(new StringReader("<DeploymentEvent><Build><MSBuild><BuildLabel>123</BuildLabel></MSBuild></Build></DeploymentEvent>")).Root;

            var source = new BuildInfoConfigComponentVersionTelemetryInitializerMock(doc);
            var requestTelemetry = new RequestTelemetry();
            source.Initialize(requestTelemetry);
            Assert.AreEqual("123", requestTelemetry.Context.Component.Version);
        }
开发者ID:gregjhogan,项目名称:ApplicationInsights-server-dotnet,代码行数:9,代码来源:BuildInfoConfigComponentVersionTelemetryInitializerTest.cs



注:本文中的Microsoft.ApplicationInsights.DataContracts.RequestTelemetry类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DataContracts.TelemetryContext类代码示例发布时间:2022-05-26
下一篇:
C# DataContracts.EventTelemetry类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap