Skip to content

Conversation

@alanwest
Copy link
Member

@alanwest alanwest commented Feb 7, 2023

We discussed this briefly on a previous PR, but I'm raising it once more because there seems to be conflicting guidance for whether to place extension methods in the namespace of the thing they're extending versus some other namespace.

DO NOT put our extensions under Microsoft.Extensions.* namespace:

https://learn.microsoft.com/dotnet/core/extensions/options-library-authors#namespace-guidance

DO put our extensions under Microsoft.Extensions.* namespace:

https://learn.microsoft.com/dotnet/core/extensions/dependency-injection-usage#register-services-for-di

In general, I don't feel strongly either way. However, we do have an existing precedent for placing our extensions in the namespace of the thing they're extending. So I lean towards us being self-consistent.

ILoggingBuilder extensions

namespace Microsoft.Extensions.Logging
{
/// <summary>
/// Contains extension methods for registering <see cref="OpenTelemetryLoggerProvider"/> into a <see cref="ILoggingBuilder"/> instance.
/// </summary>
public static class OpenTelemetryLoggingExtensions
{
/// <summary>
/// Adds an OpenTelemetry logger named 'OpenTelemetry' to the <see cref="ILoggerFactory"/>.
/// </summary>
/// <remarks>
/// Note: This is safe to be called multiple times and by library
/// authors. Only a single <see cref="OpenTelemetryLoggerProvider"/>
/// will be created for a given <see cref="IServiceCollection"/>.
/// </remarks>
/// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
/// <returns>The supplied <see cref="ILoggingBuilder"/> for call chaining.</returns>
public static ILoggingBuilder AddOpenTelemetry(this ILoggingBuilder builder)

Prometheus exporter ApplicationBuilder extensions

namespace Microsoft.AspNetCore.Builder
{
/// <summary>
/// Provides extension methods for <see cref="IApplicationBuilder"/> to add
/// Prometheus scraping endpoint.
/// </summary>
public static class PrometheusExporterApplicationBuilderExtensions
{
/// <summary>
/// Adds OpenTelemetry Prometheus scraping endpoint middleware to an
/// <see cref="IApplicationBuilder"/> instance.
/// </summary>
/// <remarks>Note: A branched pipeline is created for the route
/// specified by <see
/// cref="PrometheusAspNetCoreOptions.ScrapeEndpointPath"/>.</remarks>
/// <param name="app">The <see cref="IApplicationBuilder"/> to add
/// middleware to.</param>
/// <returns>A reference to the original <see
/// cref="IApplicationBuilder"/> for chaining calls.</returns>
public static IApplicationBuilder UseOpenTelemetryPrometheusScrapingEndpoint(this IApplicationBuilder app)

@alanwest alanwest requested a review from a team February 7, 2023 22:40
@codecov
Copy link

codecov bot commented Feb 7, 2023

Codecov Report

Merging #4164 (394118a) into main (94f67d8) will not change coverage.
The diff coverage is n/a.

❗ Current head 394118a differs from pull request most recent head c1fb06b. Consider uploading reports for the commit c1fb06b to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4164   +/-   ##
=======================================
  Coverage   85.59%   85.59%           
=======================================
  Files         293      293           
  Lines       11371    11371           
=======================================
  Hits         9733     9733           
  Misses       1638     1638           
Impacted Files Coverage Δ
...emetry/OpenTelemetryServiceCollectionExtensions.cs 100.00% <ø> (ø)
...nTelemetry/Internal/SelfDiagnosticsConfigParser.cs 82.60% <0.00%> (-6.53%) ⬇️
...orter.OpenTelemetryProtocol/OtlpExporterOptions.cs 96.36% <0.00%> (ø)
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 100.00% <0.00%> (+2.85%) ⬆️
...lementation/SqlClientInstrumentationEventSource.cs 75.00% <0.00%> (+4.16%) ⬆️
...ZPages/Implementation/ZPagesExporterEventSource.cs 62.50% <0.00%> (+6.25%) ⬆️

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't feel passionately that it should be namespace OpenTelemetry so if you feel this is better LGTM

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add changelog entry as this is breaking change when bumping from last rc

@alanwest
Copy link
Member Author

alanwest commented Feb 9, 2023

Holding on this until we've settled on some of the questions about where the AddOpenTelemetry API will live...

@alanwest
Copy link
Member Author

Handled by #4174

@alanwest alanwest closed this Feb 10, 2023
@alanwest alanwest deleted the alanwest/add-otel-extension branch February 10, 2023 23:37
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