Skip to content
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

Merged
merged 10 commits into from
Mar 9, 2017

Conversation

iantalarico
Copy link
Contributor

This also refactors Error Reporting Options and Event Targets to make them more consistent and simple to use.

…E and GCE.

This also refactors Error Reporting Options and Event Targets to make them more consistent and simple to use.
Copy link
Collaborator

@jskeet jskeet left a 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.

{
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.

@iantalarico
Copy link
Contributor Author

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.

@@ -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.

/// 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.

/// 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.

/// <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.

@@ -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.

/// 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.

// 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.

/// 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.

Copy link
Contributor Author

@iantalarico iantalarico left a 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.

/// 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.

@@ -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.

/// 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.

/// <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.

@@ -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.

/// 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.

// 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.

/// 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.

@@ -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.

{
monitoredResource = monitoredResource ?? MonitoredResourceBuilder.FromPlatform();

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor Author

@iantalarico iantalarico left a 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.

@@ -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.

Copy link
Contributor

@evildour evildour left a 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.

@@ -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.

# Conflicts:
#	apis/Google.Cloud.Diagnostics.AspNetCore/Google.Cloud.Diagnostics.AspNetCore/Trace/CloudTraceExtension.cs
@iantalarico iantalarico merged commit 97ddf80 into googleapis:master Mar 9, 2017
@iantalarico iantalarico deleted the auto-project-id branch March 9, 2017 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants