New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud Error Reporting Trace for ASP.NET Core #700
Conversation
# Conflicts: # apis/Google.Cloud.Diagnostics.AspNet/Google.Cloud.Diagnostics.AspNet/Trace/Labels.cs
# Conflicts: # apis/Google.Cloud.Diagnostics.AspNet/Google.Cloud.Diagnostics.AspNet/Trace/CloudTrace.cs # apis/Google.Cloud.Diagnostics.AspNet/Google.Cloud.Diagnostics.AspNet/Trace/TraceHeaderContextUtils.cs # apis/Google.Cloud.Diagnostics.AspNet/Google.Cloud.Diagnostics.AspNet/Trace/TraceHeaderTraceOptionsFactory.cs # apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common.Tests/AssemblyInfo.cs # apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common.Tests/Trace/LabelsTest.cs # apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common.Tests/Trace/SimpleManagedTracerTest.cs # apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common/Trace/Labels.cs # apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common/Trace/TraceHeaderContext.cs
/// </summary> | ||
/// <param name="projectId">The Google Cloud Platform project ID. Cannot be null.</param> | ||
/// <param name="config">Optional trace configuration, if unset the default will be used.</param> | ||
/// <param name="clientTask">Optional a task which produces the Trace client, if |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
// If the trace header says to trace or if the rate limiter allows tracing continue. | ||
var headerContext = provider.GetService<TraceHeaderContext>(); | ||
if (!headerContext.ShouldTrace) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// Trace the delegate and annotate it with information from the current | ||
// http context. | ||
tracer.StartSpan(httpContext.Request.Path); | ||
await _next(httpContext); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
/// <summary> | ||
/// Creates a <see cref="IManagedTracer"/> based on the <see cref="TraceHeaderContext"/> and |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
As Mike seems to be on the case here, I'll wait until he's done - I wouldn't be reviewing it today anyway, as I'm off soon and this is a big thing to start last minute on Friday :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Mike PTAL
/// </summary> | ||
/// <param name="projectId">The Google Cloud Platform project ID. Cannot be null.</param> | ||
/// <param name="config">Optional trace configuration, if unset the default will be used.</param> | ||
/// <param name="clientTask">Optional a task which produces the Trace client, if |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
/// <summary> | ||
/// Creates a <see cref="IManagedTracer"/> based on the <see cref="TraceHeaderContext"/> and |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
// If the trace header says to trace or if the rate limiter allows tracing continue. | ||
var headerContext = provider.GetService<TraceHeaderContext>(); | ||
if (!headerContext.ShouldTrace) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// Trace the delegate and annotate it with information from the current | ||
// http context. | ||
tracer.StartSpan(httpContext.Request.Path); | ||
await _next(httpContext); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 2 additional comments. Everything else looks good.
// End sample | ||
|
||
// Sample: UseTracer | ||
/// <param name="tracer">Populated by dependency injection.</param> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
using System; | ||
using Xunit; | ||
|
||
using ProjectId = Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension.ProjectId; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Thanks! PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't done a thorough review of the tests, but I love how easy it is to set up. Will see if I can use it from Azure easily, once I've honed my "getting Google credentials from Azure Key Vault" code...
{ | ||
public class CloudTraceExtensionTest | ||
{ | ||
private const string projectId = "pid"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
TraceHeaderContext context, bool rateLimiterShouldTrace) | ||
{ | ||
Mock<IConsumer<TraceProto>> mockConsumer = new Mock<IConsumer<TraceProto>>(); | ||
Mock<IServiceProvider> mockProvider = new Mock<IServiceProvider>(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// finely grained manual tracing. | ||
/// </summary> | ||
/// | ||
/// <example> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
var traceIdFactory = provider.GetService<TraceIdFactory>(); | ||
var consumer = provider.GetService<IConsumer<TraceProto>>(); | ||
|
||
// Check that we have all the needed services. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
throw new InvalidOperationException("Ensure Google Cloud Trace is properly set up."); | ||
} | ||
|
||
// If the trace header says to trace or if the rate limiter allows tracing continue. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// If the trace header says to trace or if the rate limiter allows tracing continue. | ||
if (!headerContext.ShouldTrace) | ||
{ | ||
TraceOptions options = rateLimitingFactory.CreateOptions(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// and trace the time taken for the next delegate to run. The time taken and metadata | ||
/// will be sent to the Stackdriver Trace API. | ||
/// </summary> | ||
public sealed class CloudTraceMiddleware |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// <summary> | ||
/// Creates a map of labels to represent a <see cref="StackTrace"/> for a span. | ||
/// </summary> | ||
public static Dictionary<string, string> FromStackTrace(StackTrace stackTrace) => |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank Jon, PTAL
{ | ||
public class CloudTraceExtensionTest | ||
{ | ||
private const string projectId = "pid"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
TraceHeaderContext context, bool rateLimiterShouldTrace) | ||
{ | ||
Mock<IConsumer<TraceProto>> mockConsumer = new Mock<IConsumer<TraceProto>>(); | ||
Mock<IServiceProvider> mockProvider = new Mock<IServiceProvider>(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
var traceIdFactory = provider.GetService<TraceIdFactory>(); | ||
var consumer = provider.GetService<IConsumer<TraceProto>>(); | ||
|
||
// Check that we have all the needed services. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
throw new InvalidOperationException("Ensure Google Cloud Trace is properly set up."); | ||
} | ||
|
||
// If the trace header says to trace or if the rate limiter allows tracing continue. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// If the trace header says to trace or if the rate limiter allows tracing continue. | ||
if (!headerContext.ShouldTrace) | ||
{ | ||
TraceOptions options = rateLimitingFactory.CreateOptions(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// and trace the time taken for the next delegate to run. The time taken and metadata | ||
/// will be sent to the Stackdriver Trace API. | ||
/// </summary> | ||
public sealed class CloudTraceMiddleware |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// <summary> | ||
/// Creates a map of labels to represent a <see cref="StackTrace"/> for a span. | ||
/// </summary> | ||
public static Dictionary<string, string> FromStackTrace(StackTrace stackTrace) => |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
TraceHeaderContext context, bool rateLimiterShouldTrace) | ||
{ | ||
Mock<IConsumer<TraceProto>> mockConsumer = new Mock<IConsumer<TraceProto>>(); | ||
Mock<IServiceProvider> mockProvider = new Mock<IServiceProvider>(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// and trace the time taken for the next delegate to run. The time taken and metadata | ||
/// will be sent to the Stackdriver Trace API. | ||
/// </summary> | ||
public sealed class CloudTraceMiddleware |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
GaxPreconditions.CheckState(consumer != null, | ||
string.Format(message, typeof(TraceProto).GetType())); | ||
|
||
// If the trace header and rate limiter say not to trace, return a no-op tracer. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jon, PTAL
TraceHeaderContext context, bool rateLimiterShouldTrace) | ||
{ | ||
Mock<IConsumer<TraceProto>> mockConsumer = new Mock<IConsumer<TraceProto>>(); | ||
Mock<IServiceProvider> mockProvider = new Mock<IServiceProvider>(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
GaxPreconditions.CheckState(consumer != null, | ||
string.Format(message, typeof(TraceProto).GetType())); | ||
|
||
// If the trace header and rate limiter say not to trace, return a no-op tracer. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// and trace the time taken for the next delegate to run. The time taken and metadata | ||
/// will be sent to the Stackdriver Trace API. | ||
/// </summary> | ||
public sealed class CloudTraceMiddleware |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments, but feel free to merge.
TraceHeaderContext context, bool rateLimiterShouldTrace) | ||
{ | ||
Mock<IConsumer<TraceProto>> mockConsumer = new Mock<IConsumer<TraceProto>>(); | ||
Mock<IServiceProvider> mockProvider = new Mock<IServiceProvider>(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
private const string ProjectId = "pid"; | ||
private const string TraceId = "105445aa7843bc8bf206b12000100f00"; | ||
private const ulong SpanId = 81237123; | ||
private const string projectId = "pid"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
GaxPreconditions.CheckState(consumer != null, | ||
string.Format(message, typeof(TraceProto).GetType())); | ||
|
||
// If the trace header and rate limiter say not to trace, return a no-op tracer. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// and trace the time taken for the next delegate to run. The time taken and metadata | ||
/// will be sent to the Stackdriver Trace API. | ||
/// </summary> | ||
internal sealed class CloudTraceMiddleware |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# Conflicts: # apis/Google.Cloud.Diagnostics.AspNetCore/Google.Cloud.Diagnostics.AspNetCore.Snippets/AspNetCoreSnippets.cs # apis/Google.Cloud.Diagnostics.AspNetCore/docs/index.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jon, sorry about the odd rename change...
Source-Link: googleapis/googleapis@249e9a1 Source-Link: googleapis/googleapis-gen@1f2c41b Copy-Tag: eyJwIjoiYXBpcy9Hb29nbGUuQ2xvdWQuQ29tcHV0ZS5WMS8uT3dsQm90LnlhbWwiLCJoIjoiMWYyYzQxYmJmZTA5NzYxNmNlYjFlOWZiNjc4NzJhNmJiMWRjNTlkNCJ9
Source-Link: googleapis/googleapis@249e9a1 Source-Link: googleapis/googleapis-gen@1f2c41b Copy-Tag: eyJwIjoiYXBpcy9Hb29nbGUuQ2xvdWQuQ29tcHV0ZS5WMS8uT3dsQm90LnlhbWwiLCJoIjoiMWYyYzQxYmJmZTA5NzYxNmNlYjFlOWZiNjc4NzJhNmJiMWRjNTlkNCJ9
Source-Link: googleapis/googleapis@249e9a1 Source-Link: googleapis/googleapis-gen@1f2c41b Copy-Tag: eyJwIjoiYXBpcy9Hb29nbGUuQ2xvdWQuQ29tcHV0ZS5WMS8uT3dsQm90LnlhbWwiLCJoIjoiMWYyYzQxYmJmZTA5NzYxNmNlYjFlOWZiNjc4NzJhNmJiMWRjNTlkNCJ9
Changes in this release: ### New features - Update compute API to revision 20220112 ([issue 700](googleapis#700)) ([commit ebe518a](googleapis@ebe518a)) - The original commit contained breaking changes, but they were reverted in [commit 50ea200](googleapis@50ea200)
Allows for automated tracing of incoming requests to ASP.NET Core applications. Trace data is sent to the Stackdriver Trace API.
This PR includes:
Coming soon: