Skip to content

Instantly share code, notes, and snippets.

@dasiths
Created May 14, 2021 13:58
Show Gist options
  • Save dasiths/2c4962dd2abab57dc6652ad7cb1b157d to your computer and use it in GitHub Desktop.
Save dasiths/2c4962dd2abab57dc6652ad7cb1b157d to your computer and use it in GitHub Desktop.
Tracing + Telemetry using .NET and Application Insights
// Reading
// https://tsuyoshiushio.medium.com/correlation-with-activity-with-application-insights-1-overview-753a48a645fb
// https://tsuyoshiushio.medium.com/correlation-with-activity-with-application-insights-2-activity-deep-dive-2a4147919659
// https://medium.com/prospa-engineering/implementing-distributed-tracing-with-azures-application-insights-5a09cc1c200c
var activity = new Activity("Call to CosmosDB");
// activity.SetParentId("correlation id from request")
//RequestTelemetry for Request, DependencyTelemtry for Dependencies
using var operation = telemetryClient.StartOperation<DependencyTelemetry>(activity);
Try {
// call cosmos db
} Catch (Exception e) {
operation.Telemetry.Success = false;
telemetryClient.TrackException(e);
}
Finally {
telemetryClient.StopOperation(operation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment