当前位置: 首页>>代码示例>>C#>>正文


C# TelemetryClient.TrackRequest方法代码示例

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


在下文中一共展示了TelemetryClient.TrackRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AllTelemetryIsSentWithDefaultSamplingRate

        public void AllTelemetryIsSentWithDefaultSamplingRate()
        {
            var sentTelemetry = new List<ITelemetry>();
            var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) };
            var configuration = new TelemetryConfiguration { InstrumentationKey = "Test key", TelemetryChannel = channel };

            var client = new TelemetryClient(configuration);

            const int ItemsToGenerate = 100;

            for (int i = 0; i < ItemsToGenerate; i++)
            {
                client.TrackRequest(new RequestTelemetry());
            }

            Assert.Equal(ItemsToGenerate, sentTelemetry.Count);
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:17,代码来源:TelemetryClientTest.cs

示例2: Main

        static void Main(string[] args)
        {
            var config = TelemetryConfiguration.CreateDefault();
            config.TelemetryInitializers.Add(new EventSourceForAI.EventSourceTelemetryInitializer());
            config.InstrumentationKey = "Foo";

            TelemetryClient client = new TelemetryClient(config);

            var request = new RequestTelemetry("TestRequest", DateTimeOffset.Now, TimeSpan.FromMilliseconds(10), "200", true);
            request.Context.Properties.Add("property1", "value1");
            request.Context.User.Id = "userId";

            request.Context.Operation.Id = Guid.NewGuid().ToString();

            client.TrackRequest(request);

            Thread.Sleep(100);
        }
开发者ID:kartang,项目名称:ApmTipsTools,代码行数:18,代码来源:Program.cs

示例3: Invoke

        public async Task Invoke(IOwinContext context)
        {
            var stopwatch = Stopwatch.StartNew();
            bool success = false;

            try
            {
                switch (context.Request.Path.Value.ToLowerInvariant())
                {
                    case "/":
                        JObject response = new JObject();
                        response.Add("name", ServiceName);
                        JObject resources = new JObject();
                        response.Add("resources", resources);
                        resources.Add("range", MakeUri(context, "/search/range"));
                        resources.Add("fields", MakeUri(context, "/search/fields"));
                        resources.Add("console", MakeUri(context, "/console"));
                        resources.Add("diagnostics", MakeUri(context, "/search/diag"));
                        resources.Add("segments", MakeUri(context, "/search/segments"));
                        resources.Add("query", MakeUri(context, "/search/query"));
                        context.Response.StatusCode = (int) HttpStatusCode.OK;
                        context.Response.ContentType = "application/json";
                        await context.Response.WriteAsync(response.ToString());
                        break;
                    case "/search/query":
                        await QueryMiddleware.Execute(context, _searcherManager);
                        break;
                    case "/search/range":
                        await RangeMiddleware.Execute(context, _searcherManager);
                        break;
                    case "/search/diag":
                        await DiagMiddleware.Execute(context, _searcherManager);
                        break;
                    case "/search/segments":
                        await SegmentsMiddleware.Execute(context, _searcherManager);
                        break;
                    case "/search/fields":
                        await FieldsMiddleware.Execute(context, _searcherManager);
                        break;
                    default:
                        await context.Response.WriteAsync("unrecognized");
                        context.Response.StatusCode = (int) HttpStatusCode.NotFound;
                        break;
                }

                success = true;
            }
            catch
            {
                success = false;
            }
            finally
            {
                stopwatch.Stop();
                var telemetryClient = new TelemetryClient();
                var requestTelemetry = new RequestTelemetry(context.Request.Path.Value, DateTimeOffset.UtcNow, stopwatch.Elapsed, context.Response.StatusCode.ToString(CultureInfo.InvariantCulture), success: success);
                telemetryClient.TrackRequest(requestTelemetry);
            }
        }
开发者ID:darrelmiller,项目名称:NuGet.Services.Search,代码行数:59,代码来源:Startup.cs

示例4: Post

        public async Task<HttpResponseMessage> Post(string eventId)
        {
            var userToken = Request.Headers.SingleOrDefault(x => x.Key == "Authorization").Value.First();
            if (string.IsNullOrWhiteSpace(userToken))
                return Request.CreateResponse(HttpStatusCode.Forbidden);
            if (userToken != ConfigurationManager.AppSettings["UserToken"])
                return Request.CreateResponse(HttpStatusCode.Unauthorized);

            var telemetry = new TelemetryClient();
            var stopwatch = Stopwatch.StartNew();

            try
            {
                telemetry.Context.Operation.Name = "Reward";
                telemetry.Context.Operation.Id = eventId;

                // support simply float and complex JSON outcomes
                var rewardStr = await Request.Content.ReadAsStringAsync();
                var rewardObj = JToken.Parse(rewardStr);

                // parse input
                var guid = Guid.ParseExact(eventId, "N");

                var url = ConfigurationManager.AppSettings["DecisionServiceSettingsUrl"];
                var eventUploader = DecisionServiceStaticClient.AddOrGetExisting("uploader" + url,
                    _ =>
                    {
                        telemetry.TrackEvent("EventUploader creation");
                                               
                        var metaData = ApplicationMetadataUtil.DownloadMetadata<ApplicationClientMetadata>(url);
                        return new EventUploaderASA(
                            metaData.EventHubObservationConnectionString,
                            new BatchingConfiguration
                            {
                            // TODO: these are not production ready configurations. do we need to move those to C&C as well?
                            MaxBufferSizeInBytes = 1,
                                MaxDuration = TimeSpan.FromSeconds(1),
                                MaxEventCount = 1,
                                MaxUploadQueueCapacity = 1,
                                UploadRetryPolicy = BatchUploadRetryPolicy.ExponentialRetry
                            });
                    });

                eventUploader.Upload(new Observation
                {
                    Key = guid.ToString("N", CultureInfo.InvariantCulture),
                    Value = rewardObj
                });

                stopwatch.Stop();
                telemetry.TrackRequest("ReportReward", DateTime.Now, stopwatch.Elapsed, "200", true);

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch(Exception e)
            {
                telemetry.TrackException(e);
                return Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
            }
        }
开发者ID:xornand,项目名称:mwt-ds-web-api,代码行数:60,代码来源:RewardController.cs


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