-
Notifications
You must be signed in to change notification settings - Fork 371
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
Enable automatic project id detection from monitored resources for GAE and GCE. #826
Conversation
…E and GCE. This also refactors Error Reporting Options and Event Targets to make them more consistent and simple to use.
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.
Only skimmed, but this seems reasonable... how easy is it to detect non-dev environment in ASP.NET? I think I know where to do it all in Core, and we might want to put that in the snippets too - we probably don't want tracing when running locally, and we won't be able to detect the project id.
/// <summary> | ||
/// Uses middleware that will report all uncaught exceptions to the Stackdriver | ||
/// Error Reporting API. | ||
/// <para /> |
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.
{ | ||
Debug.WriteLine("Google Cloud Platfrom project ID mismatch. " + | ||
$"Project Id parameter '{projectId}' does not match " + | ||
$"resource project ID '{resourceProjectId}' " + |
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.
I created #829 to track your comment. I think this would make development much smoother with support like this. |
@@ -70,15 +70,32 @@ public class ErrorReportingExceptionFilter : IExceptionFilter, IDisposable | |||
public static ErrorReportingExceptionFilter Create(string projectId, string serviceName, string version, | |||
ErrorReportingOptions options = null) | |||
{ | |||
GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); |
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.
@@ -67,15 +67,30 @@ public sealed class ErrorReportingExceptionLogger : ExceptionLogger, IDisposable | |||
public static ErrorReportingExceptionLogger Create(string projectId, string serviceName, string version, | |||
ErrorReportingOptions options = null) | |||
{ | |||
GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); |
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.
/// defined by <see cref="GoogleCredential.GetApplicationDefaultAsync"/>. | ||
/// <para> | ||
/// Can be used when running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project to report error to will detected from the |
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.
/// defined by <see cref="GoogleCredential.GetApplicationDefaultAsync"/>. | ||
/// <para> | ||
/// Can be used when running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project to report error to will detected from the |
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.
/// <param name="application">The Http application.</param> | ||
/// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project ID. If running on GAE or GCE the project ID will be |
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.
@@ -59,14 +59,34 @@ public static class ErrorReportingExceptionLoggerExtension | |||
this IApplicationBuilder app, string projectId, string serviceName, string version, | |||
ErrorReportingOptions options = null) | |||
{ | |||
GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); |
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.
/// Error Reporting API. | ||
/// <para> | ||
/// Can be used when running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project to report error to will detected from the |
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 does not use monitored resources, only detect the monitored resource if | ||
// a project id is needed. | ||
projectId = projectId ?? CommonUtils.GetAndCheckProjectId( | ||
projectId, MonitoredResourceBuilder.FromPlatform()); |
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 string project id is null and the MonitoredResource does not contain a project id | ||
/// then an <see cref="InvalidOperationException"/> is thrown. | ||
/// </term> | ||
/// </list> |
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 Mike, PTAL
@@ -70,15 +70,32 @@ public class ErrorReportingExceptionFilter : IExceptionFilter, IDisposable | |||
public static ErrorReportingExceptionFilter Create(string projectId, string serviceName, string version, | |||
ErrorReportingOptions options = null) | |||
{ | |||
GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// defined by <see cref="GoogleCredential.GetApplicationDefaultAsync"/>. | ||
/// <para> | ||
/// Can be used when running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project to report error to will detected from the |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -67,15 +67,30 @@ public sealed class ErrorReportingExceptionLogger : ExceptionLogger, IDisposable | |||
public static ErrorReportingExceptionLogger Create(string projectId, string serviceName, string version, | |||
ErrorReportingOptions options = null) | |||
{ | |||
GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// defined by <see cref="GoogleCredential.GetApplicationDefaultAsync"/>. | ||
/// <para> | ||
/// Can be used when running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project to report error to will detected from the |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// <param name="application">The Http application.</param> | ||
/// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project ID. If running on GAE or GCE the project ID will be |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -59,14 +59,34 @@ public static class ErrorReportingExceptionLoggerExtension | |||
this IApplicationBuilder app, string projectId, string serviceName, string version, | |||
ErrorReportingOptions options = null) | |||
{ | |||
GaxPreconditions.CheckNotNullOrEmpty(projectId, nameof(projectId)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// Error Reporting API. | ||
/// <para> | ||
/// Can be used when running on Google App Engine or Google Compute Engine. | ||
/// The Google Cloud Platform project to report error to will detected from the |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// Trace does not use monitored resources, only detect the monitored resource if | ||
// a project id is needed. | ||
projectId = projectId ?? CommonUtils.GetAndCheckProjectId( | ||
projectId, MonitoredResourceBuilder.FromPlatform()); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
/// If the string project id is null and the MonitoredResource does not contain a project id | ||
/// then an <see cref="InvalidOperationException"/> is thrown. | ||
/// </term> | ||
/// </list> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -121,7 +121,7 @@ private CloudTrace(string projectId, TraceConfiguration config = null, TraceServ | |||
/// Initialize tracing for this application. | |||
/// </summary> | |||
/// <param name="application">The Http application.</param> | |||
/// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine. | |||
/// <param name="projectId">Optional if unspecified and running on Google App Engine or Google Compute Engine. |
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.
{ | ||
monitoredResource = monitoredResource ?? MonitoredResourceBuilder.FromPlatform(); |
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.
Fixed, thanks!
{ | ||
monitoredResource = monitoredResource ?? MonitoredResourceBuilder.FromPlatform(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -121,7 +121,7 @@ private CloudTrace(string projectId, TraceConfiguration config = null, TraceServ | |||
/// Initialize tracing for this application. | |||
/// </summary> | |||
/// <param name="application">The Http application.</param> | |||
/// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine. | |||
/// <param name="projectId">Optional if unspecified and running on Google App Engine or Google Compute Engine. |
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 one additional comment. Otherwise, LGTM.
{ | ||
return new EventTarget | ||
{ | ||
// The Error Reporting API does not use monitored resources, only detect the monitored | ||
// resource if a project id is needed. | ||
ProjectId = projectId ?? CommonUtils.GetAndCheckProjectId(projectId), |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -132,8 +132,7 @@ public static void Initialize(HttpApplication application, string projectId = nu | |||
|
|||
// Trace does not use monitored resources, only detect the monitored resource if | |||
// a project id is needed. | |||
projectId = projectId ?? CommonUtils.GetAndCheckProjectId( | |||
projectId, MonitoredResourceBuilder.FromPlatform()); | |||
projectId = projectId ?? CommonUtils.GetAndCheckProjectId(projectId); |
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.
# Conflicts: # apis/Google.Cloud.Diagnostics.AspNetCore/Google.Cloud.Diagnostics.AspNetCore/Trace/CloudTraceExtension.cs
This also refactors Error Reporting Options and Event Targets to make them more consistent and simple to use.