question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable configuration support for Google.Cloud.Diagnostics.AspNetCore

See original GitHub issue

When using the Google.Cloud.Diagnostics.AspNetCore.GoogleDiagnosticsWebHostBuilderExtensions.UseGoogleDiagnostics extension, there is an assumption that the Google Cloud project ID is hardcoded. This is seen in the examples:

string projectId = "[Google Cloud Platform project ID]";
var webHost = new WebHostBuilder()
    .UseGoogleDiagnostics(projectId)
    .UseStartup<Startup>()
    .Build();

Looking at the extension, it appears this roughly boils down to a call to IWebHostBuilder.ConfigureServices(Action<IServiceCollection>) where several things get registered with DI.

There is another overload IWebHostBuilder.ConfigureServices(Action<WebHostBuilderContext, IServiceCollection>) where the web host can provide configuration for the app via WebHostBuilderContext.Configuration. This allows configuration to be set up then passed in to drive later registrations.

It would be helpful if there was a way to use this overload to avoid having to set up configuration multiple times (one for use in GCP calls, one for the actual app) and avoid hard coding.

For example, something like this:

public static IWebHostBuilder UseGoogleDiagnostics(this IWebHostBuilder builder, string projectIdKey = null, string serviceNameKey = null, string serviceVersionKey = null)
{
  builder.ConfigureServices((context, services) =>
  {
    var projectId = projectIdKey == null ? null : context.Configuration[projectIdKey];
    var serviceName = serviceNameKey == null ? null : context.Configuration[serviceNameKey];
    var serviceVersion = serviceVersionKey == null ? null : context.Configuration[serviceVersionKey];
    // then register the stuff as usual.
  }

  return builder;
}

A workaround would be to allow the GoogleDiagnosticsStartupFilter class to be public so folks could effectively write this overload as an app-specific extension. Unfortunately, with the GoogleDiagnosticsStartupFilter being internal, one can’t actually write a custom version of the extension in a very clean fashion.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
amanda-tarafacommented, Feb 25, 2019

I’ll be submitting option number 2 then, we can revisit number 3 in the future if we really need it.

1reaction
amanda-tarafacommented, Feb 20, 2019

Let me take a closer look at that. I’ll updata here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google.Cloud.Diagnostics.AspNetCore
This configures the Logging, Tracing and Error Reporting components, including neccesarry middlewares.
Read more >
Google.Cloud.Diagnostics.AspNet
Install the Google.Cloud.Diagnostics.AspNet package from NuGet. Add it to your project in the normal way (for example by right-clicking on the project in ......
Read more >
Google.Cloud.Diagnostics.AspNetCore3 debug level not ...
Short Answer: Google.Cloud.Diagnostics.AspNetCore3 does not use appsettings.json (at least for now) and one must explicitly set log levels.
Read more >
Google.Cloud.Diagnostics.AspNetCore 4.4.0
Google Cloud Logging, Trace and Error Reporting Instrumentation Libraries for ASP.NET Core.
Read more >
Google Cloud Platform Blog - googblogs.com
Product updates, customer stories, and tips and tricks on Google Cloud Platform.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found