本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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);
}
}