-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hosting: Support metrics registration via IServiceCollection & deferr…
…ed configuration (#2412) * Add metrics support to hosting lib. * Bug fixes and some public api additions. * Added missing zipkin publicapi files. * Unit tests. * CHANGELOG updates * Fixes * Code review. * Update src/OpenTelemetry.Extensions.Hosting/CHANGELOG.md Co-authored-by: Reiley Yang <[email protected]> * Code review. * Warning fixup. Co-authored-by: Reiley Yang <[email protected]> Co-authored-by: Cijo Thomas <[email protected]>
- Loading branch information
1 parent
c60dc36
commit 38ee521
Showing
32 changed files
with
737 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/OpenTelemetry.Api/Metrics/IDeferredMeterProviderBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// <copyright file="IDeferredMeterProviderBuilder.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
|
||
namespace OpenTelemetry.Metrics | ||
{ | ||
/// <summary> | ||
/// Describes a meter provider builder that supports deferred initialization | ||
/// using an <see cref="IServiceProvider"/> to perform dependency injection. | ||
/// </summary> | ||
public interface IDeferredMeterProviderBuilder | ||
{ | ||
/// <summary> | ||
/// Register a callback action to configure the <see | ||
/// cref="MeterProviderBuilder"/> once the application <see | ||
/// cref="IServiceProvider"/> is available. | ||
/// </summary> | ||
/// <param name="configure">Configuration callback.</param> | ||
/// <returns>The supplied <see cref="MeterProviderBuilder"/> for chaining.</returns> | ||
MeterProviderBuilder Configure(Action<IServiceProvider, MeterProviderBuilder> configure); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/OpenTelemetry.Exporter.Zipkin/.publicApi/net5.0/PublicAPI.Shipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
OpenTelemetry.Exporter.ZipkinExporter | ||
OpenTelemetry.Exporter.ZipkinExporter.ZipkinExporter(OpenTelemetry.Exporter.ZipkinExporterOptions options, System.Net.Http.HttpClient client = null) -> void | ||
OpenTelemetry.Exporter.ZipkinExporterOptions | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.BatchExportProcessorOptions.get -> OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity> | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.BatchExportProcessorOptions.set -> void | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.get -> System.Uri | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.set -> void | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int? | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.set -> void | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.get -> bool | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void | ||
OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void | ||
OpenTelemetry.Trace.ZipkinExporterHelperExtensions | ||
override OpenTelemetry.Exporter.ZipkinExporter.Export(in OpenTelemetry.Batch<System.Diagnostics.Activity> batch) -> OpenTelemetry.ExportResult | ||
static OpenTelemetry.Trace.ZipkinExporterHelperExtensions.AddZipkinExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.ZipkinExporterOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder |
Empty file.
8 changes: 8 additions & 0 deletions
8
src/OpenTelemetry.Extensions.Hosting/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/OpenTelemetry.Extensions.Hosting/Implementation/MeterProviderBuilderHosting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// <copyright file="MeterProviderBuilderHosting.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace OpenTelemetry.Metrics | ||
{ | ||
/// <summary> | ||
/// A <see cref="MeterProviderBuilderBase"/> with support for deferred initialization using <see cref="IServiceProvider"/> for dependency injection. | ||
/// </summary> | ||
internal sealed class MeterProviderBuilderHosting : MeterProviderBuilderBase, IDeferredMeterProviderBuilder | ||
{ | ||
private readonly List<Action<IServiceProvider, MeterProviderBuilder>> configurationActions = new List<Action<IServiceProvider, MeterProviderBuilder>>(); | ||
|
||
public MeterProviderBuilderHosting(IServiceCollection services) | ||
{ | ||
this.Services = services ?? throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
public IServiceCollection Services { get; } | ||
|
||
public MeterProviderBuilder Configure(Action<IServiceProvider, MeterProviderBuilder> configure) | ||
{ | ||
if (configure == null) | ||
{ | ||
throw new ArgumentNullException(nameof(configure)); | ||
} | ||
|
||
this.configurationActions.Add(configure); | ||
return this; | ||
} | ||
|
||
public MeterProvider Build(IServiceProvider serviceProvider) | ||
{ | ||
if (serviceProvider == null) | ||
{ | ||
throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
|
||
// Note: Not using a foreach loop because additional actions can be | ||
// added during each call. | ||
for (int i = 0; i < this.configurationActions.Count; i++) | ||
{ | ||
this.configurationActions[i](serviceProvider, this); | ||
} | ||
|
||
return this.Build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.